D-Bus 1.14.10
Data Structures | Macros | Typedefs | Functions
Hash table implementation details

DBusHashTable implementation details. More...

Data Structures

struct  DBusHashEntry
 Internal representation of a hash entry. More...
 
struct  DBusHashTable
 Internals of DBusHashTable. More...
 
struct  DBusRealHashIter
 Internals of DBusHashIter. More...
 

Macros

#define REBUILD_MULTIPLIER   3
 When there are this many entries per bucket, on average, rebuild the hash table to make it larger. More...
 
#define RANDOM_INDEX(table, i)    (((((intptr_t) (i))*1103515245) >> (table)->down_shift) & (table)->mask)
 Takes a preliminary integer hash value and produces an index into a hash tables bucket list. More...
 
#define DBUS_SMALL_HASH_TABLE   4
 Initial number of buckets in hash table (hash table statically allocates its buckets for this size and below). More...
 

Typedefs

typedef struct DBusHashEntry DBusHashEntry
 Typedef for DBusHashEntry. More...
 
typedef DBusHashEntry *(* DBusFindEntryFunction) (DBusHashTable *table, void *key, dbus_bool_t create_if_not_found, DBusHashEntry ***bucket, DBusPreallocatedHash *preallocated)
 Function used to find and optionally create a hash entry. More...
 

Functions

 _DBUS_STATIC_ASSERT (sizeof(DBusRealHashIter)==sizeof(DBusHashIter))
 

Detailed Description

DBusHashTable implementation details.

The guts of DBusHashTable.

Macro Definition Documentation

◆ DBUS_SMALL_HASH_TABLE

#define DBUS_SMALL_HASH_TABLE   4

Initial number of buckets in hash table (hash table statically allocates its buckets for this size and below).

The initial mask has to be synced to this.

Definition at line 136 of file dbus-hash.c.

◆ RANDOM_INDEX

#define RANDOM_INDEX (   table,
 
)     (((((intptr_t) (i))*1103515245) >> (table)->down_shift) & (table)->mask)

Takes a preliminary integer hash value and produces an index into a hash tables bucket list.

The idea is to make it so that preliminary values that are arbitrarily similar will end up in different buckets. The hash function was taken from a random-number generator. (This is used to hash integers.)

The down_shift drops off the high bits of the hash index, and decreases as we increase the number of hash buckets (to keep more range in the hash index). The mask also strips high bits and strips fewer high bits as the number of hash buckets increases. I don't understand two things: why is the initial downshift 28 to keep 4 bits when the initial mask is 011 to keep 2 bits, and why do we have both a mask and a downshift?

Definition at line 128 of file dbus-hash.c.

◆ REBUILD_MULTIPLIER

#define REBUILD_MULTIPLIER   3

When there are this many entries per bucket, on average, rebuild the hash table to make it larger.

Definition at line 110 of file dbus-hash.c.

Typedef Documentation

◆ DBusFindEntryFunction

typedef DBusHashEntry *(* DBusFindEntryFunction) (DBusHashTable *table, void *key, dbus_bool_t create_if_not_found, DBusHashEntry ***bucket, DBusPreallocatedHash *preallocated)

Function used to find and optionally create a hash entry.

Definition at line 162 of file dbus-hash.c.

◆ DBusHashEntry

typedef struct DBusHashEntry DBusHashEntry

Typedef for DBusHashEntry.

Definition at line 141 of file dbus-hash.c.