-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashMap.h
More file actions
72 lines (54 loc) · 1.4 KB
/
hashMap.h
File metadata and controls
72 lines (54 loc) · 1.4 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
//
// Created by JakoError on 2020/12/26.
//
#pragma once
#ifndef COMPILESTUDY_HASHMAP_H
#define COMPILESTUDY_HASHMAP_H
#include <stdbool.h>
typedef char *String;
#define KEY_TYPE String
#define VALUE_TYPE int**
#define DEFAULT_MAP_LENGTH 100
typedef struct hashmap *HashMap;
typedef struct node *HashNode;
typedef struct {
KEY_TYPE key;
VALUE_TYPE value;
} DataType;
struct node {
DataType data;
HashNode next;
};
struct hashmap {
int size;
struct node map[DEFAULT_MAP_LENGTH];
};
/**
* 乘法hash算法,乘数为31(jdk8)
* @param key --it should be string
* @return hashcode of string-->abs
*/
int hash(char key[]);
/**
* creat hashmap with existing keys and values
* if key and value are null, the map will be empty
* we allow keys or values are null
*
* when size is out of bound we have no idea to control it in C
* @param keys format as string(i use strlen to do it)
* @param values
* @param size it is important to deal with size
* @return hashmap
*/
HashMap createHashMap(KEY_TYPE keys[], VALUE_TYPE*values, int size);
//---增
bool putData(HashMap hm, KEY_TYPE key, VALUE_TYPE value);
bool putAllData(HashMap hm, KEY_TYPE key[], VALUE_TYPE value[], int size);
//---删
bool delete(HashMap hm, KEY_TYPE key);
//--查
VALUE_TYPE*getValue(HashMap hm, KEY_TYPE key);
DataType *getAllData(HashMap hm);
void clear(HashMap hm);
void freeHashMap(HashMap);
#endif //COMPILESTUDY_HASHMAP_H