rpm  5.4.14
Macros | Typedefs | Functions
rpmhash.h File Reference

Hash table implemenation. More...

#include <rpmiotypes.h>
Include dependency graph for rpmhash.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define htUnlink(_ht)   ((hashTable)rpmioUnlinkPoolItem((rpmioItem)(_ht), __FUNCTION__, __FILE__, __LINE__))
 
#define htLink(_ht)   ((hashTable)rpmioLinkPoolItem((rpmioItem)(_ht), __FUNCTION__, __FILE__, __LINE__))
 
#define htFree(_ht)   ((hashTable)rpmioFreePoolItem((rpmioItem)(_ht), __FUNCTION__, __FILE__, __LINE__))
 

Typedefs

typedef struct hashTable_shashTable
 
typedef int(* hashEqualityType )(const void *key1, const void *key2)
 Compare two hash table entries for equality. More...
 
typedef rpmuint32_t(* hashFunctionType )(rpmuint32_t h, const void *data, size_t size)
 Return hash value. More...
 

Functions

int hashEqualityString (const void *key1, const void *key2)
 Compare two hash table entries for equality. More...
 
rpmuint32_t hashFunctionString (rpmuint32_t h, const void *data, size_t size)
 Return hash value of a string. More...
 
void htAddEntry (hashTable ht, const void *key, const void *data)
 Add item to hash table. More...
 
int htGetEntry (hashTable ht, const void *key, const void *data, int *dataCount, const void *tableKey)
 Retrieve item from hash table. More...
 
const void ** htGetKeys (hashTable ht)
 Retrieve keys from hash table. More...
 
int htHasEntry (hashTable ht, const void *key)
 Check for key in hash table. More...
 
hashTable htUnlink (hashTable ht)
 Unreference a hash table instance. More...
 
hashTable htLink (hashTable ht)
 Reference a hash table instance. More...
 
hashTable htFree (hashTable ht)
 Destroy hash table. More...
 
hashTable htCreate (int numBuckets, size_t keySize, int freeData, hashFunctionType fn, hashEqualityType eq)
 Create hash table. More...
 

Detailed Description

Hash table implemenation.

Definition in file rpmhash.h.

Macro Definition Documentation

#define htFree (   _ht)    ((hashTable)rpmioFreePoolItem((rpmioItem)(_ht), __FUNCTION__, __FILE__, __LINE__))

Definition at line 131 of file rpmhash.h.

#define htLink (   _ht)    ((hashTable)rpmioLinkPoolItem((rpmioItem)(_ht), __FUNCTION__, __FILE__, __LINE__))

Definition at line 120 of file rpmhash.h.

#define htUnlink (   _ht)    ((hashTable)rpmioUnlinkPoolItem((rpmioItem)(_ht), __FUNCTION__, __FILE__, __LINE__))

Definition at line 109 of file rpmhash.h.

Typedef Documentation

typedef int(* hashEqualityType)(const void *key1, const void *key2)

Compare two hash table entries for equality.

Parameters
key1entry 1
key2entry 2
Returns
0 if entries are equal

Definition at line 25 of file rpmhash.h.

typedef rpmuint32_t(* hashFunctionType)(rpmuint32_t h, const void *data, size_t size)

Return hash value.

Parameters
hhash initial value
datadata on which to calculate hash value
sizesize of data in bytes
Returns
hash value

Definition at line 44 of file rpmhash.h.

typedef struct hashTable_s* hashTable

Definition at line 13 of file rpmhash.h.

Function Documentation

int hashEqualityString ( const void key1,
const void key2 
)

Compare two hash table entries for equality.

Parameters
key1entry 1
key2entry 2
Returns
0 if entries are equal

Definition at line 76 of file rpmhash.c.

References strcmp().

Referenced by htCreate().

rpmuint32_t hashFunctionString ( rpmuint32_t  h,
const void data,
size_t  size 
)

Return hash value of a string.

