hmap_init (&map);
or, alternatively:
struct hmap map = HMAP_INITIALIZER (map);
-
+
Each node in the hash table, presumably a structure type, must
include a struct hmap_node member. Here's an example:
struct foo
/* Returns the hash value associated with NODE. */
static inline size_t
-hmap_node_hash (const struct hmap_node *node)
+hmap_node_hash (const struct hmap_node *node)
{
return node->hash;
}
interface to this particular function that is often more
convenient. */
static inline struct hmap_node *
-hmap_next_with_hash (const struct hmap_node *node)
+hmap_next_with_hash (const struct hmap_node *node)
{
return hmap_find_hash__ (node->next, node->hash);
}
then the client must check for duplicates itself before
inserting the new node. */
static inline void
-hmap_insert_fast (struct hmap *map, struct hmap_node *node, size_t hash)
+hmap_insert_fast (struct hmap *map, struct hmap_node *node, size_t hash)
{
struct hmap_node **bucket = &map->buckets[hash & map->mask];
node->hash = hash;
The HMAP_FIRST macro is an interface to this particular
function that is often more convenient. */
static inline struct hmap_node *
-hmap_first (const struct hmap *map)
+hmap_first (const struct hmap *map)
{
return hmap_first_nonempty_bucket__ (map, 0);
}
The HMAP_NEXT macro is an interface to this particular
function that is often more convenient. */
static inline struct hmap_node *
-hmap_next (const struct hmap *map, const struct hmap_node *node)
+hmap_next (const struct hmap *map, const struct hmap_node *node)
{
return (node->next != NULL
? node->next
/* Returns the number of data items currently in MAP. */
static inline size_t
-hmap_count (const struct hmap *map)
+hmap_count (const struct hmap *map)
{
return map->count;
}
capacity. However, inserting many more elements than the
map's capacity will degrade search performance. */
static inline size_t
-hmap_capacity (const struct hmap *map)
+hmap_capacity (const struct hmap *map)
{
return hmap_mask_to_capacity__ (map->mask);
}
/* Returns the first node at or after NODE in NODE's chain that
has hash value HASH. */
static inline struct hmap_node *
-hmap_find_hash__ (struct hmap_node *node, size_t hash)
+hmap_find_hash__ (struct hmap_node *node, size_t hash)
{
- for (; node != NULL; node = node->next)
+ for (; node != NULL; node = node->next)
if (node->hash == hash)
break;
return node;
MASK must be a power of 2 minus 1 (including 0), that is, its
value in binary must be all 1-bits. */
static inline size_t
-hmap_mask_to_capacity__ (size_t mask)
+hmap_mask_to_capacity__ (size_t mask)
{
return (mask + 1) * 2;
}
argument more than once). */
static inline void *
hmap_nullable_data__ (struct hmap_node *node, size_t member_offset)
-{
+{
return node != NULL ? (char *) node - member_offset : NULL;
}