2005-09-15 09:58:31 -04:00
|
|
|
#ifndef EL__UTIL_FASTFIND_H
|
|
|
|
#define EL__UTIL_FASTFIND_H
|
|
|
|
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Whether to use these routines or not. */
|
2005-09-15 09:58:31 -04:00
|
|
|
#ifndef CONFIG_SMALL
|
|
|
|
#define USE_FASTFIND 1
|
|
|
|
#else
|
|
|
|
#undef USE_FASTFIND
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_FASTFIND
|
|
|
|
|
|
|
|
struct fastfind_key_value {
|
|
|
|
unsigned char *key;
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum fastfind_flags {
|
|
|
|
FF_NONE = 0,
|
2007-07-27 05:35:13 -04:00
|
|
|
FF_CASE_AWARE = 1, /**< honour case when comparing */
|
|
|
|
FF_COMPRESS = 2, /**< compress nodes if possible */
|
2005-09-15 09:58:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct fastfind_index {
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Description useful for debugging mode. */
|
2005-09-15 09:58:31 -04:00
|
|
|
unsigned char *comment;
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Start over. */
|
2005-09-15 09:58:31 -04:00
|
|
|
void (*reset)(void);
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Get next struct fastfind_key_value in line. */
|
2005-09-15 09:58:31 -04:00
|
|
|
struct fastfind_key_value *(*next)(void);
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Internal reference */
|
2005-09-15 09:58:31 -04:00
|
|
|
void *handle;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define INIT_FASTFIND_INDEX(comment, reset, next) \
|
|
|
|
{ (comment), (reset), (next) }
|
|
|
|
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Initialize and index a list of keys.
|
|
|
|
* Keys are iterated using:
|
|
|
|
* @param index index info
|
|
|
|
* @param flags control case sensitivity, compression
|
|
|
|
*
|
|
|
|
* This function must be called once and only once per list.
|
|
|
|
* Failure is not an option, so call it at startup. */
|
2005-09-15 09:58:31 -04:00
|
|
|
struct fastfind_index *fastfind_index(struct fastfind_index *index, enum fastfind_flags flags);
|
|
|
|
|
|
|
|
/* The main reason of all that stuff is here. */
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Search the index for @a key with length @a key_len using the
|
|
|
|
* @a index' handle created with fastfind_index(). */
|
2005-09-15 09:58:31 -04:00
|
|
|
void *fastfind_search(struct fastfind_index *index, unsigned char *key, int key_len);
|
|
|
|
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Fastfind cleanup. It frees the given @a index.
|
|
|
|
* Must be called once per list. */
|
2005-09-15 09:58:31 -04:00
|
|
|
void fastfind_done(struct fastfind_index *index);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* EL__UTIL_FASTFIND_H */
|