-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmap.h
43 lines (30 loc) · 1.12 KB
/
cmap.h
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
//
// map.h
// cmap
//
// Created by Timothy Quang-Tin Le on 8/19/18.
// Copyright © 2018 Timothy Quang-Tin Le. All rights reserved.
//
#ifndef map_h
#define map_h
#include <stdio.h>
#include <stdbool.h>
#define MAP_NUM_BUCKETS 16 //based on default setting in Java
//https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html
typedef struct map_elem map_elem;
typedef struct map Map;
Map *map_init();
//If a string is the map or key, include +1 for the null terminator in the size
void map_put(Map *map, const void *key, const void *val,
size_t key_sz, size_t val_sz);
const void *map_get(Map *map, const void *key, size_t key_sz);
void map_remove(Map *map, const void *key, size_t key_sz);
void map_free(Map *map);
size_t map_num_elems(Map *map);
//prints the distribution of the buckets of the map
//this allows testing the distribution from the hash function
void map_print_distrib(Map *map);
//should only call if all keys and vals in map are strs or ints
//"true" for all strs and "false" for all ints
void map_print_str_int_elems(Map *map, bool all_strs);
#endif /* map_h */