Skip to content

georghegel/chashtable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Logo

chashtable

C Hash Table is a simple implementation of a hash table for C.
Here's the list of functions:

Name Description
ht_create() Creates empty hash table
ht_delete() Deletes existing table
ht_get() Gets value of a given key
ht_set() Sets/creates key-value pair
ht_length() Returns length of a hash table
f1nva_hash() F1NVa hashing algorithm
gxhash() GxHash hashing algorithm

Contents

Installation and Usage

git clone https://github.com/georghegel/chashtable.git
cd chashtable
make hashtable.a
# Next steps depends on your project.
# For project with main.c:
gcc main.c hashtable.a -o myprogram

Testing

needs to be implemented

Hash tables

Hash functions

There is a lot of hash functions: cyclic redundancy checks, checksums, universal hash function families, non-cryptographic hash functions, keyed/unkeyed cryptographic hash functions.

FNV1a hash

[Wikipedia Article]
Key concepts:
FNV Prime: 1099511628211 (for 64-bit, unsigned integer)
FNV offset basis: 14695981039346656037 (for 64-bit, unsigned integer)
XOR and MUL operations As simple as this code:

uint64_t fnv1a_hash(const char* key) {
  uint64_t hash = FNV_offset_basis;
  for (const char* p = key; *p; p++) {
    hash ^= (uint64_t)(unsigned char)(*p);
    hash *= FNV_prime;
  }
  return hash;
}

GxHash

needs to be implemented

TODOs

  1. Tests
  2. Performance tests
  3. GxHash hashing algorithm

About

Missed Hash Table in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published