FreeSWITCH API Documentation  1.7.0
Macros | Functions
Hash Functions
+ Collaboration diagram for Hash Functions:

Macros

#define switch_core_hash_init(_hash)   switch_core_hash_init_case(_hash, SWITCH_TRUE)
 
#define switch_core_hash_init_nocase(_hash)   switch_core_hash_init_case(_hash, SWITCH_FALSE)
 
#define switch_core_hash_insert(_h, _k, _d)   switch_core_hash_insert_destructor(_h, _k, _d, NULL)
 
#define switch_core_hash_first(_h)   switch_core_hash_first_iter(_h, NULL)
 

Functions

switch_status_t switch_core_hash_init_case (_Out_ switch_hash_t **hash, switch_bool_t case_sensitive)
 Initialize a hash table. More...
 
switch_status_t switch_core_hash_destroy (_Inout_ switch_hash_t **hash)
 Destroy an existing hash table. More...
 
switch_status_t switch_core_hash_insert_destructor (_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ const void *data, hashtable_destructor_t destructor)
 Insert data into a hash. More...
 
switch_status_t switch_core_hash_insert_locked (_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ const void *data, _In_opt_ switch_mutex_t *mutex)
 Insert data into a hash. More...
 
switch_status_t switch_core_hash_insert_wrlock (switch_hash_t *hash, const char *key, const void *data, switch_thread_rwlock_t *rwlock)
 Retrieve data from a given hash. More...
 
void * switch_core_hash_delete (_In_ switch_hash_t *hash, _In_z_ const char *key)
 Delete data from a hash based on desired key. More...
 
void * switch_core_hash_delete_locked (_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_mutex_t *mutex)
 Delete data from a hash based on desired key. More...
 
void * switch_core_hash_delete_wrlock (_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_thread_rwlock_t *rwlock)
 Delete data from a hash based on desired key. More...
 
switch_status_t switch_core_hash_delete_multi (_In_ switch_hash_t *hash, _In_ switch_hash_delete_callback_t callback, _In_opt_ void *pData)
 Delete data from a hash based on callback function. More...
 
void * switch_core_hash_find (_In_ switch_hash_t *hash, _In_z_ const char *key)
 Retrieve data from a given hash. More...
 
void * switch_core_hash_find_locked (_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex)
 Retrieve data from a given hash. More...
 
void * switch_core_hash_find_rdlock (_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_thread_rwlock_t *rwlock)
 Retrieve data from a given hash. More...
 
switch_hash_index_tswitch_core_hash_first_iter (_In_ switch_hash_t *hash, switch_hash_index_t *hi)
 Gets the first element of a hashtable. More...
 
switch_bool_t switch_core_hash_empty (switch_hash_t *hash)
 tells if a hash is empty More...
 
switch_hash_index_tswitch_core_hash_next (_In_ switch_hash_index_t **hi)
 Gets the next element of a hashtable. More...
 
void switch_core_hash_this (_In_ switch_hash_index_t *hi, _Out_opt_ptrdiff_cap_(klen) const void **key, _Out_opt_ switch_ssize_t *klen, _Out_ void **val)
 Gets the key and value of the current hash element. More...
 
void switch_core_hash_this_val (switch_hash_index_t *hi, void *val)
 
switch_status_t switch_core_inthash_init (switch_inthash_t **hash)
 
switch_status_t switch_core_inthash_destroy (switch_inthash_t **hash)
 
switch_status_t switch_core_inthash_insert (switch_inthash_t *hash, uint32_t key, const void *data)
 
void * switch_core_inthash_delete (switch_inthash_t *hash, uint32_t key)
 
void * switch_core_inthash_find (switch_inthash_t *hash, uint32_t key)
 

Detailed Description

Macro Definition Documentation

#define switch_core_hash_first (   _h)    switch_core_hash_first_iter(_h, NULL)
#define switch_core_hash_init (   _hash)    switch_core_hash_init_case(_hash, SWITCH_TRUE)
#define switch_core_hash_init_nocase (   _hash)    switch_core_hash_init_case(_hash, SWITCH_FALSE)

Definition at line 1391 of file switch_core.h.

Referenced by switch_loadable_module_init().

#define switch_core_hash_insert (   _h,
  _k,
  _d 
)    switch_core_hash_insert_destructor(_h, _k, _d, NULL)

Function Documentation

void* switch_core_hash_delete ( _In_ switch_hash_t hash,
_In_z_ const char *  key 
)
void* switch_core_hash_delete_locked ( _In_ switch_hash_t hash,
_In_z_ const char *  key,
_In_opt_ switch_mutex_t mutex 
)

Delete data from a hash based on desired key.

Parameters
hashthe hash to delete from
keythe key from which to delete the data
mutexoptional mutex to lock
Returns
a pointer to the deleted data
switch_status_t switch_core_hash_delete_multi ( _In_ switch_hash_t hash,
_In_ switch_hash_delete_callback_t  callback,
_In_opt_ void *  pData 
)

Delete data from a hash based on callback function.

