Tizen Native API
|
Functions | |
Eina_Hash * | eina_hash_new (Eina_Key_Length key_length_cb, Eina_Key_Cmp key_cmp_cb, Eina_Key_Hash key_hash_cb, Eina_Free_Cb data_free_cb, int buckets_power_size) |
Creates a new hash table. | |
void | eina_hash_free_cb_set (Eina_Hash *hash, Eina_Free_Cb data_free_cb) |
Redefines the callback that cleans the data of a hash. | |
Eina_Hash * | eina_hash_string_djb2_new (Eina_Free_Cb data_free_cb) |
Creates a new hash table using the djb2 algorithm. | |
Eina_Hash * | eina_hash_string_superfast_new (Eina_Free_Cb data_free_cb) |
Creates a new hash table for use with strings. | |
Eina_Hash * | eina_hash_string_small_new (Eina_Free_Cb data_free_cb) |
Creates a new hash table for use with strings having a small bucket size. | |
Eina_Hash * | eina_hash_int32_new (Eina_Free_Cb data_free_cb) |
Creates a new hash table for use with 32 bit integers. | |
Eina_Hash * | eina_hash_int64_new (Eina_Free_Cb data_free_cb) |
Creates a new hash table for use with 64 bit integers. | |
Eina_Hash * | eina_hash_pointer_new (Eina_Free_Cb data_free_cb) |
Creates a new hash table for use with pointers. | |
Eina_Hash * | eina_hash_stringshared_new (Eina_Free_Cb data_free_cb) |
Creates a new hash table optimized for stringshared values. | |
Eina_Bool | eina_hash_add (Eina_Hash *hash, const void *key, const void *data) |
Adds an entry to the given hash table. | |
Eina_Bool | eina_hash_direct_add (Eina_Hash *hash, const void *key, const void *data) |
Adds an entry to the given hash table without duplicating the string key. | |
Eina_Bool | eina_hash_del (Eina_Hash *hash, const void *key, const void *data) |
Removes the entry identified by a key or data from the given hash table. | |
void * | eina_hash_find (const Eina_Hash *hash, const void *key) |
Finds a specific entry in the given hash table. | |
void * | eina_hash_modify (Eina_Hash *hash, const void *key, const void *data) |
Modifies the entry pointer at the specified key and returns the old entry. | |
void * | eina_hash_set (Eina_Hash *hash, const void *key, const void *data) |
Modifies the entry pointer at the specified key and returns the old entry or adds the entry if not found. | |
Eina_Bool | eina_hash_move (Eina_Hash *hash, const void *old_key, const void *new_key) |
Changes the key associated with the data without triggering the free callback. | |
void | eina_hash_free (Eina_Hash *hash) |
Frees the given hash table resources. | |
void | eina_hash_free_buckets (Eina_Hash *hash) |
Frees the given hash table buckets resources. | |
int | eina_hash_population (const Eina_Hash *hash) |
Returns the number of entries in the given hash table. | |
Eina_Bool | eina_hash_add_by_hash (Eina_Hash *hash, const void *key, int key_length, int key_hash, const void *data) |
Adds an entry to the given hash table. | |
Eina_Bool | eina_hash_direct_add_by_hash (Eina_Hash *hash, const void *key, int key_length, int key_hash, const void *data) |
Adds an entry to the given hash table and does not duplicate the string key. | |
Eina_Bool | eina_hash_del_by_key_hash (Eina_Hash *hash, const void *key, int key_length, int key_hash) |
Removes the entry identified by a key and a key hash from the given hash table. | |
Eina_Bool | eina_hash_del_by_key (Eina_Hash *hash, const void *key) |
Removes the entry identified by a key from the given hash table. | |
Eina_Bool | eina_hash_del_by_data (Eina_Hash *hash, const void *data) |
Removes the entry identified by data from the given hash table. | |
Eina_Bool | eina_hash_del_by_hash (Eina_Hash *hash, const void *key, int key_length, int key_hash, const void *data) |
Removes the entry identified by a key and a key hash or the data from the given hash table. | |
void * | eina_hash_find_by_hash (const Eina_Hash *hash, const void *key, int key_length, int key_hash) |
Retrieves a specific entry in the given hash table. | |
void * | eina_hash_modify_by_hash (Eina_Hash *hash, const void *key, int key_length, int key_hash, const void *data) |
Modifies the entry pointer at the specified key and returns the old entry. | |
Eina_Iterator * | eina_hash_iterator_key_new (const Eina_Hash *hash) |
Returns a new iterator associated to hash keys. | |
Eina_Iterator * | eina_hash_iterator_data_new (const Eina_Hash *hash) |
Returns a new iterator associated to hash data. | |
Eina_Iterator * | eina_hash_iterator_tuple_new (const Eina_Hash *hash) |
Returns a new iterator associated to hash keys and data. | |
void | eina_hash_foreach (const Eina_Hash *hash, Eina_Hash_Foreach func, const void *fdata) |
Calls a function on every member stored in the hash table. | |
int | eina_hash_superfast (const char *key, int len) |
Paul Hsieh (http://www.azillionmonkeys.com/qed/hash.html) hash function used by WebCore (http://webkit.org/blog/8/hashtables-part-2/) | |
static int | eina_hash_djb2 (const char *key, int len) |
static int | eina_hash_djb2_len (const char *key, int *plen) |
static int | eina_hash_int32 (const unsigned int *pkey, int len) |
static int | eina_hash_int64 (const unsigned long int *pkey, int len) |
static int | eina_hash_murmur3 (const char *key, int len) |
Typedefs | |
typedef struct _Eina_Hash | Eina_Hash |
The structure type for a generic hash table. | |
typedef struct _Eina_Hash_Tuple | Eina_Hash_Tuple |
typedef unsigned int(* | Eina_Key_Length )(const void *key) |
typedef int(* | Eina_Key_Cmp )(const void *key1, int key1_length, const void *key2, int key2_length) |
typedef int(* | Eina_Key_Hash )(const void *key, int key_length) |
typedef Eina_Bool(* | Eina_Hash_Foreach )(const Eina_Hash *hash, const void *key, void *data, void *fdata) |
Defines | |
#define | EINA_KEY_LENGTH(Function) ((Eina_Key_Length)Function) |
#define | EINA_KEY_CMP(Function) ((Eina_Key_Cmp)Function) |
#define | EINA_KEY_HASH(Function) ((Eina_Key_Hash)Function) |
Performs hash table management. It is useful for mapping keys to values.
The hash table is useful when one wants to implement a table that maps keys (usually strings) to data, and have relatively fast access time. The performance is proportional to the load factor of the table (number of elements / number of buckets). See Algorithm for implementation details.
Different implementations exist depending on what kind of key is used to access the data: strings, integers, pointers, stringshared, or your own key.
Eina hash tables can copy keys by using eina_hash_add() or not copy by using eina_hash_direct_add().
The Eina_Hash is implemented using an array of N "buckets", where each bucket is a pointer to a structure that is the head of a red-black tree. The array can then be indexed by the [hash_of_element mod N]. The hash_of_element is calculated using the hashing function, passed as a parameter to the eina_hash_new function. N is the number of buckets (array positions), and is calculated based on the buckets_power_size (argument of eina_hash_new too). The following picture ilustrates the basic idea:
Adding an element to the hash table consists of:
The first two steps have constant time, proportional to the hash function being used. Adding the key to the rbtree is proportional to the number of keys on that bucket.
The average cost of lookup depends on the number of keys per bucket (load factor) of the table, if the distribution of the keys is sufficiently uniform.
As said before, the performance depends on the load factor. So trying to keep the load factor as small as possible improves the hash table performance. But increasing the buckets_power_size also increases the memory consumption. The default hash table creation functions already have a good number of buckets, enough for most cases. Particularly for strings, if just a few keys (less than 30) are added to the hash table, eina_hash_string_small_new should be used, since it reduces the memory consumption for the buckets, and you still won't have many collisions. However, eina_hash_string_small_new still uses the same hash calculation function that eina_hash_string_superfast_new uses, which is more complex than eina_hash_string_djb2_new. The latter has a faster hash computation function, but that implies to a not so good distribution. But if just a few keys are being added, this is not a problem, it still does not have many collisions and is faster in calculating the hash than when a hash is created with eina_hash_string_small_new and eina_hash_string_superfast_new.
A simple comparison between them would be:
djb2
- faster hash function - 256 buckets (higher memory consumption) string_small
- slower hash function but less collisions - 32 buckets (lower memory consumption) string_superfast
- slower hash function but less collisions - 256 buckets (higher memory consumption)Basically for a very small number of keys (10 or less), djb2
should be used, or string_small
if you have a restriction on memory usage. And for a higher number of keys, string_superfast
should always be preferred.
If just stringshared keys are being added, use eina_hash_stringshared_new. If a lot of keys are added to the hash table (e.g. more than 1000), then it's better to increase the buckets_power_size. See eina_hash_new for more details.
When adding a new key to a hash table, use eina_hash_add or eina_hash_direct_add (the latter is if this key is already stored elsewhere). If the key may be already inside the hash table, instead of checking with eina_hash_find and then doing eina_hash_add, one can use just eina_hash_set (this changes the data pointed by this key if it is already present in the table).
#define EINA_KEY_CMP | ( | Function | ) | ((Eina_Key_Cmp)Function) |
Function | The function used to compare the hash key |
#define EINA_KEY_HASH | ( | Function | ) | ((Eina_Key_Hash)Function) |
Function | The function used to hash the key. |
#define EINA_KEY_LENGTH | ( | Function | ) | ((Eina_Key_Length)Function) |
Function | The function used to calculate the length of the hash key |
Type for a function to iterate over a hash table.
Type for a hash table of key/value pairs.
Type for a function to compare two hash keys.
Type for a function to create a hash key.
Type for a function to determine the length of a hash key.
Eina_Bool eina_hash_add | ( | Eina_Hash * | hash, |
const void * | key, | ||
const void * | data | ||
) |
Adds an entry to the given hash table.
This function adds key to hash. key is expected to be unique within the hash table. The key's uniqueness varies depending on the type of hash: a stringshared Eina_Hash needs to have unique pointers (which implies unique strings). All other string hash types require the strings themselves to be unique. Pointer, int32 and int64 hashes need to have these values as unique. Failure to use sufficient uniqueness results in unexpected results when inserting data pointers accessed by eina_hash_find() and removed by eina_hash_del().
[in] | hash | The given hash table It cannot be NULL . |
[in] | key | A unique key It cannot be NULL . |
[in] | data | The data to associate with the string given by key It cannot be NULL . |
EINA_FALSE
if an error occurs, otherwise EINA_TRUE
Eina_Bool eina_hash_add_by_hash | ( | Eina_Hash * | hash, |
const void * | key, | ||
int | key_length, | ||
int | key_hash, | ||
const void * | data | ||
) |
Adds an entry to the given hash table.
This function adds key to hash. hash, key, and data cannot be NULL
, in that case EINA_FALSE
is returned. key is expected to be unique within the hash table. Otherwise, one cannot be sure which inserted data pointer is accessed by eina_hash_find, and removed by eina_hash_del. Do not forget to count '\0' for string when setting the value of key_length. key_hash is expected to always match key. Otherwise, one cannot be sure to find it again with eina_hash_find_by_hash.
[in] | hash | The given hash table It cannot be NULL . |
[in] | key | A unique key It cannot be NULL . |
[in] | key_length | The length of the key |
[in] | key_hash | The hash that always matches the key |
[in] | data | The data to associate with the string given by the key It cannot be NULL . |
EINA_FALSE
if an error occurs, otherwise EINA_TRUE
Eina_Bool eina_hash_del | ( | Eina_Hash * | hash, |
const void * | key, | ||
const void * | data | ||
) |
Removes the entry identified by a key or data from the given hash table.
This function removes the entry identified by key or data from hash. If a free function is given to the callback on creation, it is called for the data being deleted. If hash is NULL
, the functions returns EINA_FALSE
immediately. If key is NULL
, then data is used to find the match to remove, otherwise key is used and data is not required and can be NULL
. This function returns EINA_FALSE
if an error occurs, otherwise it returns EINA_TRUE.
[in] | hash | The given hash table |
[in] | key | The key |
[in] | data | The data pointer to remove if the key is NULL |
EINA_FALSE
if an error occurs, otherwise EINA_TRUE
Eina_Bool eina_hash_del_by_data | ( | Eina_Hash * | hash, |
const void * | data | ||
) |
Removes the entry identified by data from the given hash table.
This function removes the entry identified by data from hash. If a free function is given to the callback on creation, it is called for the data being deleted. If hash or data is NULL
, the functions return EINA_FALSE
immediately. This function returns EINA_FALSE
if an error occurs, otherwise it returns EINA_TRUE
.
[in] | hash | The given hash table It cannot be NULL . |
[in] | data | The data value to search and remove It cannot be NULL . |
EINA_FALSE
if an error occurs, otherwise EINA_TRUE
on success Eina_Bool eina_hash_del_by_hash | ( | Eina_Hash * | hash, |
const void * | key, | ||
int | key_length, | ||
int | key_hash, | ||
const void * | data | ||
) |
Removes the entry identified by a key and a key hash or the data from the given hash table.
This function removes the entry identified by key and key_hash, or data, from hash. If a free function is given to the callback on creation, it is called for the data being deleted. If hash is NULL
, the functions return EINA_FALSE
immediately. If key is NULL
, then key_length and key_hash are ignored and data is used to find a match to remove, otherwise key and key_hash are used and data is not required and can be NULL
. Do not forget to count '\0' for string when setting the value of key_length. This function returns EINA_FALSE
if an error occurs, otherwise it returns EINA_TRUE
.
NULL
, then data is used to find a match to remove.[in] | hash | The given hash table It cannot be NULL . |
[in] | key | The key |
[in] | key_length | The length of the key |
[in] | key_hash | The hash that always matches the key |
[in] | data | The data pointer to remove if the key is NULL |
EINA_FALSE
if an error occurs, otherwise EINA_TRUE
Eina_Bool eina_hash_del_by_key | ( | Eina_Hash * | hash, |
const void * | key | ||
) |
Removes the entry identified by a key from the given hash table.
This function removes the entry identified by key from hash. The key length and hash is calculated automatically by using functions provided to the hash creation function. If a free function is given to the callback on creation, it is called for the data being deleted. If hash or key is NULL
, the functions return EINA_FALSE
immediately. This function returns EINA_FALSE
if an error occurs, otherwise it returns EINA_TRUE
.
[in] | hash | The given hash table It cannot be NULL . |
[in] | key | The key It cannot be NULL . |
EINA_FALSE
if an error occurs, otherwise EINA_TRUE
Eina_Bool eina_hash_del_by_key_hash | ( | Eina_Hash * | hash, |
const void * | key, | ||
int | key_length, | ||
int | key_hash | ||
) |
Removes the entry identified by a key and a key hash from the given hash table.
This function removes the entry identified by key and key_hash from hash. If a free function is given to the callback on creation, it is called for the data being deleted. Do not forget to count '\0' for string when setting the value of key_length. If hash or key is NULL
, the functions return EINA_FALSE
immediately. This function returns EINA_FALSE
if an error occurs, otherwise it returns EINA_TRUE
.
[in] | hash | The given hash table It cannot be NULL . |
[in] | key | The key It cannot be NULL . |
[in] | key_length | The length of the key |
[in] | key_hash | The hash that always matches the key |
EINA_FALSE
if an error occurs, otherwise EINA_TRUE
Eina_Bool eina_hash_direct_add | ( | Eina_Hash * | hash, |
const void * | key, | ||
const void * | data | ||
) |
Adds an entry to the given hash table without duplicating the string key.
This function adds key to hash. key is expected to be unique within the hash table. The key's uniqueness varies depending on the type of hash: a stringshared Eina_Hash needs to have unique pointers (which implies unique strings). All other string hash types require the strings themselves to be unique. Pointer, int32 and int64 hashes need to have these values as unique. Failure to use sufficient uniqueness results in unexpected results when inserting data pointers accessed by eina_hash_find() and removed by eina_hash_del().
[in] | hash | The given hash table It cannot be NULL . |
[in] | key | A unique key It cannot be NULL . |
[in] | data | The data to associate with the string given by key It cannot be NULL . |
EINA_FALSE
if an error occurs, ptherwise EINA_TRUE
Eina_Bool eina_hash_direct_add_by_hash | ( | Eina_Hash * | hash, |
const void * | key, | ||
int | key_length, | ||
int | key_hash, | ||
const void * | data | ||
) |
Adds an entry to the given hash table and does not duplicate the string key.
This function adds key to hash. hash, key, and data can be NULL
, in that case EINA_FALSE
is returned. key is expected to be unique within the hash table. Otherwise, one cannot be sure which inserted data pointer is going to be accessed by eina_hash_find, and removed by eina_hash_del. This function does not make a copy of key so it must be a string constant or should be stored elsewhere (in the object being added). Do not forget to count '\0' for string when setting the value of key_length. key_hash is expected to always match key. Otherwise, one cannot be sure to find it again with eina_hash_find_by_hash.
[in] | hash | The given hash table It cannot be NULL . |
[in] | key | A unique key It cannot be NULL . |
[in] | key_length | The length of key (don't forget to count '\0' for string). |
[in] | key_hash | The hash that always matches the key. |
[in] | data | The data to associate with the string given by key It cannot be NULL . |
EINA_FALSE
if an error occurs, otherwise EINA_TRUE
static int eina_hash_djb2 | ( | const char * | key, |
int | len | ||
) | [static] |
The djb2 hash function
[in] | key | The key to hash |
[in] | len | The length of the key |
static int eina_hash_djb2_len | ( | const char * | key, |
int * | plen | ||
) | [static] |
The djb2 hash function withoug length
[in] | key | The key to hash |
[out] | plen | The length of the key to be returned |
void* eina_hash_find | ( | const Eina_Hash * | hash, |
const void * | key | ||
) |
Finds a specific entry in the given hash table.
This function retrieves the entry associated to key in hash. If hash is NULL
, this function returns NULL
immediately. This function returns the data pointer on success, otherwise it returns NULL
.
[in] | hash | The given hash table |
[in] | key | The key of the entry to find |
NULL
void* eina_hash_find_by_hash | ( | const Eina_Hash * | hash, |
const void * | key, | ||
int | key_length, | ||
int | key_hash | ||
) |
Retrieves a specific entry in the given hash table.
This function retrieves the entry associated to key of length key_length in hash. key_hash is the hash that always matches key. It is ignored if key is NULL
. Do not forget to count '\0' for string when setting the value of key_length. If hash is NULL
, this function returns NULL
immediately. This function returns the data pointer on success, otherwise it returns NULL
.
[in] | hash | The given hash table It cannot be NULL . |
[in] | key | The key of the entry to find |
[in] | key_length | The length of the key |
[in] | key_hash | The hash that always matches the key |
NULL
void eina_hash_foreach | ( | const Eina_Hash * | hash, |
Eina_Hash_Foreach | func, | ||
const void * | fdata | ||
) |
Calls a function on every member stored in the hash table.
This function goes through every entry in the hash table hash and calls the function func on each member. The function should not modify the hash table contents if it returns 1
. If the hash table contents are modified by this function or the function wishes to stop processing it, it must return 0
, otherwise it must return 1
to keep processing.
Example:
extern Eina_Hash *hash; Eina_Bool hash_fn(const Eina_Hash *hash, const void *key, void *data, void *fdata) { printf("Func data: %s, Hash entry: %s / %p\n", fdata, (const char *)key, data); return 1; } int main(int argc, char **argv) { char *hash_fn_data; hash_fn_data = strdup("Hello World"); eina_hash_foreach(hash, hash_fn, hash_fn_data); free(hash_fn_data); }
[in] | hash | The hash table whose members are walked |
[in] | func | The function to call on each parameter |
[in] | fdata | The data pointer to pass to the function being called |
void eina_hash_free | ( | Eina_Hash * | hash | ) |
Frees the given hash table resources.
This function frees up all the memory allocated to storing hash, and calls the free callback if it has been passed to the hash table at creation time. If no free callback has been passed, any entries in the table that the program has no more pointers for elsewhere may now be lost, so this should only be called if the program has already freed any allocated data in the hash table or has pointers for data in the table stored elsewhere as well. If hash is NULL
, the function returns immediately.
Example:
extern Eina_Hash *hash; eina_hash_free(hash); hash = NULL;
[in] | hash | The hash table to be freed |
void eina_hash_free_buckets | ( | Eina_Hash * | hash | ) |
Frees the given hash table buckets resources.
This function frees up all the memory allocated to storing the buckets of hash, and calls the free callback on all hash table buckets if it has been passed to the hash table at creation time, it then frees the buckets. If no free callback has been passed, no buckets value are freed. If hash is NULL
, the function returns immediately.
[in] | hash | The hash table whose buckets have to be freed |
void eina_hash_free_cb_set | ( | Eina_Hash * | hash, |
Eina_Free_Cb | data_free_cb | ||
) |
Redefines the callback that cleans the data of a hash.
[in] | hash | The given hash table |
[in] | data_free_cb | The function called on each value when the hash table is freed, or when an item is deleted from it NULL can be passed as callback to remove an existing callback. |
static int eina_hash_int32 | ( | const unsigned int * | pkey, |
int | len | ||
) | [static] |
The 32 bit integer hash function
[in] | pkey | The key to hash |
[in] | len | The length of the key |
Eina_Hash* eina_hash_int32_new | ( | Eina_Free_Cb | data_free_cb | ) |
Creates a new hash table for use with 32 bit integers.
This function creates a new hash table where keys are 32 bit integers. When adding or looking up in the hash table, pointers to 32 bit integers must be passed. They can be addresses on the stack if you let eina_hash copy the key. Values can then be looked up with pointers other than the original key pointer that is used to add values. This method is not suitable to match string keys as it would only match the first character. On failure, this function returns NULL
.
[in] | data_free_cb | The function called on each value when the hash table is freed, or when an item is deleted from it NULL can be passed as a callback. |
static int eina_hash_int64 | ( | const unsigned long int * | pkey, |
int | len | ||
) | [static] |
The 64 bit integer hash function
[in] | pkey | The key to hash |
[in] | len | The length of the key |
Eina_Hash* eina_hash_int64_new | ( | Eina_Free_Cb | data_free_cb | ) |
Creates a new hash table for use with 64 bit integers.
This function creates a new hash table where keys are 64 bit integers. When adding or looking up in the hash table, pointers to 64 bit integers must be passed. They can be addresses on the stack. Values can then be looked up with pointers other than the original key pointer that is used to add values. This method is not suitable to match string keys as it would only match the first character. On failure, this function returns NULL
.
[in] | data_free_cb | The function called on each value when the hash table is freed, or when an item is deleted from it NULL can be passed as a callback. |
Eina_Iterator* eina_hash_iterator_data_new | ( | const Eina_Hash * | hash | ) |
Returns a new iterator associated to hash data.
This function returns a newly allocated iterator associated to hash. If hash is not populated, this function still returns a valid iterator that always returns false
on a call to eina_iterator_next(), thus keeping the API sane.
NULL
is returned and EINA_ERROR_OUT_OF_MEMORY is set. Otherwise, a valid iterator is returned.[in] | hash | The hash |
Eina_Iterator* eina_hash_iterator_key_new | ( | const Eina_Hash * | hash | ) |
Returns a new iterator associated to hash keys.
This function returns a newly allocated iterator associated to hash. If hash is not populated, this function still returns a valid iterator that always returns false
on a call to eina_iterator_next(), thus keeping the API sane.
NULL
is returned and EINA_ERROR_OUT_OF_MEMORY is set. Otherwise, a valid iterator is returned.[in] | hash | The hash |
Eina_Iterator* eina_hash_iterator_tuple_new | ( | const Eina_Hash * | hash | ) |
Returns a new iterator associated to hash keys and data.
This function returns a newly allocated iterator associated to hash. If hash is not populated, this function still returns a valid iterator that always returns false
on a call to eina_iterator_next(), thus keeping the API sane.
NULL
is returned and EINA_ERROR_OUT_OF_MEMORY is set. Otherwise, a valid iterator is returned.[in] | hash | The hash |
void* eina_hash_modify | ( | Eina_Hash * | hash, |
const void * | key, | ||
const void * | data | ||
) |
Modifies the entry pointer at the specified key and returns the old entry.
This function modifies the data of key with data in hash. If no entry is found, nothing is added to hash. On success this function returns the old entry, otherwise it returns NULL
.
[in] | hash | The given hash table |
[in] | key | The key of the entry to modify |
[in] | data | The data used to replace the old entry |
NULL
void* eina_hash_modify_by_hash | ( | Eina_Hash * | hash, |
const void * | key, | ||
int | key_length, | ||
int | key_hash, | ||
const void * | data | ||
) |
Modifies the entry pointer at the specified key and returns the old entry.
[in] | hash | The given hash table |
[in] | key | The key of the entry to modify |
[in] | key_length | The length of key (don't forget to count '\0' for string) |
[in] | key_hash | The hash that always matches the key It is ignored if key is NULL . |
[in] | data | The data to replace the old entry, if it exists |
NULL
if not found Eina_Bool eina_hash_move | ( | Eina_Hash * | hash, |
const void * | old_key, | ||
const void * | new_key | ||
) |
Changes the key associated with the data without triggering the free callback.
This function allows for the move of data from one key to another, but does not call the Eina_Free_Cb associated with the hash table when destroying the old key.
[in] | hash | The given hash table |
[in] | old_key | The current key associated with the data |
[in] | new_key | The new key to associate the data with |
EINA_FALSE
in any case but success, otherwise EINA_TRUE
on success static int eina_hash_murmur3 | ( | const char * | key, |
int | len | ||
) | [static] |
The murmur3 hash function
[in] | key | The key to hash |
[in] | len | The length of the key |
Eina_Hash* eina_hash_new | ( | Eina_Key_Length | key_length_cb, |
Eina_Key_Cmp | key_cmp_cb, | ||
Eina_Key_Hash | key_hash_cb, | ||
Eina_Free_Cb | data_free_cb, | ||
int | buckets_power_size | ||
) |
Creates a new hash table.
This function creates a new hash table using user-defined callbacks to manage the hash table. On failure, NULL
is returned and EINA_ERROR_OUT_OF_MEMORY is set. If key_cmp_cb or key_hash_cb are NULL
, NULL
is returned. If buckets_power_size is smaller than or equal to 2, or if it is greater than or equal to 17, NULL
is returned.
[in] | key_length_cb | The function called when getting the size of the key |
[in] | key_cmp_cb | The function called when comparing the keys |
[in] | key_hash_cb | The function called when getting the values |
[in] | data_free_cb | The function called on each value when the hash table is freed, or when an item is deleted from it NULL can be passed as a callback. |
[in] | buckets_power_size | The size of the buckets |
Eina_Hash* eina_hash_pointer_new | ( | Eina_Free_Cb | data_free_cb | ) |
Creates a new hash table for use with pointers.
This function creates a new hash table using the int64/int32 algorithm for table management and dereferenced pointers to compare the keys. Values can then be looked up with pointers other than the original key pointer that is used to add values. This method may appear to be able to match string keys, actually it only matches the first character. On failure, this function returns NULL
.
// For a hash that will have only one pointer to each structure extern Eina_Hash *hash; extern void *data; if (!eina_hash_find(hash, &data)) eina_hash_add(hash, &data, data);
[in] | data_free_cb | The function called on each value when the hash table is freed, or when an item is deleted from it NULL can be passed as a callback. |
int eina_hash_population | ( | const Eina_Hash * | hash | ) |
Returns the number of entries in the given hash table.
This function returns the number of entries in hash, or 0
on error. If hash is NULL
, 0
is returned.
[in] | hash | The given hash table |
void* eina_hash_set | ( | Eina_Hash * | hash, |
const void * | key, | ||
const void * | data | ||
) |
Modifies the entry pointer at the specified key and returns the old entry or adds the entry if not found.
This function modifies the data of key with data in hash. If no entry is found, data is added to hash with the key key. On success, this function returns the old entry, otherwise it returns NULL
.
[in] | hash | The given hash table |
[in] | key | The key of the entry to modify |
[in] | data | The data used to replace the old entry |
NULL
Eina_Hash* eina_hash_string_djb2_new | ( | Eina_Free_Cb | data_free_cb | ) |
Creates a new hash table using the djb2 algorithm.
This function creates a new hash table using the djb2 algorithm for table management and strcmp() to compare the keys. Values can then be looked up with pointers other than the original key pointer that is used to add values. On failure, this function returns NULL
.
[in] | data_free_cb | The function called on each value when the hash table is freed, or when an item is deleted from it NULL can be passed as a callback. |
Eina_Hash* eina_hash_string_small_new | ( | Eina_Free_Cb | data_free_cb | ) |
Creates a new hash table for use with strings having a small bucket size.
This function creates a new hash table using the superfast algorithm for table management and strcmp() to compare the keys, but with a smaller bucket size (compared to eina_hash_string_superfast_new()), which minimizes the memory used by the returned hash table. Values can then be looked up with pointers other than the original key pointer that is used to add values. On failure, this function returns NULL
.
[in] | data_free_cb | The function called on each value when the hash table is freed, or when an item is deleted from it NULL can be passed as a callback. |
Eina_Hash* eina_hash_string_superfast_new | ( | Eina_Free_Cb | data_free_cb | ) |
Creates a new hash table for use with strings.
This function creates a new hash table using the superfast algorithm for table management and strcmp() to compare the keys. Values can then be looked up with pointers other than the original key pointer that is used to add values. On failure, this function returns NULL
.
[in] | data_free_cb | The function called on each value when the hash table is freed, or when an item is deleted from it NULL can be passed as a callback. |
Eina_Hash* eina_hash_stringshared_new | ( | Eina_Free_Cb | data_free_cb | ) |
Creates a new hash table optimized for stringshared values.
This function creates a new hash table optimized for stringshared values. Values CANNOT be looked up with pointers not equal to the original key pointer that is used to add a value. On failure, this function returns NULL
.
An Excerpt of a code that does NOT work with this type of hash:
extern Eina_Hash *hash; extern const char *value; const char *a = eina_stringshare_add("key"); eina_hash_add(hash, a, value); eina_hash_find(hash, "key")
[in] | data_free_cb | The function called on each value when the hash table is freed, or when an item is deleted from it NULL can be passed as a callback. |
int eina_hash_superfast | ( | const char * | key, |
int | len | ||
) |
Paul Hsieh (http://www.azillionmonkeys.com/qed/hash.html) hash function used by WebCore (http://webkit.org/blog/8/hashtables-part-2/)
[in] | key | The key to hash |
[in] | len | The length of the key |