su 1.12.11devel
Loading...
Searching...
No Matches
Macros
htable2.h File Reference

Hash tables templates, take 2. More...

Go to the source code of this file.

Macros

#define HTABLE2_H
 Defined when <sofia-sip/htable2.h> has been included.
 
#define HTABLE2_MIN_SIZE
 Minimum size of hash table.
 
#define HTABLE2_DECLARE2(type, sname, pr, entrytype, sizetype)
 Declare hash table structure type.
 
#define HTABLE2_SCOPE
 Default scope for hash table functions.
 
#define HTABLE2_PROTOS2(type, prefix, pr, entrytype, sizetype)
 Prototypes for hash table.
 
#define HTABLE2_BODIES2(type, prefix, pr, entrytype, sizetype, hfun, is_used, reclaim, is_equal, halloc)
 Hash table implementation.
 

Detailed Description

Hash tables templates, take 2.

Note: this version stores the given element types as entries (instead of always storing a pointer to element). It can be used without <sofia-sip/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_DECLARE2(). The prototypes for hashing functions are instantiated with macro HTABLE2_PROTOS2(). The implementation is instantiated with macro HTABLE2_BODIES2().

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_BODIES2() would then be something like macro

#define ENTRY_HASH(e) ((e).e_hash_value)

When a entry with new identical 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.nosp@m..Pes.nosp@m.si@no.nosp@m.kia..nosp@m.com.
Date
Created: Tue Sep 25 17:42:40 2001 ppessi

Macro Definition Documentation

◆ HTABLE2_BODIES2

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

Hash table implementation.

The macro HTABLE2_BODIES2() 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
typehash table type
prefixfunction prefix for hash table
prfield prefix for hash table
entrytypetype of entry element
sizetypesize_t type
hfunfunction or macro returning hash value of entry
is_usedfunction or macro returning true if entry is occupied
reclaimfunction or macro zeroing entry
is_equalequality test
hallocfunction allocating or freeing memory
Since
New in 1.12.8

◆ HTABLE2_DECLARE2

#define HTABLE2_DECLARE2 (   type,
  sname,
  pr,
  entrytype,
  sizetype 
)

Declare hash table structure type.

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

Parameters
typehash table typedef
snamename of struct
prhash table field prefix
entrytypeentry type
sizetypetype of size variables
Since
New in 1.12.8

◆ HTABLE2_PROTOS2

#define HTABLE2_PROTOS2 (   type,
  prefix,
  pr,
  entrytype,
  sizetype 
)

Prototypes for hash table.

The macro HTABLE2_PROTOS2() 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
typehash table typedef
prefixfunction prefix
prhash table field prefix (not used)
entrytypeentry type
sizetypetype of size variables
Since
New in 1.12.8

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