Parameters
hhash initial value
datadata on which to calculate hash value
sizesize of data in bytes (0 will use strlen(data))
Returns
hash value

Definition at line 83 of file rpmhash.c.

References h, and key.

Referenced by Fstat(), ftpLstat(), ftpStat(), genCpioListAndHeader(), htCreate(), rpmmiGrowBasename(), rpmtsCheckInstalledFiles(), and rpmxarStat().

void htAddEntry ( hashTable  ht,
const void key,
const void data 
)

Add item to hash table.

Parameters
htpointer to hash table
keypointer to key
datapointer to data value

Definition at line 150 of file rpmhash.c.

References b, hashTable_s::buckets, hashBucket_s::data, hashBucket_s::dataCount, hashTable_s::eq, hashTable_s::fn, if(), k, hashBucket_s::key, key, hashTable_s::keySize, hashBucket_s::next, NULL, hashTable_s::numBuckets, xmalloc, and xrealloc.

Referenced by doLookup(), fpLookupSubdir(), and rpmtsAddFingerprints().

hashTable htCreate ( int  numBuckets,
size_t  keySize,
int  freeData,
hashFunctionType  fn,
hashEqualityType  eq 
)

Create hash table.

If keySize > 0, the key is duplicated within the table (which costs memory, but may be useful anyway.

Parameters
numBucketsnumber of hash buckets
keySizesize of key (0 if unknown)
freeDataShould data be freed when table is destroyed?
fnfunction to generate hash key (NULL for default)
eqfunction to compare keys for equality (NULL for default)
Returns
pointer to initialized hash table

Definition at line 277 of file rpmhash.c.

References hashTable_s::buckets, hashTable_s::eq, hashTable_s::fn, hashTable_s::freeData, hashEqualityString(), hashFunctionString(), htGetPool(), htLink(), hashTable_s::keySize, NULL, hashTable_s::numBuckets, and xcalloc().

Referenced by fpCacheCreate(), rpmtsAddFingerprints(), and rpmtsPrepare().

hashTable htFree ( hashTable  ht)

Destroy hash table.

Parameters
htpointer to hash table
Returns
NULL on last dereference

Referenced by fpCacheFree(), rpmtsAddFingerprints(), and rpmtsPrepare().

int htGetEntry ( hashTable  ht,
const void key,
const void data,
int dataCount,
const void tableKey 
)

Retrieve item from hash table.

Parameters
htpointer to hash table
keypointer to key value
Return values
*datadata value from bucket
*dataCountdata value size from bucket
*tableKeykey value from bucket (may be NULL)
Returns
0 on success, 1 if the item is not found.

Definition at line 188 of file rpmhash.c.

References b, hashBucket_s::data, hashBucket_s::dataCount, findEntry(), hashBucket_s::key, and NULL.

Referenced by cacheContainsDirectory(), fpLookupSubdir(), handleOverlappedFiles(), and rpmtsCheckInstalledFiles().

const void** htGetKeys ( hashTable  ht)

Retrieve keys from hash table.

Parameters
htpointer to hash table
Returns
array of key values terminated by a NULL pointer

Definition at line 206 of file rpmhash.c.

References b, hashTable_s::buckets, hashBucket_s::data, i, hashBucket_s::key, keys, n, hashBucket_s::next, NULL, hashTable_s::numBuckets, and xcalloc().

int htHasEntry ( hashTable  ht,
const void key 
)

Check for key in hash table.

Parameters
htpointer to hash table
keypointer to key value
Returns
1 if the key is present, 0 otherwise

Definition at line 181 of file rpmhash.c.

References b, and findEntry().

hashTable htLink ( hashTable  ht)

Reference a hash table instance.

Parameters
hthash table
Returns
new hash table reference

Referenced by htCreate().

hashTable htUnlink ( hashTable  ht)

Unreference a hash table instance.

Parameters
hthash table
Returns
NULL on last dereference