generated from UCSC-CSE-130/project2-map-reduce
-
Notifications
You must be signed in to change notification settings - Fork 2
/
kvlist.h
93 lines (76 loc) · 1.96 KB
/
kvlist.h
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
#pragma once
/**
* `kvpair_t` stores a pair strings: key and value.
*/
typedef struct kvpair_t {
char *key;
char *value;
} kvpair_t;
/**
* `kvpair_new` creates a new `kvpair_t` by copying the provided `key` and
* `value`.
*/
kvpair_t *kvpair_new(char *key, char *value);
/**
* `kvpair_clone` creates a copy of `kv`.
*/
kvpair_t *kvpair_clone(kvpair_t *kv);
/**
* `kvpair_free` frees `kvpair_t`.
*/
void kvpair_free(kvpair_t **kv);
/**
* `kvpair_update_value` updates the value of the pair.
*/
void kvpair_update_value(kvpair_t *pair, char *new_value);
struct kvlist_node_t;
typedef struct kvlist_node_t kvlist_node_t;
/**
* `kvlist_t` is a list of `kvpair_t`s.
*/
typedef struct kvlist_t kvlist_t;
/**
* `kvlist_new` creates a new `kvlist_t`.
*/
kvlist_t *kvlist_new(void);
/**
* `kvlist_free` frees `kvlist_t`.
* It also frees all pairs inside the list.
*/
void kvlist_free(kvlist_t **lst);
/**
* `kvlist_append` appends the pair `kv` to the list `lst`.
*/
void kvlist_append(kvlist_t *lst, kvpair_t *kv);
/**
* `kvlist_extend` concatenates two lists `lst` and `lst2`.
* After this function returns, all pairs in `lst2` are moved to `lst` and
* `lst2` becomes empty.
*/
void kvlist_extend(kvlist_t *lst, kvlist_t *lst2);
/**
* `kvlist_sort` sorts the list by keys.
*/
void kvlist_sort(kvlist_t *lst);
/**
* `kvlist_print` prints the contents of `lst` to the file descriptor `fd`.
*/
void kvlist_print(int fd, kvlist_t *lst);
/**
* `kvlist_iterator_t` is used to iterate over `kvlist_t`.
*/
struct kvlist_iterator_t;
typedef struct kvlist_iterator_t kvlist_iterator_t;
/**
* `kvlist_iterator_new` creates a new iterator.
*/
kvlist_iterator_t *kvlist_iterator_new(kvlist_t *lst);
/**
* `kvlist_iterator_next` returns the next `kvpair_t`.
* It returns `NULL` if there is no more pair.
*/
kvpair_t *kvlist_iterator_next(kvlist_iterator_t *it);
/**
* `kvlist_iterator_free` frees `kvlist_iterator_t`.
*/
void kvlist_iterator_free(kvlist_iterator_t **it);