blob: 09d6d4a0d2ed39d986962f602e5c7e986ea29984 (
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
|
#include <stdlib.h>
typedef struct cell{
int val;
int key;
struct cell* next;
} Cell;
typedef struct hashMap{
int size;
struct cell** map;
} HashMap;
void mapInsert(HashMap* map, int val){
map->map[g(val)] = val;
}
int mapLen(HashMap* map){
int len = 0;
for (int i = 0; i < map->size; i++){
Cell* v = map->map[i];
while (v){
len++;
v = v->next;
}
}
return len;
}
void mapDel(HashMap* map, int val){
Cell* f = map->map[g(val)];
Cell* v = f;
Cell* b;
while (v && v->val != val){
b = v;
v = v->next;
}
if (v->val != val) return;
if (!b){
f = v->next;
} else {
b = v->next;
}
free(v);
}
|