Repository navigation
Expand file tree
/
Copy pathhash-table.h
More file actions
129 lines (110 loc) · 3.32 KB
/
Copy pathhash-table.h
File metadata and controls
129 lines (110 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* ================================================
*
* Copyright 2025 Manoel Vilela
*
* Author: Manoel Vilela
* Contact: manoel_vilela@engineer.com
* Organization: ITA
*
* ===============================================
*/
#ifndef HASH_TABLE_H
#define HASH_TABLE_H
#include <stddef.h>
#include <stdbool.h>
#include "../list/single/list.h"
#include "../iterator/iterator.h"
/**
* @brief A basic implementation of a hash table.
*
* 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.
*/
typedef struct HashTable HashTable;
/**
* @brief Create a new hash table instance
* @param n_buckets number of buckets in the hash table
* @return pointer to the newly created hash table
* @ingroup DataStructureMethods
*/
HashTable* hash_table_create(size_t n_buckets);
/**
* @brief Check if hash table is empty
* @param ht hash table pointer
* @return true if empty, false otherwise
* @ingroup DataStructureMethods
*/
bool hash_table_empty(HashTable *ht);
/**
* @brief Create a hash table as copy of another
* @param ht hash table to copy
* @return pointer to the newly created hash table
* @ingroup DataStructureMethods
*/
HashTable* hash_table_copy(HashTable *ht);
/**
* @brief Put a value associated to a key
* @param ht hash table pointer
* @param key integer key used to determine the bucket
* @param value integer value to store
* @ingroup DataStructureMethods
*/
void hash_table_put(HashTable *ht, int key, int value);
/**
* @brief Remove a specific value associated with a given key
* @param ht hash table pointer
* @param key integer key used to locate the bucket
* @ingroup DataStructureMethods
*/
void hash_table_remove(HashTable *ht, int key);
/**
* @brief Get a value in the hash table
* @param ht hash table pointer
* @param key integer key used to locate the bucket
* @param exists bool pointer, set true if found false otherwise; null pointer does nothing
* @ingroup DataStructureMethods
*/
int hash_table_get(HashTable *ht, int key, bool *exists);
/**
* @brief Get the number of elements in the hash table
* @param ht hash table pointer
* @return the number of elements inside of the hash table
* @ingroup DataStructureMethods
*/
size_t hash_table_size(HashTable *ht);
/**
* @brief Print all buckets of the hash table (one list per line)
* @param ht hash table pointer
* @ingroup DataStructureMethods
*/
void hash_table_print(HashTable *ht);
/**
* @brief Print items of the hash table
* @param ht hash table pointer
* @ingroup DataStructureMethods
*/
void hash_table_print_items(HashTable *ht);
/**
* @brief Print keys of the hash table
* @param ht hash table pointer
* @ingroup DataStructureMethods
*/
void hash_table_print_keys(HashTable *ht);
/**
* @brief Build a list with the hash table keys
* @param ht hash table pointer
* @ingroup DataStructureMethods
*/
List* hash_table_keys(HashTable *ht);
Iterator* hash_table_iterator_keys(HashTable *ht);
Iterator* hash_table_iterator_data(HashTable *ht);
Iterator* hash_table_iterator_items(HashTable *ht);
/**
* @brief Free memory of hash table and its contents
* @param ht hash table pointer
* @ingroup DataStructureMethods
*/
void hash_table_free(HashTable *ht);
#endif /* HASH_TABLE_H */