Parameters
hashthe hash to delete from
callbackthe function to call which returns SWITCH_TRUE to delete, SWITCH_FALSE to preserve
Returns
SWITCH_STATUS_SUCCESS if any data is deleted
void* switch_core_hash_delete_wrlock ( _In_ switch_hash_t hash,
_In_z_ const char *  key,
_In_opt_ switch_thread_rwlock_t rwlock 
)

Delete data from a hash based on desired key.

Parameters
hashthe hash to delete from
keythe key from which to delete the data
mutexoptional rwlock to wrlock
Returns
a pointer to the deleted data
switch_status_t switch_core_hash_destroy ( _Inout_ switch_hash_t **  hash)
switch_bool_t switch_core_hash_empty ( switch_hash_t hash)

tells if a hash is empty

Parameters
hashthe hashtable
Returns
TRUE or FALSE depending on if the hash is empty

Definition at line 216 of file switch_core_hash.c.

References switch_core_hash_first, SWITCH_FALSE, switch_safe_free, and SWITCH_TRUE.

217 {
219 
220  if (hi) {
221  switch_safe_free(hi);
222  return SWITCH_FALSE;
223  }
224 
225  return SWITCH_TRUE;
226 
227 }
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
#define switch_core_hash_first(_h)
Definition: switch_core.h:1501
void* switch_core_hash_find ( _In_ switch_hash_t hash,
_In_z_ const char *  key 
)

Retrieve data from a given hash.

Parameters
hashthe hash to retrieve from
keythe key to retrieve
Returns
a pointer to the data held in the key

Referenced by _switch_event_channel_broadcast(), switch_channel_clear_app_flag_key(), switch_channel_set_app_flag_key(), switch_channel_set_device_id(), switch_channel_test_app_flag_key(), switch_check_network_list_ip_token(), switch_console_run_complete_func(), switch_core_get_secondary_recover_callback(), switch_core_mime_add_type(), switch_core_mime_ext2type(), switch_core_mime_type2ext(), switch_core_register_secondary_recover_callback(), switch_core_session_event_send(), switch_core_session_message_send(), switch_core_session_perform_force_locate(), switch_core_session_perform_locate(), switch_core_session_request_uuid(), switch_core_session_set_uuid(), switch_default_ptime(), switch_event_bind_removable(), switch_event_build_param_string(), switch_event_channel_permission_clear(), switch_event_channel_permission_modify(), switch_event_channel_permission_verify(), switch_event_channel_sub_channel(), switch_event_channel_unsub_channel(), switch_event_free_subclass_detailed(), switch_event_reserve_subclass_detailed(), switch_ivr_digit_stream_parser_feed(), switch_ivr_dmachine_bind(), switch_ivr_dmachine_clear_realm(), switch_ivr_dmachine_set_realm(), switch_live_array_add(), switch_live_array_create(), switch_live_array_del(), switch_live_array_get(), switch_loadable_module_exists(), switch_loadable_module_get_codec_interface(), switch_loadable_module_get_endpoint_interface(), switch_loadable_module_get_file_interface(), switch_loadable_module_process(), switch_loadable_module_unload_module(), switch_loadable_module_unprocess(), switch_lookup_timezone(), switch_rtp_release_port(), switch_rtp_request_port(), switch_xml_clear_user_cache(), switch_xml_locate_user_cache(), and switch_xml_user_cache().

void* switch_core_hash_find_locked ( _In_ switch_hash_t hash,
_In_z_ const char *  key,
_In_ switch_mutex_t mutex 
)

Retrieve data from a given hash.

Parameters
hashthe hash to retrieve from
keythe key to retrieve
mutexoptional mutex to lock
Returns
a pointer to the data held in the key

Referenced by switch_channel_get_private(), switch_channel_get_private_partner(), switch_loadable_module_get_management_interface(), switch_loadable_module_get_say_interface(), and switch_loadable_module_load_module_ex().

void* switch_core_hash_find_rdlock ( _In_ switch_hash_t hash,
_In_z_ const char *  key,
_In_ switch_thread_rwlock_t rwlock 
)

Retrieve data from a given hash.

Parameters
hashthe hash to retrieve from
keythe key to retrieve
mutexoptional rwlock to rdlock
Returns
a pointer to the data held in the key
switch_hash_index_t* switch_core_hash_first_iter ( _In_ switch_hash_t hash,
switch_hash_index_t hi 
)

Gets the first element of a hashtable.

Parameters
deprecate_me[deprecated] NULL
hashthe hashtable to use
Returns
The element, or NULL if it wasn't found

Referenced by switch_xml_clear_user_cache(), and unsub_all_switch_event_channel().

switch_status_t switch_core_hash_init_case ( _Out_ switch_hash_t **  hash,
switch_bool_t  case_sensitive 
)

Initialize a hash table.

Parameters
hasha NULL pointer to a hash table to aim at the new hash
poolthe pool to use for the new hash
Returns
SWITCH_STATUS_SUCCESS if the hash is created

Referenced by switch_core_init().

switch_status_t switch_core_hash_insert_destructor ( _In_ switch_hash_t hash,
_In_z_ const char *  key,
_In_opt_ const void *  data,
hashtable_destructor_t  destructor 
)

Insert data into a hash.

