CHashTable 1
Loading...
Searching...
No Matches
hash_table_internal.h
Go to the documentation of this file.
1
6#ifndef CHASHTABLE_HASH_TABLE_INTERNAL_H
7#define CHASHTABLE_HASH_TABLE_INTERNAL_H
8
9#include <stddef.h>
10#include "hash_table.h"
11
13constexpr size_t HT_INITIAL_SIZE = 53;
15constexpr double HT_LOAD_THRESHOLD = 0.75;
16
21struct hash_table {
23 size_t size;
24 size_t count;
26};
27
37size_t calc_load_threshold_count(size_t size);
38
44HashTable *hash_table_create_with_size(size_t size);
45
51Entry **create_buckets(size_t size);
52
58void clear_buckets(Entry **buckets, size_t size);
59
71void hash_table_resize(HashTable *table);
72
82size_t hash_function(int key, size_t table_size);
83
88bool is_prime(size_t n);
89
98size_t next_prime(size_t n);
99
100#endif //CHASHTABLE_HASH_TABLE_INTERNAL_H
Public API for HashTable.
constexpr size_t HT_INITIAL_SIZE
Initial hash table size, always a prime number.
Definition hash_table_internal.h:13
size_t calc_load_threshold_count(size_t size)
Precalculates the load threshold count.
Definition hash_table_resize.c:62
bool is_prime(size_t n)
Is prime function.
Definition hash_table_utils.c:22
Entry ** create_buckets(size_t size)
Creates a dynamically allocated bucket array with a set size.
Definition hash_table_resize.c:12
constexpr double HT_LOAD_THRESHOLD
The hash table grows if the count/size ratio exceeds this threshold.
Definition hash_table_internal.h:15
void clear_buckets(Entry **buckets, size_t size)
Frees all entries inside a bucket array.
Definition hash_table_resize.c:46
void hash_table_resize(HashTable *table)
Resizes the HashTable.
Definition hash_table_resize.c:66
size_t next_prime(size_t n)
Finds the next prime number after n.
Definition hash_table_utils.c:39
size_t hash_function(int key, size_t table_size)
Hash function using division method.
Definition hash_table_utils.c:12
HashTable * hash_table_create_with_size(size_t size)
Creates a new dynamically allocated HashTable object with a set size.
Definition hash_table_resize.c:24
A hash table entry object.
Definition hash_table.h:20
Definition hash_table_internal.h:21
size_t count
Definition hash_table_internal.h:24
Entry ** buckets
Definition hash_table_internal.h:22
size_t load_threshold_count
Definition hash_table_internal.h:25
size_t size
Definition hash_table_internal.h:23