Data Structures Lerax  v3.0-101-gb1f7
Opinionated Data Structures & Algorithms
Loading...
Searching...
No Matches
hash-table.h File Reference
#include <stddef.h>
#include <stdbool.h>
#include "../list/single/list.h"
#include "../iterator/iterator.h"

Go to the source code of this file.

Typedefs

typedef struct HashTable HashTable
 A basic implementation of a hash table.

Functions

HashTablehash_table_create (size_t n_buckets)
 Create a new hash table instance.
bool hash_table_empty (HashTable *ht)
 Check if hash table is empty.
HashTablehash_table_copy (HashTable *ht)
 Create a hash table as copy of another.
void hash_table_put (HashTable *ht, int key, int value)
 Put a value associated to a key.
void hash_table_remove (HashTable *ht, int key)
 Remove a specific value associated with a given key.
int hash_table_get (HashTable *ht, int key, bool *exists)
 Get a value in the hash table.
size_t hash_table_size (HashTable *ht)
 Get the number of elements in the hash table.
void hash_table_print (HashTable *ht)
 Print all buckets of the hash table (one list per line)
void hash_table_print_items (HashTable *ht)
 Print items of the hash table.
void hash_table_print_keys (HashTable *ht)
 Print keys of the hash table.
Listhash_table_keys (HashTable *ht)
 Build a list with the hash table keys.
Iteratorhash_table_iterator_keys (HashTable *ht)
Iteratorhash_table_iterator_data (HashTable *ht)
void hash_table_free (HashTable *ht)
 Free memory of hash table and its contents.

Typedef Documentation

◆ HashTable

typedef struct HashTable HashTable

A basic implementation of a hash table.


    Copyright 2025 Manoel Vilela

    Author: Manoel Vilela
   Contact: manoel_vilela@engineer.com

Organization: ITA


This implementation uses a separate chaining strategy to handle collisions. The hash table is composed of an array of buckets, where each bucket is a linked list of key-value pairs.

Function Documentation

◆ hash_table_iterator_data()

Iterator * hash_table_iterator_data ( HashTable * ht)

◆ hash_table_iterator_keys()

Iterator * hash_table_iterator_keys ( HashTable * ht)