libosmocore 1.13.1.1-afb4 Osmocom core library

Macros | Functions
hashtable.h File Reference
`#include <osmocom/core/linuxlist.h>`
`#include <osmocom/core/hash.h>`

Go to the source code of this file.

## Macros
#define | DEFINE_HASHTABLE(name, bits)
#define | DECLARE_HASHTABLE(name, bits) struct hlist_head name[1 << (bits)]
#define | HASH_SIZE(name) (ARRAY_SIZE(name))
#define | HASH_BITS(name) ilog2(HASH_SIZE(name))
#define | hash_min(val, bits) (sizeof(val) <= 4 ? hash_32(val, bits) : hash_long(val, bits))
#define | hash_init(hashtable) __hash_init(hashtable, HASH_SIZE(hashtable))
| hash_init - initialize a hash table @hashtable: hashtable to be initialized More...
#define | hash_add(hashtable, node, key) hlist_add_head(node, &hashtable[hash_min(key, HASH_BITS(hashtable))])
| hash_add - add an object to a hashtable @hashtable: hashtable to add to @node: the &struct hlist_node of the object to be added @key: the key of the object to be added More...
#define | hash_empty(hashtable) __hash_empty(hashtable, HASH_SIZE(hashtable))
| hash_empty - check whether a hashtable is empty @hashtable: hashtable to check More...
: hashtable to iterate
hash_for_each_possible_safe - iterate over all possible objects hashing to the same bucket safe against removals @obj: the type * to use as a loop cursor for each entry @tmp: a &struct hlist_node used for temporary storage @member: the name of the hlist_node within the struct @key: the key of the objects to iterate over
#define | hash_for_each(name, bkt, obj, member)
#define | hash_for_each_safe(name, bkt, tmp, obj, member)
#define | hash_for_each_possible(name, obj, member, key) hlist_for_each_entry(obj, &name[hash_min(key, HASH_BITS(name))], member)
#define | hash_for_each_possible_safe(name, obj, tmp, member, key)

## Functions
static void | __hash_init (struct hlist_head *ht, unsigned int sz)
static bool | hash_hashed (struct hlist_node *node)
| hash_hashed - check whether an object is in any hashtable @node: the &struct hlist_node of the object to be checked More...
static bool | __hash_empty (struct hlist_head *ht, unsigned int sz)
static void | hash_del (struct hlist_node *node)
| hash_del - remove an object from a hashtable @node: &struct hlist_node of the object to remove More...

## Macro Definition Documentation

## ◆ DECLARE_HASHTABLE

#define DECLARE_HASHTABLE | ( |  | name,
|  |  | bits
| ) |  | struct hlist_head name[1 << (bits)]

## ◆ DEFINE_HASHTABLE

#define DEFINE_HASHTABLE | ( |  | name,
|  |  | bits
| ) |  |

Value:
struct hlist_head name[1 << (bits)] = \
{ [0 ... ((1 << (bits)) - 1)] = HLIST_HEAD_INIT }
name
const char * name
HLIST_HEAD_INIT
#define HLIST_HEAD_INIT
Definition: linuxlist.h:428
hlist_head
Double linked lists with a single pointer list head.
Definition: linuxlist.h:420

## ◆ hash_add

#define hash_add | ( |  | hashtable,
|  |  | node,
|  |  | key
| ) |  | hlist_add_head(node, &hashtable[hash_min(key, HASH_BITS(hashtable))])

hash_add - add an object to a hashtable @hashtable: hashtable to add to @node: the &struct hlist_node of the object to be added @key: the key of the object to be added

## ◆ HASH_BITS

#define HASH_BITS | ( |  | name | ) | ilog2(HASH_SIZE(name))

## ◆ hash_empty

#define hash_empty | ( |  | hashtable | ) | __hash_empty(hashtable, HASH_SIZE(hashtable))

hash_empty - check whether a hashtable is empty @hashtable: hashtable to check

This has to be a macro since HASH_BITS() will not work on pointers since it calculates the size during preprocessing.

## ◆ hash_for_each

#define hash_for_each | ( |  | name,
|  |  | bkt,
|  |  | obj,
|  |  | member
| ) |  |

Value:
for ((bkt) = 0, obj = NULL; obj == NULL && (bkt) < HASH_SIZE(name);\
(bkt)++)\
hlist_for_each_entry(obj, &name[bkt], member)
HASH_SIZE
#define HASH_SIZE(name)
Definition: hashtable.h:19

## ◆ hash_for_each_possible

#define hash_for_each_possible | ( |  | name,
|  |  | obj,
|  |  | member,
|  |  | key
| ) |  | hlist_for_each_entry(obj, &name[hash_min(key, HASH_BITS(name))], member)

## ◆ hash_for_each_possible_safe

#define hash_for_each_possible_safe | ( |  | name,
|  |  | obj,
|  |  | tmp,
|  |  | member,
|  |  | key
| ) |  |

Value:
hlist_for_each_entry_safe(obj, tmp,\
&name[hash_min(key, HASH_BITS(name))], member)
hlist_for_each_entry_safe
#define hlist_for_each_entry_safe(pos, n, head, member)
hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry.
Definition: linuxlist.h:652
hash_min
#define hash_min(val, bits)
Definition: hashtable.h:23
HASH_BITS
#define HASH_BITS(name)
Definition: hashtable.h:20

## ◆ hash_for_each_safe

#define hash_for_each_safe | ( |  | name,
|  |  | bkt,
|  |  | tmp,
|  |  | obj,
|  |  | member
| ) |  |

Value:
for ((bkt) = 0, obj = NULL; obj == NULL && (bkt) < HASH_SIZE(name);\
(bkt)++)\
hlist_for_each_entry_safe(obj, tmp, &name[bkt], member)

## ◆ hash_init

#define hash_init | ( |  | hashtable | ) | __hash_init(hashtable, HASH_SIZE(hashtable))

hash_init - initialize a hash table @hashtable: hashtable to be initialized

Calculates the size of the hashtable from the given parameter, otherwise same as hash_init_size.

This has to be a macro since HASH_BITS() will not work on pointers since it calculates the size during preprocessing.

## ◆ hash_min

#define hash_min | ( |  | val,
|  |  | bits
| ) |  | (sizeof(val) <= 4 ? hash_32(val, bits) : hash_long(val, bits))

## ◆ HASH_SIZE

#define HASH_SIZE | ( |  | name | ) | (ARRAY_SIZE(name))

## Function Documentation

## ◆ __hash_empty()

static bool __hash_empty | ( | struct hlist_head * | ht,
|  | unsigned int | sz
| ) |  |
| inline static

References hlist_empty().

## ◆ __hash_init()

static void __hash_init | ( | struct hlist_head * | ht,
|  | unsigned int | sz
| ) |  |
| inline static

References INIT_HLIST_HEAD.

## ◆ hash_del()

static void hash_del | ( | struct hlist_node * | node | ) |
| inline static

hash_del - remove an object from a hashtable @node: &struct hlist_node of the object to remove

References hlist_del_init(), and node.

## ◆ hash_hashed()

static bool hash_hashed | ( | struct hlist_node * | node | ) |
| inline static

hash_hashed - check whether an object is in any hashtable @node: the &struct hlist_node of the object to be checked

References hlist_unhashed(), and node.