-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap.c
37 lines (32 loc) · 811 Bytes
/
map.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
#include "map.h"
#include "alloc.h"
#include "goodstring.h"
#include "sandersio.h"
#include "screentext.h"
struct map *map_init(unsigned int size) {
struct map *result = mm_zalloc(sizeof(struct map));
result->size = 0;
result->body = NULL;
return result;
}
void *map_put(struct map *map, char *key, void *val) {
struct kvpl *newl = mm_alloc(sizeof(struct kvpl));
newl->key = gs_dup(key);
newl->val = val;
newl->next = map->body;
map->body = newl;
return NULL;
}
void *map_get(struct map *map, char *key) {
struct kvpl *c_temp = map->body;
while(c_temp) {
if (gs_comp(key, c_temp->key)==0) {
return c_temp->val;
}
c_temp = c_temp->next;
}
return NULL;
}
struct map *map_new() {
return map_init(DEFAULT_SIZE);
}