-
Notifications
You must be signed in to change notification settings - Fork 0
/
lbst.h
59 lines (34 loc) · 1.31 KB
/
lbst.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
#ifndef _LBST_H_
#define _LBST_H_
#include <stdio.h>
typedef void* lbst_T;
/* Inserts a new (key, val) into the dictionary. If key is already in the
dictionary, its val is updated.
Returns:
* 1 If key was added/updated.
* -1 On error. */
int lbst_insert(lbst_T root, char *key, void *val);
/* Deletes a key from the dictionary.
Returns:
* 1 If the key is found and deleted.
* 0 If the key is not found. */
int lbst_delete(lbst_T root, char *key);
/* Searches for a key in the dictionary.
If found, it returns the a pointer to its val, else it returns NULL. */
void *lbst_lookup(lbst_T root, char *key);
/* Returns 1 if dictionary has no keys, 0 otherwise */
int lbst_is_empty(lbst_T root);
/* Creates and returns an empty dictionary. Its (key, val) pairs have
type (char*, void*).
Returns NULL on fail.*/
lbst_T lbst_create();
/* Clears the dictionary. The function lbst_is_empty() returns 1 after
calling this one. */
void lbst_clear(lbst_T root);
/* Deletes the dictionary. */
void lbst_free(lbst_T root);
/* Prints (key, val) that satisfy first <= key <= last. */
void lbst_range_query(lbst_T root, char *first, char *last, void (*print)(char *key, void *val));
/* Prints the dictionary. (key, val) pairs are sorted by key (ascending). */
void lbst_print(lbst_T root, void (*print)(char *key, void *val));
#endif