![]() |
![]() |
![]() |
Holyrel Library Reference Manual | ![]() |
---|
Hash IndexHash Index — Hash index. |
#include <libhrel/relation.h> void (*HIndexFunc) (HTuple *tuple, gpointer value, gpointer user_data); void (*HValueFunc) (gpointer value, gpointer user_data); HHashIndex; HHashIndex* h_hash_index_new (GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func, ...); HHashIndex* h_hash_index_new_l (GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func, GSList *list); void h_hash_index_free (HHashIndex *index); guint h_hash_index_get_size (HHashIndex *index); GSList* h_hash_index_get_attrs (HHashIndex *index); gpointer h_hash_index_lookup (HHashIndex *index, HTuple *tuple); void h_hash_index_insert (HHashIndex *index, HTuple *tuple, gpointer value); void h_hash_index_replace (HHashIndex *index, HTuple *tuple, gpointer value); gboolean h_hash_index_remove (HHashIndex *index, HTuple *tuple); void h_hash_index_foreach (HHashIndex *index, HIndexFunc func, gpointer user_data); void h_hash_index_for_each_value (HHashIndex *index, HValueFunc func, gpointer user_data);
void (*HIndexFunc) (HTuple *tuple, gpointer value, gpointer user_data);
tuple : |
a HTuple key |
value : |
value |
user_data : |
user data |
void (*HValueFunc) (gpointer value, gpointer user_data);
value : |
value |
user_data : |
user data |
HHashIndex* h_hash_index_new (GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func, ...);
Creates a new hash index.
key_destroy_func : |
key destructor, or NULL if none
|
value_destroy_func : |
value destructor, or NULL if none
|
... : |
name of an attribute, followed by another, and so on, then NULL ; if no names are listed, all attributes are used for hashing
|
Returns : | a newly created HHashIndex |
HHashIndex* h_hash_index_new_l (GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func, GSList *list);
A variation of h_hash_index_new()
, where the attribute name list is
stored in a GSList.
key_destroy_func : |
key destructor, or NULL if none
|
value_destroy_func : |
value destructor, or NULL if none
|
list : |
list of attribute names |
Returns : | a newly created HHashIndex |
void h_hash_index_free (HHashIndex *index);
Frees index
.
index : |
HHashIndex to free |
guint h_hash_index_get_size (HHashIndex *index);
Returns the number of elements in index
.
index : |
a HHashIndex |
Returns : | number of elements |
GSList* h_hash_index_get_attrs (HHashIndex *index);
Returns the list of attributes used for hashing.
index : |
a HHashIndex |
Returns : | list of attribute names. This must not be freed. |
gpointer h_hash_index_lookup (HHashIndex *index, HTuple *tuple);
Looks up a key in index
. Note that this function cannot
distinguish between a key is not present and one which is present
and has the value NULL
.
index : |
a HHashIndex |
tuple : |
a HTuple key to lookup |
Returns : | associated value, or NULL if the key is not found
|
void h_hash_index_insert (HHashIndex *index, HTuple *tuple, gpointer value);
Inserts a new key and value into index
. If the key already exists,
its current value is replaced with the new value. If
value_destroy_func
was supplied when creating index
, the old
value is freed using it. If key_destroy_func
was supplied when
creating index
, the passed key is freed using it.
index : |
a HHashIndex |
tuple : |
a HTuple key to insert |
value : |
value associated with key |
void h_hash_index_replace (HHashIndex *index, HTuple *tuple, gpointer value);
Inserts a new key and value into index
. This is a version of
h_hash_index_insert()
which replaces the old key with the
passed key and calls key_destroy_func
on the former.
index : |
a HHashIndex |
tuple : |
a HTuple key to insert |
value : |
value associated with key |
gboolean h_hash_index_remove (HHashIndex *index, HTuple *tuple);
Removes a new key and its associated value from index
.
index : |
a HHashIndex |
tuple : |
a HTuple key to remove |
Returns : | TRUE if key was found and removed |
void h_hash_index_foreach (HHashIndex *index, HIndexFunc func, gpointer user_data);
Performs a function over each key/value pair in index
.
index : |
a HHashIndex |
func : |
function called for each key/value pair in index
|
user_data : |
custom data to pass to func
|
void h_hash_index_for_each_value (HHashIndex *index, HValueFunc func, gpointer user_data);
Performs a function over each key/value pair in index
.
index : |
a HHashIndex |
func : |
function called for each value in index
|
user_data : |
custom data to pass to func
|
<< Indexes | AVL Tree Index >> |