CHashTable 1
Loading...
Searching...
No Matches
hash_table_utils.c File Reference

Internal utility functions for HashTable. More...

#include <stdio.h>
#include <assert.h>
#include <limits.h>
#include "hash_table_internal.h"
Include dependency graph for hash_table_utils.c:

Functions

size_t hash_function (int key, size_t table_size)
 Hash function using division method.
 
bool is_prime (size_t n)
 Is prime function.
 
size_t next_prime (size_t n)
 Finds the next prime number after n.
 

Detailed Description

Internal utility functions for HashTable.

Function Documentation

◆ hash_function()

size_t hash_function ( int  key,
size_t  table_size 
)

Hash function using division method.

The hash is hash = key % table_size. The hash is always positive.

Parameters
keyKey to hash
table_sizeHash table size
Returns
Hashed key

◆ is_prime()

bool is_prime ( size_t  n)

Is prime function.

Using an optimized trial division method with the 6k ± 1 rule

◆ next_prime()

size_t next_prime ( size_t  n)

Finds the next prime number after n.

Uses the is_prime() function.

Parameters
nThe prime is searched after n
Returns
Prime number