Hash table management. More...
Data Structures | |
struct | _Eina_Hash_Tuple |
Data for a hash table of key/value pairs. More... | |
Macros | |
#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 |
Type for a hash table of key/value pairs. | |
typedef unsigned int(* | Eina_Key_Length) (const void *key) |
Type for a function to determine the length of a hash key. | |
typedef int(* | Eina_Key_Cmp) (const void *key1, int key1_length, const void *key2, int key2_length) |
Type for a function to compare two hash keys. | |
typedef int(* | Eina_Key_Hash) (const void *key, int key_length) |
Type for a function to create a hash key. | |
typedef Eina_Bool(* | Eina_Hash_Foreach) (const Eina_Hash *hash, const void *key, void *data, void *fdata) |
Type for a function to iterate over a hash table. | |
Functions | |
EINA_API 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. More... | |
EINA_API void | eina_hash_free_cb_set (Eina_Hash *hash, Eina_Free_Cb data_free_cb) |
Sets the data cleanup callback for a hash. More... | |
EINA_API Eina_Hash * | eina_hash_string_djb2_new (Eina_Free_Cb data_free_cb) |
Creates a new hash table using the djb2 algorithm. More... | |
EINA_API Eina_Hash * | eina_hash_string_superfast_new (Eina_Free_Cb data_free_cb) |
Creates a new hash table for use with strings. More... | |
EINA_API Eina_Hash * | eina_hash_string_small_new (Eina_Free_Cb data_free_cb) |
Creates a new hash table for use with strings with small bucket size. More... | |
EINA_API Eina_Hash * | eina_hash_int32_new (Eina_Free_Cb data_free_cb) |
Creates a new hash table for use with 32bit integers. More... | |
EINA_API Eina_Hash * | eina_hash_int64_new (Eina_Free_Cb data_free_cb) |
Creates a new hash table for use with 64bit integers. More... | |
EINA_API Eina_Hash * | eina_hash_pointer_new (Eina_Free_Cb data_free_cb) |
Creates a new hash table for use with pointers. More... | |
EINA_API Eina_Hash * | eina_hash_stringshared_new (Eina_Free_Cb data_free_cb) |
Creates a new hash table optimized for stringshared values. More... | |
EINA_API Eina_Bool | eina_hash_add (Eina_Hash *hash, const void *key, const void *data) |
Adds an entry to the given hash table. More... | |
EINA_API 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. More... | |
EINA_API Eina_Bool | eina_hash_del (Eina_Hash *hash, const void *key, const void *data) |
Removes the entry identified by a key or a data from the given hash table. More... | |
EINA_API void * | eina_hash_find (const Eina_Hash *hash, const void *key) |
Retrieves a specific entry in the given hash table. More... | |
EINA_API void * | eina_hash_modify (Eina_Hash *hash, const void *key, const void *data) |
Modifies the entry pointer at the specified key and returns the previous entry. More... | |
EINA_API void * | eina_hash_set (Eina_Hash *hash, const void *key, const void *data) |
Modifies the entry pointer at the specified key and returns the previous entry or adds the entry if not found. More... | |
EINA_API Eina_Bool | eina_hash_move (Eina_Hash *hash, const void *old_key, const void *new_key) |
Changes the key of an entry in a hash without triggering the free callback. More... | |
EINA_API void | eina_hash_free (Eina_Hash *hash) |
Frees the given hash table's resources. More... | |
EINA_API void | eina_hash_free_buckets (Eina_Hash *hash) |
Frees the given hash table buckets resources. More... | |
EINA_API int | eina_hash_population (const Eina_Hash *hash) |
Returns the number of entries in the given hash table. More... | |
EINA_API 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 by its key hash. More... | |
EINA_API 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 a hash table by its key hash without duplicating the string key. More... | |
EINA_API 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. More... | |
EINA_API 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. More... | |
EINA_API Eina_Bool | eina_hash_del_by_data (Eina_Hash *hash, const void *data) |
Removes an entry from a hash table identified by its data value. More... | |
EINA_API 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 a data value from the given hash table. More... | |
EINA_API void * | eina_hash_find_by_hash (const Eina_Hash *hash, const void *key, int key_length, int key_hash) |
Retrieves a specific entry from the given hash table. More... | |
EINA_API 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 previous entry. More... | |
EINA_API Eina_Iterator * | eina_hash_iterator_key_new (const Eina_Hash *hash) |
Returns a new iterator associated with hash keys. More... | |
EINA_API Eina_Iterator * | eina_hash_iterator_data_new (const Eina_Hash *hash) |
Returns a new iterator associated with a hash. More... | |
EINA_API Eina_Iterator * | eina_hash_iterator_tuple_new (const Eina_Hash *hash) |
Returned a new iterator associated with hash keys and data. More... | |
EINA_API 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. More... | |
EINA_API void | eina_hash_list_append (Eina_Hash *hash, const void *key, const void *data) |
Appends data to an Eina_List inside a hash. More... | |
EINA_API void | eina_hash_list_direct_append (Eina_Hash *hash, const void *key, const void *data) |
Appends data to an Eina_List inside a hash using eina_hash_direct_add(). More... | |
EINA_API void | eina_hash_list_prepend (Eina_Hash *hash, const void *key, const void *data) |
Prepends data to an Eina_List inside a hash. More... | |
EINA_API void | eina_hash_list_direct_prepend (Eina_Hash *hash, const void *key, const void *data) |
Prepends data to an Eina_List inside a hash using eina_hash_direct_add(). More... | |
EINA_API void | eina_hash_list_remove (Eina_Hash *hash, const void *key, const void *data) |
Removes data from an Eina_List inside a hash. More... | |
EINA_API 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/) More... | |
static int | eina_hash_djb2 (const char *key, int len) |
Hash function first reported by Dan Bernstein many years ago in comp.lang.c. More... | |
static int | eina_hash_djb2_len (const char *key, int *plen) |
Hash function first reported by Dan Bernstein many years ago in comp.lang.c. More... | |
static int | eina_hash_int32 (const unsigned int *pkey, int len) |
Hash function from http://web.archive.org/web/20071223173210/http://www.concentric.net/~Ttwang/tech/inthash.htm. More... | |
static int | eina_hash_int64 (const unsigned long long int *pkey, int len) |
Hash function from http://web.archive.org/web/20071223173210/http://www.concentric.net/~Ttwang/tech/inthash.htm. More... | |
static int | eina_hash_murmur3 (const char *key, int len) |
Hash function from http://sites.google.com/site/murmurhash/. More... | |
static int | eina_hash_crc (const char *key, int len) |
Hash function using crc-32 algorithm and and 0xEDB88320 polynomial. More... | |
Hash table management.
Maps keys to values.
The hash table associates keys (e.g. strings) to data, with 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.
There are optimized implementations for some common key types, such as strings, integers, pointers, and stringshared; custom optimizations are also permitted.
The hash table keys can be either copied or non-copied, using eina_hash_add() or eina_hash_direct_add(), respectively.
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 illustrates the basic idea:
Adding an element to the hash table involves the following steps:
The first two steps have constant time, proportional to the hash function being used. Adding the key to the rbtree will be proportional to the number of keys in that bucket.
The average lookup cost depends on the number of keys per bucket (load factor) of the table, assuming the distribution of keys is sufficiently uniform.
Keeping the load factor small will improve the hash table performance. But increasing the buckets_power_size will also increase the memory consumption. The default hash table creation functions provides enough buckets for most cases. If just a few string keys (less than 30) will be added to the hash table, eina_hash_string_small_new should be used, since it reduces the memory consumption for the buckets without causing too many collisions. However, eina_hash_string_small_new still uses the same hash calculation function that eina_hash_string_superfast_new, which is more complex than eina_hash_string_djb2_new. The latter has a faster hash computation function, but that will imply a not so good distribution. But if just a few keys are being added, this is not a problem, it will still have not many collisions and be faster to calculate the hash than in a hash 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) - not randomized, avoid it on public remote interface.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 be preferred if not used on a public remote interface.
If just stringshared keys are being added, use eina_hash_stringshared_new. If a lot of keys will be 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 if this key is already stored elsewhere). If the key may be already inside the hash table, rather than checking with eina_hash_find followed by eina_hash_add, one can use just eina_hash_set (this will change the data pointed by this key if it was already present in the table).
These examples show many Eina_Hash functions in action:
#define EINA_KEY_LENGTH | ( | Function | ) | ((Eina_Key_Length)Function) |
[in] | Function | The function used to calculate length of hash key. |
#define EINA_KEY_CMP | ( | Function | ) | ((Eina_Key_Cmp)Function) |
[in] | Function | The function used to compare hash key. |
#define EINA_KEY_HASH | ( | Function | ) | ((Eina_Key_Hash)Function) |
[in] | Function | The function used to hash key. |
EINA_API 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.
[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. |
NULL
on failure.This function creates a new hash table using user-defined callbacks to manage the hash table. If key_cmp_cb
or key_hash_cb
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.
The number of buckets created will be 2 ^ buckets_power_size
. This means that if buckets_power_size
is 5, there will be created 32 buckets, whereas for a buckets_power_size
of 8, there will be 256 buckets.
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().
References EINA_MAGIC_SET, EINA_SAFETY_ON_NULL_RETURN_VAL, and EINA_SAFETY_ON_TRUE_RETURN_VAL.
Referenced by eina_cow_add(), eina_file_open(), eina_file_virtualize(), eina_hash_int32_new(), eina_hash_int64_new(), eina_hash_pointer_new(), eina_hash_string_djb2_new(), eina_hash_string_small_new(), eina_hash_string_superfast_new(), and eina_hash_stringshared_new().
EINA_API void eina_hash_free_cb_set | ( | Eina_Hash * | hash, |
Eina_Free_Cb | data_free_cb | ||
) |
Sets the data cleanup callback for a hash.
[in,out] | 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. |
The argument received by data_free_cb
will be the data of the item being removed.
References EINA_SAFETY_ON_NULL_RETURN.
EINA_API Eina_Hash * eina_hash_string_djb2_new | ( | Eina_Free_Cb | data_free_cb | ) |
Creates a new hash table using the djb2 algorithm.
[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. |
NULL
on failure.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 was used to add values.
References eina_hash_djb2(), eina_hash_new(), EINA_KEY_CMP, EINA_KEY_HASH, and EINA_KEY_LENGTH.
EINA_API Eina_Hash * eina_hash_string_superfast_new | ( | Eina_Free_Cb | data_free_cb | ) |
Creates a new hash table for use with strings.
[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. |
NULL
on failure.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 was used to add values.
References eina_hash_new(), eina_hash_superfast(), EINA_KEY_CMP, EINA_KEY_HASH, and EINA_KEY_LENGTH.
Referenced by ecore_buffer_init(), ecore_evas_data_set(), ecore_imf_context_prediction_hint_hash_set(), ecore_imf_module_register(), ecore_wl2_display_connect(), ecore_wl2_display_create(), edje_color_class_set(), efreet_desktop_x_field_set(), efreet_menu_parse(), eldbus_proxy_event_callback_add(), elm_color_class_editor_add(), elm_theme_color_class_list(), and elm_theme_flush().
EINA_API Eina_Hash * eina_hash_string_small_new | ( | Eina_Free_Cb | data_free_cb | ) |
Creates a new hash table for use with strings with small bucket size.
[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. |
NULL
on failure.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 will minimize the memory used by the returned hash table. Values can then be looked up with pointers other than the original key pointer that was used to add values.
References eina_hash_new(), eina_hash_superfast(), EINA_KEY_CMP, EINA_KEY_HASH, and EINA_KEY_LENGTH.
Referenced by ecore_thread_global_data_add(), ecore_thread_global_data_set(), ecore_thread_local_data_add(), ecore_thread_local_data_set(), edje_edit_data_add(), edje_edit_group_data_add(), edje_file_text_class_set(), eio_file_associate_add(), eio_file_associate_direct_add(), eldbus_address_connection_get(), and eldbus_object_get().
EINA_API Eina_Hash * eina_hash_int32_new | ( | Eina_Free_Cb | data_free_cb | ) |
Creates a new hash table for use with 32bit integers.
[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. |
NULL
on failure.This function creates a new hash table where keys are 32bit integers. When adding or looking up in the hash table, pointers to 32bit integers must be passed. They can be addresses on the stack if you let the eina_hash copy the key. Values can then be looked up with pointers other than the original key pointer that was used to add values. This method is not suitable to match string keys as it would only match the first character.
References eina_hash_int32(), eina_hash_new(), EINA_KEY_CMP, EINA_KEY_HASH, and EINA_KEY_LENGTH.
Referenced by ecore_drm_evdev_key_remap_set(), and ecore_wl2_display_connect().
EINA_API Eina_Hash * eina_hash_int64_new | ( | Eina_Free_Cb | data_free_cb | ) |
Creates a new hash table for use with 64bit integers.
[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. |
NULL
on failure.This function creates a new hash table where keys are 64bit integers. When adding or looking up in the hash table, pointers to 64bit 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 was used to add values. This method is not suitable to match string keys as it would only match the first character.
References eina_hash_int64(), eina_hash_new(), EINA_KEY_CMP, EINA_KEY_HASH, and EINA_KEY_LENGTH.
EINA_API Eina_Hash * eina_hash_pointer_new | ( | Eina_Free_Cb | data_free_cb | ) |
Creates a new hash table for use with pointers.
[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. |
NULL
on failure.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 was used to add values. This method may appear to be able to match string keys, but actually it only matches the first character.
References eina_hash_int32(), eina_hash_int64(), eina_hash_new(), EINA_KEY_CMP, EINA_KEY_HASH, and EINA_KEY_LENGTH.
Referenced by eina_cow_add(), eina_file_open(), eina_file_virtualize(), elm_drop_target_add(), eolian_aux_class_callables_get(), eolian_aux_state_class_children_find(), and evas_object_image_data_get().
EINA_API Eina_Hash * eina_hash_stringshared_new | ( | Eina_Free_Cb | data_free_cb | ) |
Creates a new hash table optimized for stringshared 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 callback. |
NULL
on failure.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 was used to add a value.
Excerpt of code that will NOT work with this type of hash:
References eina_hash_new(), EINA_KEY_CMP, and EINA_KEY_HASH.
Referenced by efreet_mime_type_cache_clear().
Adds an entry to the given hash table.
[in,out] | hash | The given hash table. Cannot be NULL . |
[in] | key | A unique key. Cannot be NULL . |
[in] | data | The data to associate with the string given by key . Cannot be NULL . |
This function adds key
to hash
. key
must be unique within the hash table so that eina_hash_find() and eina_hash_del() operate on the correct data item.
Key uniqueness varies depending on the type of hash:
a stringshared Eina_Hash needs unique pointers (which implies unique strings). All other string hash types require that the strings themselves are unique. Pointer, int32 and int64 hashes need to have unique values. 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.
References EINA_FALSE, and EINA_SAFETY_ON_NULL_RETURN_VAL.
Referenced by ecore_buffer_register(), ecore_drm_evdev_key_remap_set(), ecore_evas_data_set(), ecore_imf_module_register(), ecore_thread_global_data_add(), ecore_thread_local_data_add(), ecore_wl2_display_connect(), ecore_wl2_display_create(), edje_edit_data_add(), edje_edit_group_data_add(), edje_edit_program_del(), edje_external_type_register(), eeze_net_new(), efreet_desktop_x_field_set(), eina_error_msg_get(), eina_file_map_new(), eina_file_virtual_map_new(), eina_hash_move(), eina_mempool_register(), eio_file_associate_add(), eldbus_service_object_manager_attach(), elm_color_class_editor_add(), elm_prefs_item_iface_register(), elm_theme_color_class_list(), and evas_object_image_data_get().
Adds an entry to the given hash table without duplicating the string.
[in,out] | hash | The given hash table. Cannot be NULL . |
[in] | key | A unique key. Cannot be NULL . |
[in] | data | The data to associate with the string given by key . Cannot be NULL |
This function adds key
to hash
. key
must be unique within the hash table so that eina_hash_find() and eina_hash_del() operate on the correct data item.
Key uniqueness varies depending on the type of hash:
a stringshared Eina_Hash needs unique pointers (which implies unique strings). All other string hash types require that the strings themselves are unique. Pointer, int32 and int64 hashes need to have unique values. 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().
Unlike eina_hash_add(), this function does not make a copy of key
, so it must be a string constant or stored elsewhere (such as in the object being added). Key strings are case sensitive.
References EINA_FALSE, and EINA_SAFETY_ON_NULL_RETURN_VAL.
Referenced by ecore_thread_global_data_add(), ecore_thread_local_data_add(), edje_edit_group_add(), edje_edit_group_alias_add(), edje_edit_group_copy(), edje_external_type_array_register(), edje_file_text_class_set(), eina_file_map_new(), eina_file_open(), eina_file_virtual_map_new(), eio_file_associate_direct_add(), eio_monitor_stringshared_add(), elm_prefs_item_iface_register(), elm_prefs_page_iface_register(), and ethumb_client_thumb_exists().
Removes the entry identified by a key or a data from the given hash table.
[in,out] | hash | The given hash table. |
[in] | key | The key. |
[in] | data | The data pointer to remove if the key is NULL . |
This function removes the entry identified by 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 function 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
.
References EINA_FALSE, eina_hash_del_by_data(), and EINA_SAFETY_ON_NULL_RETURN_VAL.
Referenced by ecore_buffer_unregister(), ecore_evas_data_set(), ecore_imf_context_prediction_hint_hash_del(), ecore_wl_window_free(), edje_edit_data_del(), edje_edit_group_data_del(), edje_edit_group_del(), edje_external_type_array_unregister(), edje_file_text_class_del(), eina_file_common_map_free(), eina_file_flush(), eina_file_open(), eina_file_virtual_map_free(), eina_hash_move(), eina_mempool_unregister(), eio_monitor_stringshared_add(), eldbus_service_interface_unregister(), eldbus_service_object_manager_detach(), elm_prefs_item_iface_unregister(), elm_prefs_page_iface_unregister(), and evas_object_image_data_set().
Retrieves a specific entry in the given hash table.
[in] | hash | The given hash table. |
[in] | key | The key of the entry to find. |
NULL
otherwise.This function retrieves the entry associated with key
in hash
. If hash
is NULL
, this function returns NULL
.
References eina_hash_find_by_hash(), and EINA_SAFETY_ON_NULL_RETURN_VAL.
Referenced by ecore_buffer_unregister(), ecore_evas_data_get(), ecore_evas_drop_available_types_get(), ecore_thread_global_data_find(), ecore_thread_global_data_wait(), ecore_thread_local_data_find(), ecore_wl2_connected_display_get(), ecore_wl2_display_connect(), ecore_wl2_display_create(), ecore_wl_window_find(), edje_edit_data_add(), edje_edit_data_del(), edje_edit_data_source_generate(), edje_edit_data_value_get(), edje_edit_data_value_set(), edje_edit_font_del(), edje_edit_group_add(), edje_edit_group_alias_add(), edje_edit_group_alias_is(), edje_edit_group_aliased_get(), edje_edit_group_aliases_get(), edje_edit_group_copy(), edje_edit_group_data_add(), edje_edit_group_data_del(), edje_edit_group_data_value_get(), edje_edit_group_data_value_set(), edje_edit_group_del(), edje_edit_group_exist(), edje_edit_group_name_set(), edje_edit_object_color_class_list_get(), edje_edit_part_del(), edje_edit_part_item_append(), edje_edit_part_item_index_source_set(), edje_edit_part_item_insert_after(), edje_edit_part_item_insert_after_index(), edje_edit_part_item_insert_at(), edje_edit_part_item_insert_before(), edje_edit_part_item_insert_before_index(), edje_edit_part_item_source_set(), edje_edit_program_action_set(), edje_edit_program_del(), edje_edit_script_program_get(), edje_edit_script_program_set(), edje_edit_state_del(), edje_external_param_info_get(), edje_external_type_get(), edje_external_type_register(), edje_file_text_class_del(), edje_file_text_class_get(), edje_file_text_class_set(), edje_mmap_data_get(), edje_mmap_group_exists(), eeze_net_new(), efreet_desktop_x_field_get(), efreet_util_desktop_exec_find(), efreet_util_desktop_exec_glob_list(), efreet_util_desktop_file_id_find(), efreet_util_path_to_file_id(), eina_error_msg_get(), eina_file_common_map_free(), eina_file_map_faulted(), eina_file_map_new(), eina_file_map_populate(), eina_file_open(), eina_file_unlink(), eina_file_virtual_map_free(), eina_file_virtual_map_new(), eina_hash_move(), eio_file_associate_find(), eio_monitor_stringshared_add(), eldbus_name_owner_changed_callback_del(), eldbus_proxy_property_local_get(), eldbus_service_object_manager_attach(), eldbus_service_property_changed(), elm_drop_target_del(), elm_theme_color_class_list(), ethumb_client_thumb_exists(), evas_object_image_data_set(), evas_object_smart_type_check(), and evas_object_smart_type_check_ptr().
Modifies the entry pointer at the specified key and returns the previous entry.
[in,out] | hash | The given hash table. |
[in] | key | The key of the entry to modify. |
[in] | data | The new data. |
NULL
otherwise.This function modifies the data of key
with data
in hash
. If no entry is found, nothing is added to hash
.
References eina_hash_modify_by_hash(), and EINA_SAFETY_ON_NULL_RETURN_VAL.
Modifies the entry pointer at the specified key and returns the previous entry or adds the entry if not found.
[in,out] | hash | The given hash table. |
[in] | key | The key of the entry to modify. |
[in] | data | The data to replace the previous entry. |
NULL
otherwise.This function modifies the value of key
to data
in hash
. If no entry is found, data
is added to hash
with the key key
.
References _Eina_Hash_Tuple::data, EINA_SAFETY_ON_NULL_RETURN_VAL, _Eina_Hash_Tuple::key, and _Eina_Hash_Tuple::key_length.
Referenced by ecore_imf_context_prediction_hint_hash_set(), ecore_thread_global_data_set(), ecore_thread_local_data_set(), edje_edit_program_action_set(), efreet_util_path_to_file_id(), and evas_smart_legacy_type_register().
Changes the key of an entry in a hash without triggering the free callback.
[in,out] | hash | The given hash table. |
[in] | old_key | The current key associated with the data. |
[in] | new_key | The new key to associate data with. |
This function moves data from one key to another, but does not call the Eina_Free_Cb associated with the hash table when destroying the old key.
References EINA_FALSE, eina_hash_add(), eina_hash_del(), eina_hash_find(), and EINA_SAFETY_ON_NULL_RETURN_VAL.
Referenced by edje_edit_data_name_set(), edje_edit_group_data_name_set(), and edje_edit_group_name_set().
Frees the given hash table's resources.
[in] | hash | The hash table to be freed. |
This function frees memory allocated for the hash
and to its internal buckets.
If data_free_cb
was specified at creation time in eina_hash_new, it will be called for each element as it gets freed. If the callback was not specified, then any data in these elements may now be lost, if not stored or freed elsewhere.
If hash
is NULL
, the function returns immediately.
Example:
References eina_rbtree_delete(), and EINA_RBTREE_FREE_CB.
Referenced by ecore_buffer_free(), ecore_buffer_init(), ecore_buffer_shutdown(), ecore_drm_evdev_key_remap_enable(), ecore_imf_context_del(), ecore_wl2_display_connect(), efreet_mime_type_cache_clear(), eina_cow_del(), eina_file_clean_close(), eldbus_proxy_event_callback_del(), elm_theme_color_class_list(), elm_theme_flush(), and ethumb_client_shutdown().
Frees the given hash table buckets resources.
[in] | hash | The hash table whose buckets have to be freed. |
This function frees memory allocated to internal buckets for hash
.
If data_free_cb
was specified at creation time in eina_hash_new(), it will be called for each element as it gets freed. If the callback was not specified, then any data in these elements may now be lost, if not stored or freed elsewhere.
If hash
is NULL
, the function returns immediately.
References eina_rbtree_delete(), and EINA_RBTREE_FREE_CB.
Returns the number of entries in the given hash table.
[in] | hash | The given hash table. |
0
on error or if hash
is NULL
. Referenced by eina_cow_gc().
EINA_API 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 by its key hash.
[in,out] | hash | The given hash table. Cannot be NULL . |
[in] | key | A unique key. Cannot be NULL . |
[in] | key_length | The length of key (including terminating '\0'). |
[in] | key_hash | The hash of key . |
[in] | data | The data to associate with the string given by the key. Cannot be NULL . |
This function adds key
to hash
.
key
must be unique within the hash table so that eina_hash_find() and eina_hash_del() operate on the correct data item. key_hash
must match key
so that the correct item can be found by eina_hash_find_by_hash(). Key strings are case sensitive.
EINA_API 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 a hash table by its key hash without duplicating the string key.
[in,out] | hash | The given hash table. Cannot be NULL . |
[in] | key | A unique key. Cannot be NULL . |
[in] | key_length | The length of key (including terminating '\0'). |
[in] | key_hash | The hash of key . |
[in] | data | The data to associate with the string given by key . Cannot be NULL . |
This function adds key
to hash
.
key
must be unique within the hash table so that eina_hash_find() and eina_hash_del() operate on the correct data item. key_hash
must match key
so that the correct item can be found by eina_hash_find_by_hash(). Key strings are case sensitive.
Unlike eina_hash_add_by_hash(), this function does not make a copy of key
, so it must be a string constant or stored elsewhere (such as inside the object being added).
EINA_API 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.
[in,out] | hash | The given hash table. Cannot be NULL . |
[in] | key | The key. Cannot be NULL . |
[in] | key_length | The length of the key (including terminating '\0'). |
[in] | key_hash | The hash that always matches the key. |
This function removes the entry identified by 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. If hash
or key
are NULL
, the function returns EINA_FALSE immediately.
References EINA_FALSE, and EINA_SAFETY_ON_NULL_RETURN_VAL.
Referenced by eina_file_close().
Removes the entry identified by a key from the given hash table.
This version will calculate key length and hash by using functions provided to the hash creation function.
[in,out] | hash | The given hash table. Cannot be NULL . |
[in] | key | The key. Cannot be NULL . |
This function removes the entry identified by key
from hash
. The key length and hash will be calculated automatically via a function provided to the hash 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 function returns EINA_FALSE immediately.
References EINA_FALSE, and EINA_SAFETY_ON_NULL_RETURN_VAL.
Referenced by ecore_thread_global_data_del(), ecore_thread_local_data_del(), ecore_wl2_display_destroy(), ecore_wl2_display_disconnect(), edje_external_type_unregister(), eeze_net_free(), efreet_desktop_x_field_del(), and efreet_desktop_x_field_set().
Removes an entry from a hash table identified by its data value.
[in,out] | hash | The given hash table. Cannot be NULL . |
[in] | data | The data value to search and remove. Cannot be NULL . |
hash
or data
are NULL
, EINA_TRUE otherwise. thing goes fine.This function removes the entry identified by data
from hash
. If a free function was given to the callback on creation, it will be called for the data being deleted.
References EINA_FALSE, and EINA_SAFETY_ON_NULL_RETURN_VAL.
Referenced by eina_hash_del(), and eina_hash_del_by_hash().
EINA_API 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 a data value from the given hash table.
If key
is NULL
, then data
is used to find a match to remove.
[in,out] | hash | The given hash table. Cannot be NULL . |
[in] | key | The key. |
[in] | key_length | The length of the key. |
[in] | key_hash | The hash that always match the key. |
[in] | data | The data pointer to remove if the key is NULL . |
This function removes the entry identified by 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 function returns 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
.
References EINA_FALSE, eina_hash_del_by_data(), and EINA_SAFETY_ON_NULL_RETURN_VAL.
EINA_API void * eina_hash_find_by_hash | ( | const Eina_Hash * | hash, |
const void * | key, | ||
int | key_length, | ||
int | key_hash | ||
) |
Retrieves a specific entry from the given hash table.
[in] | hash | The given hash table. 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
if hash
is NULL
or if the data pointer could not be retrieved.This function retrieves the entry associated with 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
.
References _Eina_Hash_Tuple::data, EINA_SAFETY_ON_NULL_RETURN_VAL, _Eina_Hash_Tuple::key, and _Eina_Hash_Tuple::key_length.
Referenced by eina_file_close(), and eina_hash_find().
EINA_API 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 previous entry.
[in,out] | hash | The given hash table. |
[in] | key | The key of the entry to modify. |
[in] | key_length | Should be the length of key (don't forget to count '\0' for string). |
[in] | key_hash | The hash that always matches the key. Ignored if key is NULL . |
[in] | data | The data to replace the current entry, if it exists. |
NULL
if not found. If an existing entry is not found, nothing is added to the hash. References _Eina_Hash_Tuple::data, EINA_SAFETY_ON_NULL_RETURN_VAL, _Eina_Hash_Tuple::key, and _Eina_Hash_Tuple::key_length.
Referenced by eina_hash_modify().
EINA_API Eina_Iterator * eina_hash_iterator_key_new | ( | const Eina_Hash * | hash | ) |
Returns a new iterator associated with hash keys.
[in] | hash | The hash. |
NULL
if memory could not be allocated.This function returns a newly allocated iterator associated with hash
. If hash
is not populated, this function still returns a valid iterator that will always return false on eina_iterator_next().
References EINA_MAGIC_SET, FUNC_ITERATOR_FREE, FUNC_ITERATOR_GET_CONTAINER, and FUNC_ITERATOR_NEXT.
Referenced by edje_edit_data_list_get(), edje_edit_data_source_generate(), edje_edit_group_data_list_get(), and edje_mmap_collection_list().
EINA_API Eina_Iterator * eina_hash_iterator_data_new | ( | const Eina_Hash * | hash | ) |
Returns a new iterator associated with a hash.
[in] | hash | The hash. |
NULL
if memory could not be allocated.This function returns a newly allocated iterator associated with hash
. If hash
is not populated, this function still returns a valid iterator that will always return false on eina_iterator_next().
References EINA_MAGIC_SET, FUNC_ITERATOR_FREE, FUNC_ITERATOR_GET_CONTAINER, and FUNC_ITERATOR_NEXT.
Referenced by ecore_wl2_display_globals_get(), ecore_wl_window_surface_find(), edje_edit_clean_save_as(), edje_edit_font_path_get(), edje_edit_fonts_list_get(), edje_edit_group_add(), edje_edit_group_aliased_get(), edje_edit_group_aliases_get(), edje_edit_group_copy(), edje_edit_image_replace(), edje_edit_image_set_del(), edje_edit_set_usage_list_get(), edje_edit_vector_usage_list_get(), edje_file_iterator_new(), edje_mmap_group_exists(), eina_cow_gc(), eina_file_flush(), and eio_monitoring_interval_set().
EINA_API Eina_Iterator * eina_hash_iterator_tuple_new | ( | const Eina_Hash * | hash | ) |
Returned a new iterator associated with hash keys and data.
[in] | hash | The hash. |
NULL
if memory could not be allocated.This function returns a newly allocated iterator associated with hash
. If hash
is not populated, this function still returns a valid iterator that will always return false on eina_iterator_next().
References EINA_MAGIC_SET, FUNC_ITERATOR_FREE, FUNC_ITERATOR_GET_CONTAINER, and FUNC_ITERATOR_NEXT.
Referenced by edje_external_iterator_get(), edje_mmap_color_class_iterator_new(), edje_mmap_size_class_iterator_new(), edje_mmap_text_class_iterator_new(), and eina_hash_foreach().
EINA_API 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.
[in] | hash | The hash table whose members will be walked. |
[in] | func | The function to call on each parameter. |
[in] | fdata | The data pointer to pass to the function being called. |
This function iterates over the hash table hash
, calling the function func
on each member. If func
modifies the contents of the hash table, or wishes to stop processing it should return EINA_FALSE. If func
returns EINA_TRUE the foreach loop will keep processing.
Example:
References EINA_EACH_CB, eina_hash_iterator_tuple_new(), eina_iterator_foreach(), eina_iterator_free(), and EINA_SAFETY_ON_NULL_RETURN.
Referenced by ecore_buffer_shutdown(), edje_color_class_list(), edje_size_class_list(), edje_text_class_list(), and elm_theme_color_class_list().
Appends data to an Eina_List inside a hash.
This function is identical to the sequence of calling eina_hash_find(), eina_list_append(), eina_hash_set(), but with one fewer required hash lookup.
[in,out] | hash | The hash table. |
[in] | key | The key associated with the data. |
[in] | data | The data to append to the list. |
References _Eina_Hash_Tuple::data, eina_list_append(), EINA_SAFETY_ON_NULL_RETURN, _Eina_Hash_Tuple::key, and _Eina_Hash_Tuple::key_length.
Referenced by elm_drop_target_add().
EINA_API void eina_hash_list_direct_append | ( | Eina_Hash * | hash, |
const void * | key, | ||
const void * | data | ||
) |
Appends data to an Eina_List inside a hash using eina_hash_direct_add().
This function is identical to the sequence of calling eina_hash_find(), eina_list_append(), eina_hash_set(), but with one fewer required hash lookup.
[in,out] | hash | The hash table. |
[in] | key | The key associated with the data. |
[in] | data | The data to append to the list. |
References _Eina_Hash_Tuple::data, eina_list_append(), EINA_SAFETY_ON_NULL_RETURN, _Eina_Hash_Tuple::key, and _Eina_Hash_Tuple::key_length.
Prepends data to an Eina_List inside a hash.
This function is identical to the sequence of calling eina_hash_find(), eina_list_prepend(), eina_hash_set(), but with one fewer required hash lookup.
[in,out] | hash | The hash table. |
[in] | key | The key associated with the data. |
[in] | data | The data to prepend to the list. |
References _Eina_Hash_Tuple::data, eina_list_append(), eina_list_prepend(), EINA_SAFETY_ON_NULL_RETURN, _Eina_Hash_Tuple::key, and _Eina_Hash_Tuple::key_length.
Referenced by evas_object_name_set().
EINA_API void eina_hash_list_direct_prepend | ( | Eina_Hash * | hash, |
const void * | key, | ||
const void * | data | ||
) |
Prepends data to an Eina_List inside a hash using eina_hash_direct_add().
This function is identical to the sequence of calling eina_hash_find(), eina_list_prepend(), eina_hash_set(), but with one fewer required hash lookup.
[in,out] | hash | The hash table. |
[in] | key | The key associated with the data. |
[in] | data | The data to prepend to the list. |
References _Eina_Hash_Tuple::data, eina_list_append(), eina_list_prepend(), EINA_SAFETY_ON_NULL_RETURN, _Eina_Hash_Tuple::key, and _Eina_Hash_Tuple::key_length.
Removes data from an Eina_List inside a hash.
This function is identical to the sequence of calling eina_hash_find(), eina_list_remove(), eina_hash_set(), but with one fewer required hash lookup.
[in,out] | hash | The hash table. |
[in] | key | The key associated with the data. |
[in] | data | The data to remove from the list. |
References _Eina_Hash_Tuple::data, eina_list_remove(), EINA_SAFETY_ON_NULL_RETURN, _Eina_Hash_Tuple::key, and _Eina_Hash_Tuple::key_length.
Referenced by elm_drop_target_del(), and evas_object_name_set().
EINA_API 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. |
Referenced by eina_file_close(), eina_hash_string_small_new(), and eina_hash_string_superfast_new().
|
inlinestatic |
Hash function first reported by Dan Bernstein many years ago in comp.lang.c.
[in] | key | The key to hash. |
[in] | len | The length of the key. |
Referenced by eina_hash_string_djb2_new().
|
inlinestatic |
Hash function first reported by Dan Bernstein many years ago in comp.lang.c.
[in] | key | The key to hash. |
[in] | plen | The length of the key. |
|
inlinestatic |
Hash function from http://web.archive.org/web/20071223173210/http://www.concentric.net/~Ttwang/tech/inthash.htm.
[in] | pkey | The key to hash. |
[in] | len | The length of the key. |
Referenced by eina_hash_int32_new(), and eina_hash_pointer_new().
|
inlinestatic |
Hash function from http://web.archive.org/web/20071223173210/http://www.concentric.net/~Ttwang/tech/inthash.htm.
[in] | pkey | The key to hash. |
[in] | len | The length of the key. |
Referenced by eina_file_map_key_hash(), eina_hash_int64_new(), and eina_hash_pointer_new().
|
inlinestatic |
Hash function from http://sites.google.com/site/murmurhash/.
[in] | key | The key to hash. |
[in] | len | The length of the key. |
|
inlinestatic |
Hash function using crc-32 algorithm and and 0xEDB88320 polynomial.
[in] | key | The key to hash. |
[in] | len | The length of the key. |