- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

# rpmdb/rpmhash.h File Reference

Hash table implemenation. More...

Go to the source code of this file.

## Typedefs
typedef hashTable_s * | hashTable
typedef unsigned int(*) | hashFunctionType (const void *string)
typedef int(*) | hashEqualityType (const void *key1, const void *key2)
## Functions
unsigned int | hashFunctionString (const void *string)
| Return hash value of a string.
int | hashEqualityString (const void *key1, const void *key2)
| Compare two hash table entries for equality.
hashTable | htCreate (int numBuckets, int keySize, int freeData, hashFunctionType fn, hashEqualityType eq)
| Create hash table.
void | 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)

Definition at line 24 of file rpmhash.h.

typedef unsigned int(*) hashFunctionType(const void *string)

Definition at line 19 of file rpmhash.h.

typedef struct hashTable_s* hashTable

Definition at line 11 of file rpmhash.h.

## Function Documentation

int hashEqualityString | ( | const void * | key1,
|  | const void * | key2 |
| ) |  |  |

Compare two hash table entries for equality.

Parameters:

  | key1 | entry 1
  | key2 | entry 2

Returns:
  0 if entries are equal

Definition at line 59 of file rpmhash.c.

Referenced by fpCacheCreate().

unsigned int hashFunctionString | ( | const void * | string | ) |

Return hash value of a string.

Parameters:

  | string | string on which to calculate hash value

Returns:
  hash value

Definition at line 66 of file rpmhash.c.

Referenced by fpCacheCreate().

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

Add item to hash table.

Parameters:

  | ht | pointer to hash table
  | key | pointer to key
  | data | pointer to data value

Definition at line 101 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 rpmRunTransactions().

hashTable htCreate | ( | int | numBuckets,
|  | int | 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:

  | numBuckets | number of hash buckets
  | keySize | size of key (0 if unknown)
  | freeData | Should data be freed when table is destroyed?
  | fn | function to generate hash value for key
  | eq | function to compare hash keys for equality

Returns:
  pointer to initialized hash table

Definition at line 83 of file rpmhash.c.

References xcalloc(), and xmalloc().

Referenced by fpCacheCreate(), and rpmRunTransactions().

void htFree | ( | hashTable | ht | ) |

Destroy hash table.

Parameters:

  | ht | pointer to hash table

Definition at line 133 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().

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

Retrieve item from hash table.

Parameters:

  | ht | pointer to hash table
  | key | pointer to key value

Return values:

  | data | address to store data value from bucket
  | dataCount | address to store data value size from bucket
  | tableKey | address to store key value from bucket (may be NULL)

Returns:
  0 on success, 1 if the item is not found.

Definition at line 169 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:

  | ht | pointer to hash table
  | key | pointer to key value

Returns:
  1 if the key is present, 0 otherwise

Definition at line 162 of file rpmhash.c.

References findEntry().