#include "gwlib.h"Include dependency graph for dict.c:

Go to the source code of this file.
Data Structures | |
| struct | Item |
| struct | Dict |
Typedefs | |
| typedef Item | Item |
Functions | |
| Item * | item_create (Octstr *key, void *value) |
| void | item_destroy (void *item) |
| int | item_has_key (void *item, void *key) |
| void | lock (Dict *dict) |
| void | unlock (Dict *dict) |
| long | key_to_index (Dict *dict, Octstr *key) |
| int | handle_null_value (Dict *dict, Octstr *key, void *value) |
| int | dict_put_true (Dict *dict, Octstr *key, void *value) |
| Dict * | dict_create (long size_hint, void(*destroy_value)(void *)) |
| void | dict_destroy (Dict *dict) |
| void | dict_put (Dict *dict, Octstr *key, void *value) |
| int | dict_put_once (Dict *dict, Octstr *key, void *value) |
| void * | dict_get (Dict *dict, Octstr *key) |
| void * | dict_remove (Dict *dict, Octstr *key) |
| long | dict_key_count (Dict *dict) |
| List * | dict_keys (Dict *dict) |
|
|
Definition at line 74 of file dict.c. Referenced by dict_destroy(), dict_get(), dict_keys(), dict_put(), dict_put_true(), dict_remove(), item_create(), item_destroy(), and item_has_key(). |
|
||||||||||||
|
Definition at line 192 of file dict.c. References mutex_create, Dict::size, Dict::tab, and List::tab. Referenced by brunet_parse_body(), cfg_create(), clickatell_parse_body(), conn_pool_init(), create_group(), init_concat_handler(), init_reroute(), main(), parse_value_element(), port_init(), pushusers_create(), radius_acct_init(), run_smsbox(), server(), smasi_create(), smpp_create(), smsbox_start(), store_file_init(), urltrans_create(), wap_map_add_user(), wap_push_ppg_init(), wap_push_ppg_pushuser_list_add(), wml_init(), and xmlrpc_create_struct_value(). 00193 {
00194 Dict *dict;
00195 long i;
00196
00197 dict = gw_malloc(sizeof(*dict));
00198
00199 /*
00200 * Hash tables tend to work well until they are fill to about 50%.
00201 */
00202 dict->size = size_hint * 2;
00203
00204 dict->tab = gw_malloc(sizeof(dict->tab[0]) * dict->size);
00205 for (i = 0; i < dict->size; ++i)
00206 dict->tab[i] = NULL;
00207 dict->lock = mutex_create();
00208 dict->destroy_value = destroy_value;
00209 dict->key_count = 0;
00210
00211 return dict;
00212 }
|
|
Here is the call graph for this function:

|
||||||||||||
Here is the call graph for this function:

|
|
Definition at line 335 of file dict.c. References Dict::key_count, lock, result, and unlock. Referenced by boxc_status(), main(), proxy_thread(), run_smsbox(), server(), store_file_dump(), store_file_load(), store_file_messages(), xmlrpc_count_members(), and xmlrpc_print_struct(). 00336 {
00337 long result;
00338
00339 lock(dict);
00340 result = dict->key_count;
00341 unlock(dict);
00342
00343 return result;
00344 }
|
|
|
Definition at line 347 of file dict.c. References gwlist_append(), gwlist_create, gwlist_get(), gwlist_len(), Item, Item::key, lock, octstr_duplicate, Dict::size, Dict::tab, and unlock. Referenced by add_group(), cfg_dump(), clear_old_concat_parts(), do_dump(), do_queue_cleanup(), grp_dump(), io_thread(), run_smsbox(), store_file_load(), store_file_status(), and xmlrpc_print_struct(). 00348 {
00349 List *list;
00350 Item *item;
00351 long i, j;
00352
00353 list = gwlist_create();
00354
00355 lock(dict);
00356 for (i = 0; i < dict->size; ++i) {
00357 if (dict->tab[i] == NULL)
00358 continue;
00359 for (j = 0; j < gwlist_len(dict->tab[i]); ++j) {
00360 item = gwlist_get(dict->tab[i], j);
00361 gwlist_append(list, octstr_duplicate(item->key));
00362 }
00363 }
00364 unlock(dict);
00365
00366 return list;
00367 }
|
Here is the call graph for this function:

