-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.c
More file actions
102 lines (84 loc) · 1.95 KB
/
Copy pathmap.c
File metadata and controls
102 lines (84 loc) · 1.95 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <string.h>
#include "proxy.h"
int map_insert(struct rb_root *root, pxy_agent_t *q)
{
struct rb_node **new = &(root->rb_node), *parent = NULL;
while (*new) {
pxy_agent_t *data = rb_entry(*new,struct pxy_agent_s,rbnode);
int result = strcmp(data->epid,q->epid);
parent = *new;
if (result < 0)
new = &((*new)->rb_left);
else if (result > 0)
new = &((*new)->rb_right);
else
return -1;
}
rb_link_node(&q->rbnode,parent,new);
rb_insert_color(&q->rbnode,root);
return 1;
}
pxy_agent_t* map_search(struct rb_root *root,char *name)
{
struct rb_node *node = root->rb_node;
while (node) {
pxy_agent_t *q = rb_entry(node,struct pxy_agent_s,rbnode);
int result = strcmp(q->epid,name);
if (result < 0)
node = node->rb_left;
else if (result > 0)
node = node->rb_right;
else
return q;
}
return NULL;
}
pxy_agent_t* map_remove(struct rb_root *root, char *name)
{
pxy_agent_t *data = map_search(root,name);
if (data) {
rb_erase(&data->rbnode,root);
}
return data;
}
int map_insert_reg3(struct rb_root *root, reg3_t *q)
{
struct rb_node **new = &(root->rb_node), *parent = NULL;
while (*new) {
reg3_t* data = rb_entry(*new, struct reg3_s, rbnode);
int result = strcmp(data->epid,q->epid);
parent = *new;
if (result < 0)
new = &((*new)->rb_left);
else if (result > 0)
new = &((*new)->rb_right);
else
return -1;
}
rb_link_node(&q->rbnode,parent,new);
rb_insert_color(&q->rbnode,root);
return 1;
}
reg3_t* map_search_reg3(struct rb_root *root, char *name)
{
struct rb_node *node = root->rb_node;
while (node) {
reg3_t* q = rb_entry(node, struct reg3_s, rbnode);
int result = strcmp(q->epid,name);
if (result < 0)
node = node->rb_left;
else if (result > 0)
node = node->rb_right;
else
return q;
}
return NULL;
}
reg3_t* map_remove_reg3(struct rb_root *root, char *name)
{
reg3_t* data = map_search_reg3(root,name);
if (data) {
rb_erase(&data->rbnode,root);
}
return data;
}