Back to index

python-biopython  1.60
trie.h
Go to the documentation of this file.
00001 typedef struct Trie Trie; /* forward declaration */
00002 
00003 
00004 
00005 /* Trie_new
00006  * --------
00007  * Create a new trie.  Return a Trie structure, which is an abstract
00008  * data structure.  The client should not have to know about the
00009  * details of this structure.  When finished, each Trie should be
00010  * freed with Trie_del.
00011  */
00012 Trie* Trie_new(void);
00013 
00014 
00015 /* Trie_del
00016  * --------
00017  * Free a Trie data structure.
00018  */
00019 void Trie_del(Trie* trie);
00020 
00021 
00022 /* Trie_set
00023  * --------
00024  * Set a string in the Trie to some value.  Returns a 0 if the
00025  * function succeeded.
00026  */
00027 int Trie_set(Trie* trie, const char *key, const void *value);
00028 
00029 /* Trie_get
00030  * --------
00031  * Lookup whether a key exists in the Trie.  Returns the value that
00032  * was previous set in the Trie, or NULL if it doesn't exist.
00033  */
00034 void *Trie_get(const Trie* trie, const char *key);
00035 
00036 
00037 /* Trie_get_approximate
00038  * --------------------
00039  * Lookup whether a key exists in the Trie, allowing for mismatches to
00040  * the dictionary.  Passes back values using a callback function.
00041  */
00042 void 
00043 Trie_get_approximate(const Trie* trie, const char *key, const int k,
00044                    void (*callback)(const char *key, 
00045                                   const void *value,
00046                                   const int mismatches,
00047                                   void *data),
00048                    void *data
00049                    );
00050 
00051 /* Trie_len
00052  * --------
00053  * Return the number of strings in the trie.
00054  */
00055 int Trie_len(const Trie* trie);
00056 
00057 
00058 /* Trie_has_key
00059  * ------------
00060  * Return whether a key exists in the trie.
00061  */
00062 int Trie_has_key(const Trie* trie, const char *key);
00063 
00064 
00065 /* Trie_has_prefix
00066  * ---------------
00067  * Return whether a string is a prefix of a key in the trie.
00068  */
00069 int Trie_has_prefix(const Trie* trie, const char *prefix);
00070 
00071 
00072 /* Trie_with_prefix
00073  * ----------------
00074  * Iterate over all the keys in the trie that start with a prefix.
00075  */
00076 void Trie_with_prefix(const Trie* trie, const char *prefix,
00077                     void (*callback)(const char *key, 
00078                                    const void *value,
00079                                    void *data),
00080                     void *data
00081                     );
00082 
00083 
00084 /* Trie_iterate
00085  * ------------
00086  * Iterate through everything stored in the trie.  callback is a
00087  * function that gets called for each thing in the trie.  It is called
00088  * in arbitrary order.  data is a pointer to some arbitrary data and
00089  * gets passed unchanged to the callback.
00090  */
00091 void Trie_iterate(const Trie* trie, 
00092                 void (*callback)(const char *key, 
00093                                const void *value,
00094                                void *data),
00095                 void *data
00096                 );
00097 
00098 /* Trie_serialize
00099  * --------------
00100  * Serialize a tree into a stream of bytes.  This function takes a
00101  * callback 'write' that should take a pointer to data and the length
00102  * of the data in bytes.  This will be called repeatedly until the
00103  * whole Trie is serialized.  When it is done, this function will call
00104  * 'write' with a length of 0.  Since the values are handled by the
00105  * client, this function also takes a callback function 'write_value'
00106  * so that the client can serialize their own values.
00107  *
00108  * This function is platform-dependent, so byte streams created on one
00109  * machine may not necessarily port to another.
00110  */
00111 int Trie_serialize(const Trie* trie, 
00112                  int (*write)(const void *towrite, const int length, 
00113                             void *data),
00114                  int (*write_value)(const void *value, void *data),
00115                  void *data);
00116 
00117 
00118 
00119 /* Trie_deserialize
00120  * ----------------
00121  * Deserialize a tree that was previously serialized with
00122  * Trie_serialize.  This function takes a callback 'read' that should
00123  * read 'length' bytes and save it to 'wasread'.  'read_value' should
00124  * read a value and return a pointer to it.  'data' is a pointer that
00125  * will be passed unchanged to 'read' and 'read_value'.
00126  */
00127 Trie* Trie_deserialize(int (*read)(void *wasread, const int length, void *data),
00128                     void *(*read_value)(void *data),
00129                     void *data);