|
||||||||||||||||
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 271 of file dict.c. References dict_put_true(), and handle_null_value(). Referenced by init_reroute(), init_smsbox_routes(), pap_request_thread(), parse_struct_element(), and xmlrpc_add_member(). 00272 {
00273 int ret;
00274
00275 ret = 1;
00276 if (handle_null_value(dict, key, value))
00277 return 1;
00278 if (dict_put_true(dict, key, value)) {
00279 ret = 1;
00280 } else {
00281 ret = 0;
00282 }
00283 return ret;
00284 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 154 of file dict.c. References Dict::destroy_value, gwlist_append(), gwlist_create, gwlist_search(), Item, item_create(), item_has_key(), Dict::key_count, key_to_index(), lock, Dict::tab, and unlock. Referenced by dict_put_once(). 00155 {
00156 Item *p;
00157 long i;
00158 int item_unique;
00159
00160 item_unique = 0;
00161 lock(dict);
00162 i = key_to_index(dict, key);
00163
00164 if (dict->tab[i] == NULL) {
00165 dict->tab[i] = gwlist_create();
00166 p = NULL;
00167 } else {
00168 p = gwlist_search(dict->tab[i], key, item_has_key);
00169 }
00170
00171 if (p == NULL) {
00172 p = item_create(key, value);
00173 gwlist_append(dict->tab[i], p);
00174 dict->key_count++;
00175 item_unique = 1;
00176 } else {
00177 if (dict->destroy_value != NULL)
00178 dict->destroy_value(value);
00179 item_unique = 0;
00180 }
00181
00182 unlock(dict);
00183
00184 return item_unique;
00185 }
|
Here is the call graph for this function:

|
||||||||||||
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 142 of file dict.c. References Dict::destroy_value, and dict_remove(). Referenced by dict_put_once(). 00143 {
00144 if (value == NULL) {
00145 value = dict_remove(dict, key);
00146 if (dict->destroy_value != NULL)
00147 dict->destroy_value(value);
00148 return 1;
00149 }
00150
00151 return 0;
00152 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 81 of file dict.c. References Item, Item::key, and octstr_duplicate. Referenced by dict_put(), and dict_put_true(). 00082 {
00083 Item *item;
00084
00085 item = gw_malloc(sizeof(*item));
00086 item->key = octstr_duplicate(key);
00087 item->value = value;
00088 return item;
00089 }
|
|
|
Definition at line 91 of file dict.c. References Item, Item::key, and octstr_destroy(). Referenced by dict_destroy(), dict_remove(), and gw_prioqueue_destroy(). 00092 {
00093 Item *p;
00094
00095 p = item;
00096 octstr_destroy(p->key);
00097 gw_free(p);
00098 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 101 of file dict.c. References Item, and octstr_compare(). Referenced by dict_get(), dict_put(), dict_put_true(), and dict_remove(). 00102 {
00103 return octstr_compare(key, ((Item *) item)->key) == 0;
00104 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 137 of file dict.c. References octstr_hash_key(), and Dict::size. Referenced by dict_get(), dict_put(), dict_put_true(), and dict_remove(). 00138 {
00139 return octstr_hash_key(key) % dict->size;
00140 }
|
Here is the call graph for this function:

|
|
Definition at line 125 of file dict.c. References Dict::lock, and mutex_lock. 00126 {
00127 mutex_lock(dict->lock);
00128 }
|
|
|
Definition at line 131 of file dict.c. References Dict::lock, and mutex_unlock. 00132 {
00133 mutex_unlock(dict->lock);
00134 }
|