Copying Bio-python to globplot to satisfy the dependency
[jabaws.git] / binaries / src / globplot / biopython-1.50 / Bio / trie.h
1 typedef struct _Trie *Trie;
2
3
4
5 /* Trie_new
6  * --------
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.
11  */
12 Trie Trie_new(void);
13
14
15 /* Trie_del
16  * --------
17  * Free a Trie data structure.
18  */
19 void Trie_del(Trie trie);
20
21
22 /* Trie_set
23  * --------
24  * Set a string in the Trie to some value.  Returns a 0 if the
25  * function succeeded.
26  */
27 int Trie_set(Trie trie, const unsigned char *key, const void *value);
28
29 /* Trie_get
30  * --------
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.
33  */
34 void *Trie_get(const Trie trie, const unsigned char *key);
35
36
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.
41  */
42 void 
43 Trie_get_approximate(const Trie trie, const unsigned char *key, const int k,
44                      void (*callback)(const unsigned char *key, 
45                                       const void *value,
46                                       const int mismatches,
47                                       void *data),
48                      void *data
49                      );
50
51 /* Trie_len
52  * --------
53  * Return the number of strings in the trie.
54  */
55 int Trie_len(const Trie trie);
56
57
58 /* Trie_has_key
59  * ------------
60  * Return whether a key exists in the trie.
61  */
62 int Trie_has_key(const Trie trie, const unsigned char *key);
63
64
65 /* Trie_has_prefix
66  * ---------------
67  * Return whether a string is a prefix of a key in the trie.
68  */
69 int Trie_has_prefix(const Trie trie, const unsigned char *prefix);
70
71
72 /* Trie_with_prefix
73  * ----------------
74  * Iterate over all the keys in the trie that start with a prefix.
75  */
76 void Trie_with_prefix(const Trie trie, const unsigned char *prefix,
77                       void (*callback)(const unsigned char *key, 
78                                        const void *value,
79                                        void *data),
80                       void *data
81                       );
82
83
84 /* Trie_iterate
85  * ------------
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.
90  */
91 void Trie_iterate(const Trie trie, 
92                   void (*callback)(const unsigned char *key, 
93                                    const void *value,
94                                    void *data),
95                   void *data
96                   );
97
98 /* Trie_serialize
99  * --------------
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.
107  *
108  * This function is platform-dependent, so byte streams created on one
109  * machine may not necessarily port to another.
110  */
111 int Trie_serialize(const Trie trie, 
112                    int (*write)(const void *towrite, const int length, 
113                                 void *data),
114                    int (*write_value)(const void *value, void *data),
115                    void *data);
116
117
118
119 /* Trie_deserialize
120  * ----------------
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'.
126  */
127 Trie Trie_deserialize(int (*read)(void *wasread, const int length, void *data),
128                       void *(*read_value)(void *data),
129                       void *data);