aboutsummaryrefslogtreecommitdiff
path: root/doc/Manual/en/BH_Hashmap.pod
blob: 1688a2a2432efab07115b14cf42085dd3920767c (plain)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
=encoding UTF-8


=head1 NAME

BH_Hashmap - unordered associative array


=head1 SYNTAX

 #include <BH/Hashmap.h>
 
 cc prog.c -o prog -lbh


=head1 DESCRIPTION

The BH_Hashmap library provides an implementation of an unordered associative 
array based on a hash table. It allows you to store and retrieve data by key 
efficiently.


=head1 API CALLS


=head2 BH_HashmapNew

 BH_Hashmap *BH_HashmapNew(BH_EqualCallback equal,
                           BH_HashCallback hash);

Creates an associative array.

The I<equal> parameter takes a pointer to a function that compares two elements.

The I<hash> parameter takes a pointer to a function that calculates the hash
value of an element.

If successful, the function returns a pointer to a new BH_Hashmap object or NULL
in case of an error.


=head2 BH_HashmapFree

 void BH_HashmapFree(BH_Hashmap *hashmap);

Destroys the associative array.


=head2 BH_HashmapClear

 void BH_HashmapClear(BH_Hashmap *hashmap);

Clears the associative array.


=head2 BH_HashmapReserve

 int BH_HashmapReserve(BH_Hashmap *hashmap,
                       size_t size);

Reserves space for at least I<size> elements.

Calling this function invalidates existing iterators.

If successful, the function returns 0; otherwise, it returns an error code.


=head2 BH_HashmapInsert

 int BH_HashmapInsert(BH_Hashmap *hashmap,
                      void *key,
                      void *value);

Inserts an element represented by the key-value pair I<key> and I<value>.

The function allows inserting multiple elements with the same key value.

Calling this function invalidates existing iterators.

If successful, the function returns 0; otherwise, it returns an error code.


=head2 BH_HashmapRemove

 void BH_HashmapRemove(BH_Hashmap *hashmap,
                       void *key);

Removes the element with the given key value I<key>.

If the associative array contains multiple elements with the same key value, the
function will remove only one key-value pair.

Calling this function invalidates existing iterators.


=head2 BH_HashmapAt

 int BH_HashmapAt(BH_Hashmap *hashmap,
                  void *key,
                  void **value);

Checks if there is an element with the given key I<key>.

The optional I<value> parameter returns the value of the element with the given
key.

If successful, the function returns 0; otherwise, it returns an error code.


=head2 BH_HashmapEmpty

 int BH_HashmapEmpty(BH_Hashmap *hashmap);

Checks if the associative array is empty.


=head2 BH_HashmapSize

 size_t BH_HashmapSize(BH_Hashmap *hashmap);

Returns the number of elements.


=head2 BH_HashmapCapacity

 size_t BH_HashmapCapacity(BH_Hashmap *hashmap);

Returns the capacity.


=head2 BH_HashmapFactor

 float BH_HashmapFactor(BH_Hashmap *hashmap);

Returns the maximum load factor.


=head2 BH_HashmapSetFactor

 void BH_HashmapSetFactor(BH_Hashmap *hashmap,
                          float factor);

Sets the maximum load factor I<factor>.

The new value of the maximum load factor will be applied on the next call to 
L</BH_HashmapInsert> or L</BH_HashmapReserve>.


=head2 BH_HashmapIterAt

 void *BH_HashmapIterAt(BH_Hashmap *hashmap,
                        void *key);

Returns an iterator to the element with the given key I<key>.

If successful, the function returns an iterator or NULL.


=head2 BH_HashmapIterNext

 void *BH_HashmapIterNext(BH_Hashmap *hashmap,
                          void *iter);

Returns an iterator to the next element.

The optional I<iter> parameter takes an iterator to the current element.

If successful, the function returns an iterator or NULL.


=head2 BH_HashmapIterRemove

 void BH_HashmapIterRemove(BH_Hashmap *hashmap,
                           void *iter);

Removes the element by the given iterator I<iter>.

Calling this function invalidates existing iterators.


=head2 BH_HashmapIterKey

 void *BH_HashmapIterKey(void *iter);

Returns the key of the element pointed to by the iterator I<iter>.


=head2 BH_HashmapIterValue

 void *BH_HashmapIterValue(void *iter);

Returns the value of the element pointed to by the iterator I<iter>.


=head1 SEE ALSO

L<BH>