This header implements hash maps keyed on pointers, and with arbitrary value slots. The slots are arbitrary sized memory which is stored on the nodes for best efficiency. The slots are accessed directly using the *_mem functions, whereas some specialised functions are provided for pointers and integers.
| #define cucon_pmap_cct cucon_pmap_init |
| #define cucon_pmap_cct_copy_mem cucon_pmap_init_copy_mem |
| #define cucon_pmap_cct_copy_mem_ctor cucon_pmap_init_copy_mem_ctor |
| #define cucon_pmap_cct_copy_node cucon_pmap_init_copy_node |
| #define cucon_pmap_cct_copy_void cucon_pmap_init_copy_void |
| void cucon_pmap_assign_isecn | ( | cucon_pmap_t | dst, | |
| cucon_pmap_t | src | |||
| ) |
Assign to dst the intersection dst ∩ src, keeping the slots.
References cucon_umap_assign_isecn().
| void cucon_pmap_assign_isecn_union | ( | cucon_pmap_t | map0, | |
| cucon_pmap_t | map1 | |||
| ) |
Move all pairs of map0 with keys not in map1 to map1. This effectively assigns map0 ∩ map1 to map0 and map0 ∪ map1 to map1, where only keys are considered for the set operation tests.
References cucon_umap_assign_isecn_union().
| void cucon_pmap_assign_union_void | ( | cucon_pmap_t | dst, | |
| cucon_pmap_t | src | |||
| ) |
Assign to dst the union of dst and src, with void slots for duplicated nodes.
References cucon_umap_assign_union_void().
| cu_bool_t cucon_pmap_conj_keys | ( | cucon_pmap_t | map, | |
| cu_clop(cb, cu_bool_t, void const *) | ||||
| ) |
Perform a sequential conjunction of cb over keys in map.
Referenced by cucon_pset_conj().
| cu_bool_t cucon_pmap_conj_mem | ( | cucon_pmap_t | map, | |
| cu_clop(cb, cu_bool_t, void const *, void *) | ||||
| ) |
Sequentially conjunct cb over (key, value) pairs in map.
| cu_bool_t cucon_pmap_conj_node | ( | cucon_pmap_t | map, | |
| cu_clop(cb, cu_bool_t, cucon_pmap_node_t node) | ||||
| ) |
Sequential conjunction of cb over nodes in map.
References cu_clop, and cucon_umap_conj_node().
| void cucon_pmap_dump_idr_ptr | ( | cucon_pmap_t | map, | |
| FILE * | out | |||
| ) |
Dump map to out assuming keys are cu_idr_t and slots are pointers.
| void cucon_pmap_dump_stats | ( | cucon_pmap_t | map, | |
| FILE * | out | |||
| ) |
For profiling use.
References cucon_umap_dump_stats().
| cu_bool_t cucon_pmap_eq_keys | ( | cucon_pmap_t | map0, | |
| cucon_pmap_t | map1 | |||
| ) |
True iff map0 and map1 contains the same sets of keys.
References cucon_umap_eq_keys().
| cu_bool_t cucon_pmap_eq_mem | ( | cucon_pmap_t | map0, | |
| cucon_pmap_t | map1, | |||
| size_t | slot_size | |||
| ) |
True iff map0 and map1 are equal, assuming slot size is slot_size bytes and trivially comparable.
References cucon_umap_eq_mem().
| cu_bool_t cucon_pmap_eq_ptr | ( | cucon_pmap_t | map0, | |
| cucon_pmap_t | map1 | |||
| ) |
True iff map0 and map1 are equal, assuming slots are pointers with pointer equality.
References cucon_umap_eq_ptr().
| cu_bool_t cucon_pmap_erase | ( | cucon_pmap_t | map, | |
| void const * | key | |||
| ) |
If key has a mapping in map, erase it and return true, else return false. To optimise for many deletions, use _keep_cap variants and call cucon_umap_update_cap once afterwards.
References cucon_umap_erase().
| int cucon_pmap_erase_int | ( | cucon_pmap_t | map, | |
| void const * | key | |||
| ) |
If key has a mapping in map, erase it and return the int value stored in the slot, else return * INT_MIN.
int. References cucon_umap_erase_int().
| cu_bool_t cucon_pmap_erase_keep_cap | ( | cucon_pmap_t | map, | |
| void const * | key | |||
| ) |
If key has a mapping in map, erase it and return true, else return false. To optimise for many deletions, use _keep_cap variants and call cucon_umap_update_cap once afterwards.
References cucon_umap_erase_keep_cap().
| void* cucon_pmap_erase_ptr | ( | cucon_pmap_t | map, | |
| void const * | key | |||
| ) |
If key has a mapping in map, erase it and return the pointer value stored in the slot, else return NULL.
References cucon_umap_erase_ptr().
| int cucon_pmap_find_int | ( | cucon_pmap_t | map, | |
| void const * | key | |||
| ) |
If key is in map, return its mapping, else return INT_MIN.
References cucon_umap_find_int().
| void* cucon_pmap_find_mem | ( | cucon_pmap_t | map, | |
| void const * | key | |||
| ) |
If key has a mapping in map, return a pointer to the slot, else return NULL.
References cucon_umap_find_mem().
| cucon_pmap_node_t cucon_pmap_find_node | ( | cucon_pmap_t | map, | |
| void const * | key | |||
| ) |
Returns the internal node of key, or NULL if none.
References cucon_umap_find_node().
Referenced by cucon_pmap_find_void().
| void* cucon_pmap_find_ptr | ( | cucon_pmap_t | map, | |
| void const * | key | |||
| ) |
If key has a mapping in map, interpret the slot as a pointer and return it, else return NULL.
References cucon_umap_find_ptr().
| cu_bool_t cucon_pmap_find_void | ( | cucon_pmap_t | map, | |
| void const * | key | |||
| ) |
True iff map contains key, ignoring the slot.
References cucon_pmap_find_node().
| cu_hash_t cucon_pmap_hash_keys | ( | cucon_pmap_t | map | ) |
Returns a hash of the keys in map.
References cucon_umap_hash_keys().
| cu_hash_t cucon_pmap_hash_mem | ( | cucon_pmap_t | map, | |
| size_t | slot_size | |||
| ) |
Returns a hash of the keys and slots of map, assuming slots are slot_size bytes long.
References cucon_umap_hash_mem().
| cu_hash_t cucon_pmap_hash_ptr | ( | cucon_pmap_t | map | ) |
Returns a hash of the keys and slots of map, assuming the slots are pointers.
References cucon_umap_hash_ptr().
| void cucon_pmap_init | ( | cucon_pmap_t | map | ) |
Construct map as an empty property map.
References cucon_umap_init().
| void cucon_pmap_init_copy_mem | ( | cucon_pmap_t | dst, | |
| cucon_pmap_t | src, | |||
| size_t | slot_size | |||
| ) |
Construct dst as a copy of src assuming slots are slot_size bytes which can be copied with memcpy.
References cucon_umap_init_copy_mem().
| void cucon_pmap_init_copy_mem_ctor | ( | cucon_pmap_t | dst, | |
| cucon_pmap_t | src, | |||
| size_t | slot_size, | |||
| cu_clop(value_init_copy, void, void *dst_slot, void *src_slot,uintptr_t key) | ||||
| ) |
Copy src to dst, assuming all slots have the same size, where value_init_copy copies the value at src_slot to dst_slot.
References cucon_umap_init_copy_mem_ctor().
| void cucon_pmap_init_copy_node | ( | cucon_pmap_t | dst, | |
| cucon_pmap_t | src, | |||
| cu_clop(node_alloc_copy, cucon_pmap_node_t, void *, uintptr_t) | ||||
| ) |
Copy src to dst where src may have variable slot size. node_alloc_copy shall call cucon_umap_alloc to allocate some node, and construct a copy of src_slot at the location given by cucon_umap_node_get_mem(node).
References cu_clop, and cucon_umap_init_copy_node().
| void cucon_pmap_init_copy_void | ( | cucon_pmap_t | dst, | |
| cucon_pmap_t | src | |||
| ) |
Construct dst as a copy of src but dropping all value slots.
References cucon_umap_init_copy_void().
| cu_bool_t cucon_pmap_insert_general | ( | cucon_pmap_t | map, | |
| void const * | key, | |||
| cu_clop0(alloc_node, cucon_pmap_node_t) | , | |||
| cucon_pmap_node_t * | node_out | |||
| ) |
If key is not in map, insert a node allocated with alloc_node mapped from key and return true, else return false. In any case *node_out is set to the node of key. This function lets you embed a node in your own data structures. alloc_node must use garbage collection.
References cu_clop0, and cucon_umap_insert_general().
| cu_bool_t cucon_pmap_insert_init_node | ( | cucon_pmap_t | map, | |
| cucon_pmap_node_t | node | |||
| ) |
Insert node, which must be prepared with a key, into map.
References cucon_umap_insert_init_node().
| cu_bool_t cucon_pmap_insert_int | ( | cucon_pmap_t | map, | |
| void const * | key, | |||
| int | val | |||
| ) |
If key is not in map, map it to val and return true, else return false. If cucon_umap_find_int is used, then val should not be INT_MIN for the obvious reason. This is a shortcut equivalent to calling cucon_umap_insert_mem and initialising the slot with val.
References cucon_umap_insert_int().
| cu_bool_t cucon_pmap_insert_mem | ( | cucon_pmap_t | map, | |
| void const * | key, | |||
| size_t | slot_size, | |||
| cu_ptr_ptr_t | slot | |||
| ) |
If key has a mapping in map, set *slot to a pointer to the value and return false, else create a new mapping to slot_size bytes of assigned to *slot and return true. This the generic insert which supports arbitrary value types.
References cucon_umap_insert_mem().
| cu_bool_t cucon_pmap_insert_new_node | ( | cucon_pmap_t | map, | |
| void const * | key, | |||
| size_t | node_size, | |||
| cu_ptr_ptr_t | node_out | |||
| ) |
If key is not in map, this call allocates a node of size node_size, initialises a cucon_pmap_node from offset 0 with the key key, inserts the node into map, assigns it to *node_out, and returns true. Otherwise, returns false.
References cucon_umap_insert_new_node().
| cu_bool_t cucon_pmap_insert_ptr | ( | cucon_pmap_t | map, | |
| void const * | key, | |||
| void * | ptr | |||
| ) |
Insert (key, ptr) into map if it does not exist. Returns true iff the insertion was done. This is a shortcut equivalent to calling cucon_umap_insert_mem and initialising the slot with ptr.
References cucon_umap_insert_ptr().
| cu_bool_t cucon_pmap_insert_void | ( | cucon_pmap_t | map, | |
| void const * | key | |||
| ) |
Insert key into map unless it exists. Returns true iff the insertion was done.
References cucon_umap_insert_void().
| cu_bool_t cucon_pmap_is_empty | ( | cucon_pmap_t | map | ) |
True iff map is empty.
| void cucon_pmap_iter_keys | ( | cucon_pmap_t | map, | |
| cu_clop(cb, void, void const *) | ||||
| ) |
Call cb on each key in map.
Referenced by cucon_pset_iter().
| void cucon_pmap_iter_mem | ( | cucon_pmap_t | map, | |
| cu_clop(cb, void, void const *key, void *value) | ||||
| ) |
Call cb on each key-value pair in map.
| void cucon_pmap_iter_ptr | ( | cucon_pmap_t | map, | |
| cu_clop(cb, void, void const *key, void *value) | ||||
| ) |
Call cb on each key-value pair in map.
| void cucon_pmap_move_isecn | ( | cucon_pmap_t | dst, | |
| cucon_pmap_t | src0, | |||
| cucon_pmap_t | src1 | |||
| ) |
For each element in src0 ∩ src1, move one pair to dst and delete the other. It is unspecified which of the values from the sources are moved. If dst already contains the key, the elemets of both sources are simply discarded.
References cucon_umap_move_isecn().
| cucon_pmap_t cucon_pmap_new | ( | void | ) |
Return an empty property map.
References cucon_umap_new().
| cucon_pmap_t cucon_pmap_new_copy_mem | ( | cucon_pmap_t | src, | |
| size_t | slot_size | |||
| ) |
Return a copy of src assuming slots are slot_size bytes which can be copied with memcpy.
References cucon_umap_new_copy_mem().
| cucon_pmap_t cucon_pmap_new_copy_void | ( | cucon_pmap_t | src | ) |
Return a copy of src after dropping all value slots.
References cucon_umap_new_copy_void().
| void const* cucon_pmap_pop_any_key | ( | cucon_pmap_t | map | ) |
As cucon_umap_pop_any_node, but return key instead of node.
References cucon_umap_pop_any_key().
| cucon_pmap_node_t cucon_pmap_pop_any_node | ( | cucon_pmap_t | map | ) |
Erase any element of map and return the erased node. This uses a random number generator to prevent compromising the average case structure of map.
References cucon_umap_pop_any_node().
| int cucon_pmap_replace_int | ( | cucon_pmap_t | map, | |
| void const * | key, | |||
| int | val | |||
| ) |
If key has a mapping in map, replace it with val and return the old mapping, else insert val and return INT_MIN. As a special case, if val is INT_MIN, erase the mapping of key and return the old value or INT_MIN of none.
int. References cucon_umap_replace_int().
| void* cucon_pmap_replace_ptr | ( | cucon_pmap_t | map, | |
| void const * | key, | |||
| void * | ptr | |||
| ) |
If key is bound in map, assume it is bound to a pointer, replace the poiter with ptr and return the old pointer, else bind key to ptr and return NULL.
References cucon_umap_replace_ptr().
| size_t cucon_pmap_size | ( | cucon_pmap_t | map | ) |
Return the number of elements in map.
| void cucon_pmap_swap | ( | cucon_pmap_t | map0, | |
| cucon_pmap_t | map1 | |||
| ) |
Swap the contents of map0 with map1.
References cucon_umap_swap().
| void cucon_pmap_update_cap | ( | cucon_pmap_t | map | ) |
Update capacity after _keep_cap calls.
References cucon_umap_update_cap().