~ubuntu-branches/ubuntu/oneiric/mmpong/oneiric

« back to all changes in this revision

Viewing changes to server/hashmap.h

  • Committer: Bazaar Package Importer
  • Author(s): André Gaul
  • Date: 2009-01-09 16:39:01 UTC
  • Revision ID: james.westby@ubuntu.com-20090109163901-3k701q6yxwailed7
Tags: upstream-0.9
Import upstream version 0.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
  Copyright (C) 2008 Kai Hertel
 
3
 
 
4
        This file is part of mmpong.
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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/>.
 
18
*/
 
19
 
 
20
#ifndef __HASHMAP_HEADER__
 
21
#define __HASHMAP_HEADER__
 
22
 
 
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)
 
29
 
 
30
struct hashentry {
 
31
        void **keys;
 
32
        void **vals;
 
33
        unsigned size;
 
34
};
 
35
 
 
36
struct hashmap {
 
37
        struct hashentry *table;
 
38
        unsigned size;
 
39
};
 
40
 
 
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
 
47
 
 
48
#endif
 
49