Hash Table
[Containers]
give a small description here : what it is for, what it does , etc.
More...Data Structures | |
struct | _Eina_Hash_Tuple |
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) |
Typedefs | |
typedef struct _Eina_Hash | Eina_Hash |
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) |
Functions | |
EAPI 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) |
Create a new hash table. | |
EAPI Eina_Hash *EAPI Eina_Hash * | eina_hash_string_djb2_new (Eina_Free_Cb data_free_cb) |
Create a new hash table using the djb2 algorithm. | |
EAPI Eina_Hash * | eina_hash_string_superfast_new (Eina_Free_Cb data_free_cb) |
Create a new hash table for use with strings. | |
EAPI Eina_Hash * | eina_hash_string_small_new (Eina_Free_Cb data_free_cb) |
Create a new hash table for use with strings with small bucket size. | |
EAPI Eina_Hash * | eina_hash_int32_new (Eina_Free_Cb data_free_cb) |
Create a new hash table for use with 32bit integers. | |
EAPI Eina_Hash * | eina_hash_int64_new (Eina_Free_Cb data_free_cb) |
Create a new hash table for use with 64bit integers. | |
EAPI Eina_Hash * | eina_hash_pointer_new (Eina_Free_Cb data_free_cb) |
Create a new hash table for use with pointers. | |
EAPI Eina_Hash * | eina_hash_stringshared_new (Eina_Free_Cb data_free_cb) |
Create a new hash table optimized for stringshared values. | |
EAPI Eina_Bool | eina_hash_add (Eina_Hash *hash, const void *key, const void *data) |
Add an entry to the given hash table. | |
EAPI Eina_Bool EAPI Eina_Bool | eina_hash_direct_add (Eina_Hash *hash, const void *key, const void *data) |
Add an entry to the given hash table without duplicating the string key. | |
EAPI Eina_Bool EAPI Eina_Bool EAPI Eina_Bool | eina_hash_del (Eina_Hash *hash, const void *key, const void *data) |
Remove the entry identified by a key or a data from the given hash table. | |
EAPI void * | eina_hash_find (const Eina_Hash *hash, const void *key) |
Retrieve a specific entry in the given hash table. | |
EAPI void *EAPI void * | eina_hash_modify (Eina_Hash *hash, const void *key, const void *data) |
Modify the entry pointer at the specified key and return the old entry. | |
EAPI void *EAPI void EAPI void * | eina_hash_set (Eina_Hash *hash, const void *key, const void *data) |
Modify the entry pointer at the specified key and return the old entry or add the entry if not found. | |
EAPI void *EAPI void EAPI void EAPI Eina_Bool | eina_hash_move (Eina_Hash *hash, const void *old_key, const void *new_key) |
Change the key associated with a data without triggering the free callback. | |
EAPI void *EAPI void EAPI void EAPI Eina_Bool EAPI void | eina_hash_free (Eina_Hash *hash) |
Free the given hash table resources. | |
EAPI void | eina_hash_free_buckets (Eina_Hash *hash) |
Free the given hash table buckets resources. | |
EAPI int | eina_hash_population (const Eina_Hash *hash) |
Returns the number of entries in the given hash table. | |
EAPI Eina_Bool | eina_hash_add_by_hash (Eina_Hash *hash, const void *key, int key_length, int key_hash, const void *data) |
Add an entry to the given hash table. | |
EAPI Eina_Bool EAPI Eina_Bool | eina_hash_direct_add_by_hash (Eina_Hash *hash, const void *key, int key_length, int key_hash, const void *data) |
Add an entry to the given hash table and do not duplicate the string key. | |
EAPI Eina_Bool EAPI Eina_Bool EAPI Eina_Bool | eina_hash_del_by_key_hash (Eina_Hash *hash, const void *key, int key_length, int key_hash) |
Remove the entry identified by a key and a key hash from the given hash table. | |
EAPI Eina_Bool EAPI Eina_Bool EAPI Eina_Bool EAPI Eina_Bool | eina_hash_del_by_key (Eina_Hash *hash, const void *key) |
Remove the entry identified by a key from the given hash table. | |
EAPI Eina_Bool EAPI Eina_Bool EAPI Eina_Bool EAPI Eina_Bool EAPI Eina_Bool | eina_hash_del_by_data (Eina_Hash *hash, const void *data) |
Remove the entry identified by a data from the given hash table. | |
EAPI Eina_Bool EAPI Eina_Bool EAPI Eina_Bool EAPI Eina_Bool EAPI Eina_Bool EAPI Eina_Bool | eina_hash_del_by_hash (Eina_Hash *hash, const void *key, int key_length, int key_hash, const void *data) |
Remove the entry identified by a key and a key hash or a data from the given hash table. | |
EAPI void * | eina_hash_find_by_hash (const Eina_Hash *hash, const void *key, int key_length, int key_hash) |
Retrieve a specific entry in the given hash table. | |
EAPI void *EAPI void * | eina_hash_modify_by_hash (Eina_Hash *hash, const void *key, int key_length, int key_hash, const void *data) |
Modify the entry pointer at the specified key and returns the old entry. | |
EAPI void *EAPI void EAPI Eina_Iterator * | eina_hash_iterator_key_new (const Eina_Hash *hash) |
Returned a new iterator associated to hash keys. | |
EAPI Eina_Iterator * | eina_hash_iterator_data_new (const Eina_Hash *hash) |
Returned a new iterator associated to hash data. | |
EAPI Eina_Iterator * | eina_hash_iterator_tuple_new (const Eina_Hash *hash) |
Returned a new iterator associated to hash keys and data. | |
EAPI void | eina_hash_foreach (const Eina_Hash *hash, Eina_Hash_Foreach func, const void *fdata) |
Call a function on every member stored in the hash table. | |
EAPI void EAPI int | eina_hash_superfast (const char *key, int len) EINA_ARG_NONNULL(1) |
static int | eina_hash_djb2 (const char *key, int len) EINA_ARG_NONNULL(1) |
static int | eina_hash_djb2_len (const char *key, int *plen) EINA_ARG_NONNULL(1 |
static int static int | eina_hash_int32 (const unsigned int *pkey, int len) EINA_ARG_NONNULL(1) |
static int | eina_hash_int64 (const unsigned long int *pkey, int len) EINA_ARG_NONNULL(1) |
Detailed Description
give a small description here : what it is for, what it does , etc...
Hash API. Give some hints about the use (functions that must be used like init / shutdown), general use, etc... Give also a link to tutorial below.
Algorithm
Give here the algorithm used in the implementationPerformance
Give some hints about performance if it is possible, and an image !Tutorial
Here is a fantastic tutorial about our hash tableFunction Documentation
EAPI 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 | |||
) |
Create a new hash table.
- Parameters:
-
key_length_cb The function called when getting the size of the key. key_cmp_cb The function called when comparing the keys. key_hash_cb The function called when getting the values. data_free_cb The function called when the hash table is freed. buckets_power_size The size of the buckets.
- Returns:
- The new hash table.
NULL
is returned and EINA_ERROR_OUT_OF_MEMORY is set. If key_cmp_cb
or are NULL
, NULL
is returned. If buckets_power_size
is smaller or equal than 2, or if it is greater or equal than 17, NULL
is returned.Pre-defined functions are available to create a hash table. See eina_hash_string_djb2_new(), eina_hash_string_superfast_new(), eina_hash_string_small_new(), eina_hash_int32_new(), eina_hash_int64_new(), eina_hash_pointer_new() and eina_hash_stringshared_new().
EAPI Eina_Hash * eina_hash_string_djb2_new | ( | Eina_Free_Cb | data_free_cb | ) |
Create a new hash table using the djb2 algorithm.
- Parameters:
-
data_free_cb The function called when the hash table is freed.
- Returns:
- The new hash table.
NULL
. data_free_cb
is a callback called when the hash table is freed. NULL
can be passed as callback.
EAPI Eina_Hash * eina_hash_string_superfast_new | ( | Eina_Free_Cb | data_free_cb | ) |
Create a new hash table for use with strings.
- Parameters:
-
data_free_cb The function called when the hash table is freed.
- Returns:
- The new hash table.
NULL
. data_free_cb
is a callback called when the hash table is freed. NULL
can be passed as callback.
EAPI Eina_Hash * eina_hash_string_small_new | ( | Eina_Free_Cb | data_free_cb | ) |
Create a new hash table for use with strings with small bucket size.
- Parameters:
-
data_free_cb The function called when the hash table is freed.
- Returns:
- The new hash table.
NULL
. data_free_cb
is a callback called when the hash table is freed. NULL
can be passed as callback.
EAPI Eina_Hash * eina_hash_int32_new | ( | Eina_Free_Cb | data_free_cb | ) |
Create a new hash table for use with 32bit integers.
- Parameters:
-
data_free_cb The function called when the hash table is freed.
- Returns:
- The new hash table.
NULL
. data_free_cb
is a callback called when the hash table is freed. NULL
can be passed as callback.
EAPI Eina_Hash * eina_hash_int64_new | ( | Eina_Free_Cb | data_free_cb | ) |
Create a new hash table for use with 64bit integers.
- Parameters:
-
data_free_cb The function called when the hash table is freed.
- Returns:
- The new hash table.
NULL
. data_free_cb
is a callback called when the hash table is freed. NULL
can be passed as callback.
EAPI Eina_Hash * eina_hash_pointer_new | ( | Eina_Free_Cb | data_free_cb | ) |
Create a new hash table for use with pointers.
- Parameters:
-
data_free_cb The function called when the hash table is freed.
- Returns:
- The new hash table.
NULL
. data_free_cb
is a callback called when the hash table is freed. NULL
can be passed as callback.
EAPI Eina_Hash * eina_hash_stringshared_new | ( | Eina_Free_Cb | data_free_cb | ) |
Create a new hash table optimized for stringshared values.
- Parameters:
-
data_free_cb The function called when the hash table is freed.
- Returns:
- The new hash table.
NULL
. data_free_cb
is a callback called when the hash table is freed. NULL
can be passed as callback.Excerpt of code that will 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")
Add an entry to the given hash table.
- Parameters:
-
hash The given hash table. key A unique key. data Data to associate with the string given by key
.
- Returns:
- EINA_FALSE if an error occurred, EINA_TRUE otherwise.
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. Key uniqueness varies depending on the type of hash:
a stringshared Eina_Hash need only have unique pointers for keys, but the strings in the pointers may be identical. All other hash types require the strings themselves to be unique. Failure to use sufficient uniqueness will result in unexpected results when inserting data pointers accessed with eina_hash_find(), and removed with eina_hash_del(). Key strings are case sensitive. If an error occurs, eina_error_get() should be used to determine if an allocation error occurred during this function. This function returns EINA_FALSE if an error occurred, EINA_TRUE otherwise.
Add an entry to the given hash table without duplicating the string key.
- Parameters:
-
hash The given hash table. Can be NULL
.key A unique key. Can be NULL
.data Data to associate with the string given by key
.
- Returns:
- EINA_FALSE if an error occurred, EINA_TRUE otherwise.
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. Key uniqueness varies depending on the type of hash:
a stringshared Eina_Hash need only have unique pointers for keys, but the strings in the pointers may be identical. All other hash types require the strings themselves to be unique. Failure to use sufficient uniqueness will result in unexpected results when inserting data pointers accessed with eina_hash_find(), and removed with eina_hash_del(). This function does not make a copy of key
, so it must be a string constant or stored elsewhere ( in the object being added). Key strings are case sensitive. If an error occurs, eina_error_get() should be used to determine if an allocation error occurred during this function. This function returns EINA_FALSE if an error occurred, EINA_TRUE otherwise.
Remove the entry identified by a key or a data from the given hash table.
- Parameters:
-
hash The given hash table. key The key. data The data pointer to remove if the key is NULL
.
- Returns:
- EINA_FALSE if an error occurred, EINA_TRUE otherwise.
key
or data
from hash
. If a free function was given to the callback on creation, it will be called for the data being deleted. If hash
is NULL
, the functions returns immediately EINA_FALSE. If key
is NULL
, then data
is used to find the a match to remove, otherwise key
is used and data
is not required and can be NULL
. This function returns EINA_FALSE if an error occurred, EINA_TRUE otherwise.
- Note:
- if you know you already have the key, use eina_hash_del_by_key() or eina_hash_del_by_key_hash(). If you know you don't have the key, use eina_hash_del_by_data() directly.
EAPI void * eina_hash_find | ( | const Eina_Hash * | hash, | |
const void * | key | |||
) |
Retrieve a specific entry in the given hash table.
- Parameters:
-
hash The given hash table. key The key of the entry to find.
- Returns:
- The data pointer for the stored entry on success,
NULL
otherwise.
key
in hash
. If hash
is NULL
, this function returns immediately NULL
. This function returns the data pointer on success, NULL
otherwise.
EAPI void * eina_hash_modify | ( | Eina_Hash * | hash, | |
const void * | key, | |||
const void * | data | |||
) |
Modify the entry pointer at the specified key and return the old entry.
- Parameters:
-
hash The given hash table. key The key of the entry to modify. data The data to replace the old entry.
- Returns:
- The data pointer for the old stored entry on success, or
NULL
otherwise.
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
.
EAPI void * eina_hash_set | ( | Eina_Hash * | hash, | |
const void * | key, | |||
const void * | data | |||
) |
Modify the entry pointer at the specified key and return the old entry or add the entry if not found.
- Parameters:
-
hash The given hash table. key The key of the entry to modify. data The data to replace the old entry
- Returns:
- The data pointer for the old stored entry, or
NULL
otherwise.
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
. To check for errors, use eina_error_get().
Change the key associated with a data without triggering the free callback.
- Parameters:
-
hash The given hash table. old_key The current key associated with the data new_key The new key to associate data with
- Returns:
- EINA_FALSE in any case but success, EINA_TRUE on success.
EAPI void eina_hash_free | ( | Eina_Hash * | hash | ) |
Free the given hash table resources.
- Parameters:
-
hash The hash table to be freed.
hash
, and call 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 the 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;
EAPI void eina_hash_free_buckets | ( | Eina_Hash * | hash | ) |
Free the given hash table buckets resources.
- Parameters:
-
hash The hash table whose buckets have to be freed.
hash
, and call the free callback on all hash table buckets if it has been passed to the hash table at creation time, then frees the buckets. If no free callback has been passed, no buckets value will be freed. If hash
is NULL
, the function returns immediately.
EAPI int eina_hash_population | ( | const Eina_Hash * | hash | ) |
Returns the number of entries in the given hash table.
- Parameters:
-
hash The given hash table.
- Returns:
- The number of entries in the hash table.
hash
, or 0 on error. If hash
is NULL
, 0 is returned.
EAPI Eina_Bool eina_hash_add_by_hash | ( | Eina_Hash * | hash, | |
const void * | key, | |||
int | key_length, | |||
int | key_hash, | |||
const void * | data | |||
) |
Add an entry to the given hash table.
- Parameters:
-
hash The given hash table. key A unique key. key_length The length of the key. key_hash The hash that will always match key. data The data to associate with the string given by the key.
- Returns:
- EINA_FALSE if an error occurred, EINA_TRUE otherwise.
key
to hash
. hash
, key
and data
can be NULL
, in that case EINA_FALSE is returned. key
is expected to be a unique string within the hash table. Otherwise, one cannot be sure which inserted data pointer will be accessed with eina_hash_find, and removed with 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. Key strings are case sensitive. If an error occurs, eina_error_get() should be used to determine if an allocation error occurred during this function. This function returns EINA_FALSE if an error occurred, EINA_TRUE otherwise.
EAPI Eina_Bool eina_hash_direct_add_by_hash | ( | Eina_Hash * | hash, | |
const void * | key, | |||
int | key_length, | |||
int | key_hash, | |||
const void * | data | |||
) |
Add an entry to the given hash table and do not duplicate the string key.
- Parameters:
-
hash The given hash table. Can be NULL
.key A unique key. Can be NULL
.key_length Should be the length of key
(don't forget to count '\0' for string).key_hash The hash that will always match key. data Data to associate with the string given by key
.
- Returns:
- EINA_FALSE if an error occurred, EINA_TRUE otherwise.
key
to hash
. hash
, key
and data
can be NULL
, in that case EINA_FALSE is returned. key
is expected to be a unique string within the hash table. Otherwise, one cannot be sure which inserted data pointer will be accessed with eina_hash_find, and removed with eina_hash_del. This function does not make a copy of key
so it must be a string constant or 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. Key strings are case sensitive. If an error occurs, eina_error_get() should be used to determine if an allocation error occurred during this function. This function returns EINA_FALSE if an error occurred, EINA_TRUE otherwise.
EAPI Eina_Bool eina_hash_del_by_key_hash | ( | Eina_Hash * | hash, | |
const void * | key, | |||
int | key_length, | |||
int | key_hash | |||
) |
Remove the entry identified by a key and a key hash from the given hash table.
- Parameters:
-
hash The given hash table. key The key. key_length The length of the key. key_hash The hash that always match the key.
- Returns:
- EINA_FALSE if an error occurred, EINA_TRUE otherwise.
key
and key_hash
from hash
. If a free function was given to the callback on creation, it will be 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
are NULL
, the functions returns immediately EINA_FALSE. This function returns EINA_FALSE if an error occurred, EINA_TRUE otherwise.
- Note:
- if you don't have the key_hash, use eina_hash_del_by_key() instead.
if you don't have the key, use eina_hash_del_by_data() instead.
Remove the entry identified by a key from the given hash table.
This version will calculate key length and hash by using functions provided to hash creation function.
- Parameters:
-
hash The given hash table. key The key.
- Returns:
- EINA_FALSE if an error occurred, EINA_TRUE otherwise.
key
from hash
. The key length and hash will be calculated automatically by using functiond provided to has creation function. If a free function was given to the callback on creation, it will be called for the data being deleted. If hash
or key
are NULL
, the functions returns immediately EINA_FALSE. This function returns EINA_FALSE if an error occurred, EINA_TRUE otherwise.
- Note:
- if you already have the key_hash, use eina_hash_del_by_key_hash() instead.
if you don't have the key, use eina_hash_del_by_data() instead.
Remove the entry identified by a data from the given hash table.
This version is slow since there is no quick access to nodes based on data.
- Parameters:
-
hash The given hash table. data The data value to search and remove.
- Returns:
- EINA_FALSE if an error occurred, EINA_TRUE otherwise. thing goes fine.
data
from hash
. If a free function was given to the callback on creation, it will be called for the data being deleted. If hash
or data
are NULL
, the functions returns immediately EINA_FALSE. This function returns EINA_FALSE if an error occurred, EINA_TRUE otherwise.
- Note:
- if you already have the key, use eina_hash_del_by_key() or eina_hash_del_by_key_hash() instead.
EAPI Eina_Bool eina_hash_del_by_hash | ( | Eina_Hash * | hash, | |
const void * | key, | |||
int | key_length, | |||
int | key_hash, | |||
const void * | data | |||
) |
Remove the entry identified by a key and a key hash or a data from the given hash table.
If key
is NULL
, then data
is used to find a match to remove.
- Parameters:
-
hash The given hash table. key The key. key_length The length of the key. key_hash The hash that always match the key. data The data pointer to remove if the key is NULL
.
- Returns:
- EINA_FALSE if an error occurred, EINA_TRUE otherwise.
key
and key_hash
, or data
, from hash
. If a free function was given to the callback on creation, it will be called for the data being deleted. If hash
is NULL
, the functions returns immediately EINA_FALSE. If key
is NULL
, then key_hash
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 occurred, EINA_TRUE otherwise.
- Note:
- if you know you already have the key, use eina_hash_del_by_key_hash(), if you know you don't have the key, use eina_hash_del_by_data() directly.
EAPI void * eina_hash_find_by_hash | ( | const Eina_Hash * | hash, | |
const void * | key, | |||
int | key_length, | |||
int | key_hash | |||
) |
Retrieve a specific entry in the given hash table.
- Parameters:
-
hash The given hash table. key The key of the entry to find. key_length The length of the key. key_hash The hash that always match the key
- Returns:
- The data pointer for the stored entry on success,
NULL
otherwise.
key
of length key_length
in hash
. key_hash
is the hash that always match 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 immediately NULL
. This function returns the data pointer on success, NULL
otherwise.
EAPI void * eina_hash_modify_by_hash | ( | Eina_Hash * | hash, | |
const void * | key, | |||
int | key_length, | |||
int | key_hash, | |||
const void * | data | |||
) |
Modify the entry pointer at the specified key and returns the old entry.
- Parameters:
-
hash The given hash table. key The key of the entry to modify. key_length Should be the length of key
(don't forget to count '\0' for string).key_hash The hash that always match the key. Ignored if key
isNULL
.data The data to replace the old entry, if it exists.
- Returns:
- The data pointer for the old stored entry, or
NULL
if not found. If an existing entry is not found, nothing is added to the hash.
EAPI Eina_Iterator * eina_hash_iterator_key_new | ( | const Eina_Hash * | hash | ) |
Returned a new iterator associated to hash keys.
- Parameters:
-
hash The hash.
- Returns:
- A new iterator.
hash
. If hash
is not populated, this function still returns a valid iterator that will always return false on eina_iterator_next(), thus keeping API sane.If the memory can not be allocated, NULL is returned and EINA_ERROR_OUT_OF_MEMORY is set. Otherwise, a valid iterator is returned.
- Warning:
- if the hash structure changes then the iterator becomes invalid! That is, if you add or remove items this iterator behavior is undefined and your program may crash!
EAPI Eina_Iterator * eina_hash_iterator_data_new | ( | const Eina_Hash * | hash | ) |
Returned a new iterator associated to hash data.
- Parameters:
-
hash The hash.
- Returns:
- A new iterator.
hash
. If hash
is not populated, this function still returns a valid iterator that will always return false on eina_iterator_next(), thus keeping API sane.
If the memory can not be allocated, NULL
is returned and EINA_ERROR_OUT_OF_MEMORY is set. Otherwise, a valid iterator is returned.
- Warning:
- if the hash structure changes then the iterator becomes invalid. That is, if you add or remove items this iterator behavior is undefined and your program may crash.
EAPI Eina_Iterator * eina_hash_iterator_tuple_new | ( | const Eina_Hash * | hash | ) |
Returned a new iterator associated to hash keys and data.
- Parameters:
-
hash The hash.
- Returns:
- A new iterator.
hash
. If hash
is not populated, this function still returns a valid iterator that will always return false on eina_iterator_next(), thus keeping API sane.If the memory can not be allocated, NULL is returned and EINA_ERROR_OUT_OF_MEMORY is set. Otherwise, a valid iterator is returned.
- Note:
- iterator data will provide values as Eina_Hash_Tuple that should not be modified!
- Warning:
- if the hash structure changes then the iterator becomes invalid! That is, if you add or remove items this iterator behavior is undefined and your program may crash!
EAPI void eina_hash_foreach | ( | const Eina_Hash * | hash, | |
Eina_Hash_Foreach | func, | |||
const void * | fdata | |||
) |
Call a function on every member stored in the hash table.
- Parameters:
-
hash The hash table whose members will be walked func The function to call on each parameter fdata The data pointer to pass to the function being called
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 must return 0, otherwise 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); }