Hash Index

Hash Index — Hash index.

Synopsis


#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);

Description

Details

HIndexFunc ()

void        (*HIndexFunc)                   (HTuple *tuple,
                                             gpointer value,
                                             gpointer user_data);

tuple : a HTuple key
value : value
user_data : user data

HValueFunc ()

void        (*HValueFunc)                   (gpointer value,
                                             gpointer user_data);

value : value
user_data : user data

HHashIndex

typedef struct _HHashIndex HHashIndex;

A hash table index.


h_hash_index_new ()

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

h_hash_index_new_l ()

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

h_hash_index_free ()

void        h_hash_index_free               (HHashIndex *index);

Frees index.

index : HHashIndex to free

h_hash_index_get_size ()

guint       h_hash_index_get_size           (HHashIndex *index);

Returns the number of elements in index.

index : a HHashIndex
Returns : number of elements

h_hash_index_get_attrs ()

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.

h_hash_index_lookup ()

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

h_hash_index_insert ()

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

h_hash_index_replace ()

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

h_hash_index_remove ()

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

h_hash_index_foreach ()

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

h_hash_index_for_each_value ()

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