libosmocore 1.9.0.192-1c24
Osmocom core library
hashtable.h File Reference

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 }
const char * name
#define HLIST_HEAD_INIT
Definition: linuxlist.h:418
Double linked lists with a single pointer list head.
Definition: linuxlist.h:410

◆ 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)
#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:
&name[hash_min(key, HASH_BITS(name))], member)
#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:642
#define hash_min(val, bits)
Definition: hashtable.h:23
#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 
)
inlinestatic

References hlist_empty().

◆ __hash_init()

static void __hash_init ( struct hlist_head ht,
unsigned int  sz 
)
inlinestatic

References INIT_HLIST_HEAD.

◆ hash_del()

static void hash_del ( struct hlist_node node)
inlinestatic

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)
inlinestatic

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.