-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvector.c
61 lines (53 loc) · 1.24 KB
/
vector.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "xml.h"
#include "vector.h"
#include "utils.h"
struct node* node_start = NULL;
void vector_push(char* node_path) {
if(node_path != NULL) {
url_t* url_parts = utils_format_url(node_path);
if(url_parts != NULL) {
struct node* node_link = malloc(sizeof(struct node));
ZERO_BUF(node_link);
node_link->host = url_parts->url_host;
node_link->path = url_parts->url_uri;
node_link->next_ptr = node_start;
node_start = node_link;
}
free(url_parts);
}
}
static void vector_destory_element(struct node* element) {
free(element->host);
free(element->path);
free(element);
}
void vector_destroy() {
struct node* node_tmp;
FOR_EACH(node_start, node_tmp) {
if(node_tmp == NULL) {
break;
}
vector_destory_element(node_tmp);
}
node_start = NULL;
}
int vector_size() {
int node_elements = 0;
struct node* node_tmp;
FOR_EACH(node_start, node_tmp) {
node_elements++;
}
return node_elements;
}
struct node* vector_rand() {
uint vector_index = (rand() & vector_size());
uint current_index = 0;
struct node* node_tmp;
FOR_EACH(node_start, node_tmp) {
if(current_index == vector_index) {
return node_tmp;
}
++current_index;
}
return node_start;
}