sofia-sip/htable2.h File Reference


Detailed Description

Hash tables templates, take 2.

Note: this version can handle structures as entries, and it can be used without <su_alloc.h>.

This file contain a hash table template for C. The hash tables are resizeable, and they usually contain pointers to entries. The declaration for template datatypes is instantiated with macro HTABLE2_DECLARE(). The prototypes for hashing functions are instantiated with macro HTABLE2_PROTOS(). The implementation is instantiated with macro HTABLE2_BODIES().

The hash table template is most efficient when the hash value is precalculated and stored in each entry. The hash "function" given to the HTABLE2_BODIES() would then be something like macro

 #define HTABLE2_ENTRY_HASH(e) ((e).e_hash_value)

When a entry with new identical hash key is added to the table, it can be either inserted (before any other entry with same key value) or appended.

Example code can be found from <htable_test.c>.

Author:
Pekka Pessi <Pekka.Pessi@nokia-email.address.hidden>.
Date:
Created: Tue Sep 25 17:42:40 2001 ppessi

Go to the source code of this file.

Defines

#define HTABLE2_MIN_SIZE
 Minimum size of hash table.
#define HTABLE2_DECLARE(sname, prefix, pr, entrytype)
 Declare hash table structure type.
#define HTABLE2_SCOPE
 Default scope for hash table functions.
#define HTABLE2_PROTOS(type, prefix, pr, entrytype)
 Prototypes for hash table.
#define HTABLE2_BODIES(type, prefix, pr, entrytype,hfun, is_used, reclaim, is_equal, halloc)
 Hash table implementation.


Define Documentation

#define HTABLE2_BODIES ( type,
prefix,
pr,
entrytype,
hfun,
is_used,
reclaim,
is_equal,
halloc   ) 

Hash table implementation.

The macro HTABLE2_BODIES() expands the hash table functions. The function and type names start with prefix, the field names start with pr. The entry type is entrytype. The function (or macro) name returning hash value of each entry is given as hfun.

Parameters:
type hash table type
prefix function prefix for hash table
pr field prefix for hash table
entrytype type of entry element
hfun function or macro returning hash value of entry
is_used function or macro returning true if entry is occupied
reclaim function or macro zeroing entry
is_equal equality test
halloc function allocating or freeing memory

#define HTABLE2_DECLARE ( sname,
prefix,
pr,
entrytype   ) 

Declare hash table structure type.

The macro HTABLE2_DECLARE() expands to a declaration for hash table structure. The its typedef will be prefix_t, the field names start with pr. The entry type is entrytype.

Parameters:
sname name of struct
prefix hash table type and function prefix
pr hash table field prefix
entrytype entry type

#define HTABLE2_PROTOS ( type,
prefix,
pr,
entrytype   ) 

Prototypes for hash table.

The macro HTABLE2_PROTOS() expands to the prototypes of hash table functions. The function and type names start with prefix, the field names start with pr. The entry type is entrytype.

Parameters:
type hash table typedef
prefix function prefix
pr hash table field prefix
entrytype entry type


Sofia-SIP 1.12.1 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.