2
Copyright (C) 2008 Kai Hertel
4
This file is part of mmpong.
6
mmpong is free software: you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
11
mmpong is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with mmpong. If not, see <http://www.gnu.org/licenses/>.
20
#ifndef __HASHMAP_HEADER__
21
#define __HASHMAP_HEADER__
23
// Quick drive-by instructions on how to use this mapping scheme:
24
// * create map of desired size (I will spare you the introduction to stochastics here)
25
// * after that, you can begin to insert (key, value) pairs into the map, look them up, work on the values in store and remove them easily
26
// * functions to provide:
27
// -- int map(int hashmap_size, void *key); // this one is supposed to map any given key to a number in [ 0 ; hashmap_size-1 ]
28
// -- int cmp(void *key_to_be_found, void *key_in_store); // this one needs to recognize a key when iterating through possible candidates (e.g. strcmp, memcmp)
37
struct hashentry *table;
41
struct hashmap *hashmap_create(unsigned, const struct hashmap *, unsigned (*)(const unsigned, const void *));
42
void hashmap_destroy(struct hashmap *);
43
void **hashmap_lookup(struct hashmap *, const void *, unsigned (*)(const unsigned, const void *), int (*)(const void *, const void *));
44
int hashmap_insert(struct hashmap *, void *, void *, unsigned (*)(const unsigned, const void *), int (*)(const void *, const void *));
45
int hashmap_remove(struct hashmap *, const void *, unsigned (*)(const unsigned, const void *), int (*)(const void *, const void *));
46
//unsigned hashmap_fast_inc(struct hashmap *, unsigned, int, unsigned (*)(unsigned, void *)); // special operation to speed up server accesses