|
json-c 0.18
|
Internal methods for working with json_type_object objects. Although this is exposed by the json_object_get_object() function and within the json_object_iter type, it is not recommended for direct use. More...
Data Structures | |
| struct | lh_entry |
| struct | lh_table |
Macros | |
| #define | LH_PRIME 0x9e370001UL |
| #define | LH_LOAD_FACTOR 0.66 |
| #define | LH_EMPTY (void *)-1 |
| #define | LH_FREED (void *)-2 |
| #define | JSON_C_STR_HASH_DFLT 0 |
| #define | JSON_C_STR_HASH_PERLLIKE 1 |
| #define | lh_foreach(table, entry) |
| #define | lh_foreach_safe(table, entry, tmp) |
Typedefs | |
| typedef void | lh_entry_free_fn(struct lh_entry *e) |
| typedef unsigned long | lh_hash_fn(const void *k) |
| typedef int | lh_equal_fn(const void *k1, const void *k2) |
| typedef struct lh_table | lh_table |
Functions | |
| int | json_global_set_string_hash (const int h) |
| struct lh_table * | lh_table_new (int size, lh_entry_free_fn *free_fn, lh_hash_fn *hash_fn, lh_equal_fn *equal_fn) |
| struct lh_table * | lh_kchar_table_new (int size, lh_entry_free_fn *free_fn) |
| struct lh_table * | lh_kptr_table_new (int size, lh_entry_free_fn *free_fn) |
| void | lh_table_free (struct lh_table *t) |
| int | lh_table_insert (struct lh_table *t, const void *k, const void *v) |
| int | lh_table_insert_w_hash (struct lh_table *t, const void *k, const void *v, const unsigned long h, const unsigned opts) |
| struct lh_entry * | lh_table_lookup_entry (struct lh_table *t, const void *k) |
| struct lh_entry * | lh_table_lookup_entry_w_hash (struct lh_table *t, const void *k, const unsigned long h) |
| json_bool | lh_table_lookup_ex (struct lh_table *t, const void *k, void **v) |
| int | lh_table_delete_entry (struct lh_table *t, struct lh_entry *e) |
| int | lh_table_delete (struct lh_table *t, const void *k) |
| int | lh_table_length (struct lh_table *t) |
| int | lh_table_resize (struct lh_table *t, int new_size) |
| static struct lh_entry * | lh_table_head (const lh_table *t) |
| static unsigned long | lh_get_hash (const struct lh_table *t, const void *k) |
| static void * | lh_entry_k (const struct lh_entry *e) |
| static int | lh_entry_k_is_constant (const struct lh_entry *e) |
| static void * | lh_entry_v (const struct lh_entry *e) |
| static void | lh_entry_set_val (struct lh_entry *e, void *newval) |
| static struct lh_entry * | lh_entry_next (const struct lh_entry *e) |
| static struct lh_entry * | lh_entry_prev (const struct lh_entry *e) |
Internal methods for working with json_type_object objects. Although this is exposed by the json_object_get_object() function and within the json_object_iter type, it is not recommended for direct use.
| #define JSON_C_STR_HASH_DFLT 0 |
default string hash function
| #define JSON_C_STR_HASH_PERLLIKE 1 |
perl-like string hash function
| #define LH_EMPTY (void *)-1 |
sentinel pointer value for empty slots
| #define lh_foreach | ( | table, | |
| entry ) |
Convenience list iterator.
| #define lh_foreach_safe | ( | table, | |
| entry, | |||
| tmp ) |
lh_foreach_safe allows calling of deletion routine while iterating.
| #define LH_FREED (void *)-2 |
sentinel pointer value for freed slots
| #define LH_LOAD_FACTOR 0.66 |
The fraction of filled hash buckets until an insert will cause the table to be resized. This can range from just above 0 up to 1.0.
| #define LH_PRIME 0x9e370001UL |
golden prime used in hash functions
| typedef void lh_entry_free_fn(struct lh_entry *e) |
callback function prototypes
| typedef int lh_equal_fn(const void *k1, const void *k2) |
callback function prototypes
| typedef unsigned long lh_hash_fn(const void *k) |
callback function prototypes
| typedef struct lh_table lh_table |
| int json_global_set_string_hash | ( | const int | h | ) |
This function sets the hash function to be used for strings. Must be one of the JSON_C_STR_HASH_* values.
References json_global_set_string_hash().
Referenced by json_global_set_string_hash().
|
inlinestatic |
Return a non-const version of lh_entry.k.
lh_entry.k is const to indicate and help ensure that linkhash itself doesn't modify it, but callers are allowed to do what they want with it.
References lh_entry::k, and lh_entry_k().
Referenced by lh_entry_k().
|
inlinestatic |
Returns 1 if the key for the given entry is constant, and thus does not need to be freed when the lh_entry is freed.
References lh_entry::k_is_constant, and lh_entry_k_is_constant().
Referenced by lh_entry_k_is_constant().
Return the next element, or NULL if there is no next element.
References lh_entry_next(), and lh_entry::next.
Referenced by lh_entry_next().
Return the previous element, or NULL if there is no previous element.
References lh_entry_prev(), and lh_entry::prev.
Referenced by lh_entry_prev().
|
inlinestatic |
Change the value for an entry. The caller is responsible for freeing the previous value.
References lh_entry_set_val(), and lh_entry::v.
Referenced by lh_entry_set_val().
|
inlinestatic |
Return a non-const version of lh_entry.v.
v is const to indicate and help ensure that linkhash itself doesn't modify it, but callers are allowed to do what they want with it.
References lh_entry_v(), and lh_entry::v.
Referenced by lh_entry_v().
|
inlinestatic |
Calculate the hash of a key for a given table.
This is an extension to support functions that need to calculate the hash several times and allows them to do it just once and then pass in the hash to all utility functions. Depending on use case, this can be a considerable performance improvement.
| t | the table (used to obtain hash function) |
| k | a pointer to the key to lookup |
References lh_table::hash_fn, lh_entry::k, and lh_get_hash().
Referenced by lh_get_hash().
|
extern |
Convenience function to create a new linkhash table with char keys.
| size | initial table size. |
| free_fn | callback function used to free memory for entries. |
References lh_kchar_table_new().
Referenced by lh_kchar_table_new().
|
extern |
Convenience function to create a new linkhash table with ptr keys.
| size | initial table size. |
| free_fn | callback function used to free memory for entries. |
References lh_kptr_table_new().
Referenced by lh_kptr_table_new().
|
extern |
Delete a record from the table.
If a callback free function is provided then it is called for the for the item being deleted.
| t | the table to delete from. |
| k | a pointer to the key to delete. |
References lh_table_delete().
Referenced by lh_table_delete().
Delete a record from the table.
If a callback free function is provided then it is called for the for the item being deleted.
| t | the table to delete from. |
| e | a pointer to the entry to delete. |
References lh_table_delete_entry().
Referenced by lh_table_delete_entry().
|
extern |
Free a linkhash table.
If a lh_entry_free_fn callback free function was provided then it is called for all entries in the table.
| t | table to free. |
References lh_table_free().
Referenced by lh_table_free().
Return the first entry in the lh_table.
References lh_table::head, and lh_table_head().
Referenced by lh_table_head().
|
extern |
Insert a record into the table.
| t | the table to insert into. |
| k | a pointer to the key to insert. |
| v | a pointer to the value to insert. |
0 is returned. On error, a negative value is returned. References lh_table_insert().
Referenced by lh_table_insert().
|
extern |
Insert a record into the table using a precalculated key hash.
The hash h, which should be calculated with lh_get_hash() on k, is provided by the caller, to allow for optimization when multiple operations with the same key are known to be needed.
| t | the table to insert into. |
| k | a pointer to the key to insert. |
| v | a pointer to the value to insert. |
| h | hash value of the key to insert |
| opts | if set to JSON_C_OBJECT_ADD_CONSTANT_KEY, sets lh_entry.k_is_constant so t's free function knows to avoid freeing the key. |
References lh_table_insert_w_hash().
Referenced by lh_table_insert_w_hash().
|
extern |
Return the number of entries in the table.
References lh_table_length().
Referenced by lh_table_length().
Lookup a record in the table.
| t | the table to lookup |
| k | a pointer to the key to lookup |
References lh_table_lookup_entry().
Referenced by lh_table_lookup_entry().
|
extern |
Lookup a record in the table using a precalculated key hash.
The hash h, which should be calculated with lh_get_hash() on k, is provided by the caller, to allow for optimization when multiple operations with the same key are known to be needed.
| t | the table to lookup |
| k | a pointer to the key to lookup |
| h | hash value of the key to lookup |
References lh_table_lookup_entry_w_hash().
Referenced by lh_table_lookup_entry_w_hash().
Lookup a record in the table.
| t | the table to lookup |
| k | a pointer to the key to lookup |
| v | a pointer to a where to store the found value (set to NULL if it doesn't exist). |
References lh_table_lookup_ex().
Referenced by lh_table_lookup_ex().
|
extern |
Create a new linkhash table.
| size | initial table size. The table is automatically resized although this incurs a performance penalty. |
| free_fn | callback function used to free memory for entries when lh_table_free or lh_table_delete is called. If NULL is provided, then memory for keys and values must be freed by the caller. |
| hash_fn | function used to hash keys. 2 standard ones are defined: lh_ptr_hash and lh_char_hash for hashing pointer values and C strings respectively. |
| equal_fn | comparison function to compare keys. 2 standard ones defined: lh_ptr_hash and lh_char_hash for comparing pointer values and C strings respectively. |
References lh_table_new().
Referenced by lh_table_new().
| int lh_table_resize | ( | struct lh_table * | t, |
| int | new_size ) |
Resizes the specified table.
| t | Pointer to table to resize. |
| new_size | New table size. Must be positive. |
0 is returned. On error, a negative value is returned. References lh_table_resize().
Referenced by lh_table_resize().