1 typedef struct _Trie *Trie;
7 * Create a new trie. Return a Trie structure, which is an abstract
8 * data structure. The client should not have to know about the
9 * details of this structure. When finished, each Trie should be
10 * freed with Trie_del.
17 * Free a Trie data structure.
19 void Trie_del(Trie trie);
24 * Set a string in the Trie to some value. Returns a 0 if the
27 int Trie_set(Trie trie, const unsigned char *key, const void *value);
31 * Lookup whether a key exists in the Trie. Returns the value that
32 * was previous set in the Trie, or NULL if it doesn't exist.
34 void *Trie_get(const Trie trie, const unsigned char *key);
37 /* Trie_get_approximate
38 * --------------------
39 * Lookup whether a key exists in the Trie, allowing for mismatches to
40 * the dictionary. Passes back values using a callback function.
43 Trie_get_approximate(const Trie trie, const unsigned char *key, const int k,
44 void (*callback)(const unsigned char *key,
53 * Return the number of strings in the trie.
55 int Trie_len(const Trie trie);
60 * Return whether a key exists in the trie.
62 int Trie_has_key(const Trie trie, const unsigned char *key);
67 * Return whether a string is a prefix of a key in the trie.
69 int Trie_has_prefix(const Trie trie, const unsigned char *prefix);
74 * Iterate over all the keys in the trie that start with a prefix.
76 void Trie_with_prefix(const Trie trie, const unsigned char *prefix,
77 void (*callback)(const unsigned char *key,
86 * Iterate through everything stored in the trie. callback is a
87 * function that gets called for each thing in the trie. It is called
88 * in arbitrary order. data is a pointer to some arbitrary data and
89 * gets passed unchanged to the callback.
91 void Trie_iterate(const Trie trie,
92 void (*callback)(const unsigned char *key,
100 * Serialize a tree into a stream of bytes. This function takes a
101 * callback 'write' that should take a pointer to data and the length
102 * of the data in bytes. This will be called repeatedly until the
103 * whole Trie is serialized. When it is done, this function will call
104 * 'write' with a length of 0. Since the values are handled by the
105 * client, this function also takes a callback function 'write_value'
106 * so that the client can serialize their own values.
108 * This function is platform-dependent, so byte streams created on one
109 * machine may not necessarily port to another.
111 int Trie_serialize(const Trie trie,
112 int (*write)(const void *towrite, const int length,
114 int (*write_value)(const void *value, void *data),
121 * Deserialize a tree that was previously serialized with
122 * Trie_serialize. This function takes a callback 'read' that should
123 * read 'length' bytes and save it to 'wasread'. 'read_value' should
124 * read a value and return a pointer to it. 'data' is a pointer that
125 * will be passed unchanged to 'read' and 'read_value'.
127 Trie Trie_deserialize(int (*read)(void *wasread, const int length, void *data),
128 void *(*read_value)(void *data),