November 07, 2008
Beyond B-TreesUser-Defined Indexes
eXtremeDB's user-defined index is not an index in its own right; rather, it extends a B-Tree to accept the user's specified comparison function. This is needed because applications use different rules for sorting string values. For example, an application might want to ignore a character's case, or compare values using the rules of a particular language.
By default, eXtremeDB uses "raw comparison" by comparing strings as sequences of bytes. Consider the class Person containing first and last names of the person:
If a case-insensitive index for Person's name is desired, it can be declared in the eXtremeDB schema description file using the userdef keyword:
Next, the comparison function is defined in a C file. This actually requires two functionsone to compare two objects, and another to compare a given key value to the index field value(s) of an object. The eXtremeDB schema compiler generates function prototypesprogrammers must only provide function bodies:
The user-defined function must be registered in the database before use. Another valuable application of user-defined functions is an implementation of the soundex algorithm to search based on the sound of a word rather than its exact spelling"wear," "where," and "ware," for instance.
Conclusion
Knowing something about specialized indexes enables faster development, more efficient code, and the ability to work with more complex data structures. Other "nontraditional" indexes worth exploring include the Patrice Trie (www.ddj.com/architect/208800854), KD-Trees (another spatial index), T-Trees for in-memory data access and storage, and Hash tables for quickly locating a single unique index entry.
|
|
||||||||||||||||||||||||||||||
|
|
|
|