Basic explanation of how search table works:
A search_table is a global object. Only one of these is expected to exist. It consists of a number of "bins", each bin containing all entries which have a certain sequence of two characters in a row, plus some metadata.
Each bin is a simple array, without repetitions, of items. Each item consists of a string to which a certain mapping of characters onto characters has been applied, plus a void * representing the actual data mapped to. (I used void * to make this code reasonably generic, so that in any project I or someone else wants to use code like this for, they can just use it.) The same mapping is also applied to each search before running it. This maps uppercase and lowercase letters to match one another, maps all whitespace and punctuation to a simple space, etc. This mechanism is very flexible and could easily be adapted to match accented characters, etc.
The actual search builds a regular expression to do the matching. This might have a tiny bit higher overhead than a custom implementation of string matching, but it also allows a great deal of flexibility and ease of experimentation with different search techniques, both to increase efficiency and to give the best possible results. Hopefully the code is reasonably self-explanatory, but if you find it confusing, email the gtk-gnutella-devel mailing list and I'll try to respond...
Go to the source code of this file.
Data Structures | |
struct | st_entry |
struct | st_bin |
struct | _search_table |
Typedefs | |
typedef guint8 | char_map_t [256] |
Maps one char to another. | |
typedef _search_table | search_table_t |
typedef void(* | st_search_callback )(gpointer ctx, struct shared_file *sf) |
Needs brief description here. | |
Functions | |
size_t | match_map_string (char_map_t map, gchar *string) |
Apply a char map to a string, inplace. | |
void | st_initialize (search_table_t *, char_map_t) |
Initialize permanent data in search table. | |
void | st_create (search_table_t *table) |
Recreate variable parts of the search table. | |
void | st_destroy (search_table_t *) |
Destroy a search table. | |
void | st_insert_item (search_table_t *, const gchar *, struct shared_file *) |
Insert an item into the search_table one-char strings are silently ignored. | |
void | st_compact (search_table_t *) |
Minimize space consumption. | |
void | st_search (search_table_t *table, gchar *search, st_search_callback callback, gpointer ctx, gint max_res, struct query_hashvec *qhv) |
|
Maps one char to another.
|
|
|
|
Needs brief description here.
|
|
Apply a char map to a string, inplace.
|
|
Minimize space consumption.
|
|
Recreate variable parts of the search table.
|
|
Destroy a search table.
|
|
Initialize permanent data in search table.
|
|
Insert an item into the search_table one-char strings are silently ignored.
|
|
|