Typedefs | Functions

rpmio/rpmhash.h File Reference

Hash table implemenation. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

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

Functions

hashTable htCreate (int numBuckets, size_t keySize, int freeData, hashFunctionType fn, hashEqualityType eq)
 Create hash table.
hashTable htFree (hashTable ht)
 Destroy hash table.
void htAddEntry (hashTable ht, const void *key, const void *data)
 Add item to hash table.
int htGetEntry (hashTable ht, const void *key, const void *data, int *dataCount, const void *tableKey)
 Retrieve item from hash table.
int htHasEntry (hashTable ht, const void *key)
 Check for key in hash table.

Detailed Description

Hash table implemenation.

Definition in 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 33 of file rpmhash.h.

typedef uint32_t(* hashFunctionType)(uint32_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 24 of file rpmhash.h.

typedef struct hashTable_s* hashTable

Definition at line 11 of file rpmhash.h.


Function Documentation

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 177 of file rpmhash.c.

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

Referenced by doLookup(), and rpmtsRun().

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 159 of file rpmhash.c.

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

Referenced by fpCacheCreate(), and rpmtsRun().

hashTable htFree ( hashTable  ht )

Destroy hash table.

Parameters:
htpointer to hash table
Returns:
NULL always

Definition at line 207 of file rpmhash.c.

References _free(), hashTable_s::buckets, hashBucket_s::data, hashTable_s::freeData, hashBucket_s::key, hashTable_s::keySize, hashBucket_s::next, and hashTable_s::numBuckets.

Referenced by fpCacheFree(), and rpmtsRun().

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 242 of file rpmhash.c.

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

Referenced by cacheContainsDirectory(), and handleOverlappedFiles().

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 235 of file rpmhash.c.

References findEntry().