Parameters
hashthe hash to add data to
keythe name of the key to add the data to
datathe data to add
Returns
SWITCH_STATUS_SUCCESS if the data is added
Note
the string key must be a constant or a dynamic string
switch_status_t switch_core_hash_insert_locked ( _In_ switch_hash_t hash,
_In_z_ const char *  key,
_In_opt_ const void *  data,
_In_opt_ switch_mutex_t mutex 
)

Insert data into a hash.

Parameters
hashthe hash to add data to
keythe name of the key to add the data to
datathe data to add
mutexoptional mutex to lock
Returns
SWITCH_STATUS_SUCCESS if the data is added
Note
the string key must be a constant or a dynamic string

Referenced by switch_channel_set_private(), and switch_loadable_module_unload_module().

switch_status_t switch_core_hash_insert_wrlock ( switch_hash_t hash,
const char *  key,
const void *  data,
switch_thread_rwlock_t rwlock 
)

Retrieve data from a given hash.

Parameters
hashthe hash to retrieve from
keythe key to retrieve
mutexoptional rwlock to wrlock
Returns
a pointer to the data held in the key

Definition at line 84 of file switch_core_hash.c.

References switch_core_hash_insert, SWITCH_STATUS_FALSE, switch_thread_rwlock_unlock(), and switch_thread_rwlock_wrlock().

85 {
87 
88  if (rwlock) {
90  }
91 
92  status = switch_core_hash_insert(hash, key, data);
93 
94  if (rwlock) {
96  }
97 
98  return status;
99 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:263
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:237
switch_thread_rwlock_t * rwlock
Definition: switch_event.c:73
switch_status_t
Common return values.
#define switch_core_hash_insert(_h, _k, _d)
Definition: switch_core.h:1410
switch_hash_index_t* switch_core_hash_next ( _In_ switch_hash_index_t **  hi)
void switch_core_hash_this ( _In_ switch_hash_index_t hi,
_Out_opt_ptrdiff_cap_(klen) const void **  key,
_Out_opt_ switch_ssize_t klen,
_Out_ void **  val 
)
void switch_core_hash_this_val ( switch_hash_index_t hi,
void *  val 
)

Definition at line 244 of file switch_core_hash.c.

References switch_hashtable_this_val().

245 {
246  switch_hashtable_this_val(hi, val);
247 }
void switch_hashtable_this_val(switch_hashtable_iterator_t *i, void *val)
void* switch_core_inthash_delete ( switch_inthash_t hash,
uint32_t  key 
)

Definition at line 274 of file switch_core_hash.c.

References switch_hashtable_remove().

Referenced by hide_node(), switch_jb_pop_nack(), and switch_jb_put_packet().

275 {
276  return switch_hashtable_remove(hash, (void *)&key);
277 }
void * switch_hashtable_remove(switch_hashtable_t *h, void *k)
switch_status_t switch_core_inthash_destroy ( switch_inthash_t **  hash)

Definition at line 255 of file switch_core_hash.c.

References switch_hashtable_destroy(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_jb_destroy(), and switch_jb_reset().

256 {
258 
259  return SWITCH_STATUS_SUCCESS;
260 }
void switch_hashtable_destroy(switch_hashtable_t **h)
void* switch_core_inthash_find ( switch_inthash_t hash,
uint32_t  key 
)

Definition at line 279 of file switch_core_hash.c.

References switch_hashtable_search().

Referenced by jb_next_packet_by_seq(), jb_next_packet_by_ts(), switch_jb_get_packet_by_seq(), and switch_jb_peek_frame().

280 {
281  return switch_hashtable_search(hash, (void *)&key);
282 }
void * switch_hashtable_search(switch_hashtable_t *h, void *k)
switch_status_t switch_core_inthash_init ( switch_inthash_t **  hash)

Definition at line 250 of file switch_core_hash.c.

References switch_create_hashtable(), switch_hash_default_int(), and switch_hash_equalkeys_int().

Referenced by switch_jb_create(), switch_jb_reset(), and switch_jb_ts_mode().

251 {
253 }
static uint32_t switch_hash_default_int(void *ky)
switch_status_t switch_create_hashtable(switch_hashtable_t **hp, unsigned int minsize, unsigned int(*hashfunction)(void *), int(*key_eq_fn)(void *, void *))
static int switch_hash_equalkeys_int(void *k1, void *k2)
switch_status_t switch_core_inthash_insert ( switch_inthash_t hash,
uint32_t  key,
const void *  data 
)

Definition at line 262 of file switch_core_hash.c.

References HASHTABLE_DUP_CHECK, HASHTABLE_FLAG_FREE_KEY, switch_hashtable_insert_destructor(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_zmalloc.

Referenced by add_node(), switch_jb_pop_nack(), and switch_jb_put_packet().

263 {
264  uint32_t *k = NULL;
265  int r = 0;
266 
267  switch_zmalloc(k, sizeof(*k));
268  *k = key;
270 
272 }
int switch_hashtable_insert_destructor(switch_hashtable_t *h, void *k, void *v, hashtable_flag_t flags, hashtable_destructor_t destructor)
#define switch_zmalloc(ptr, len)