-
Notifications
You must be signed in to change notification settings - Fork 2
/
genhash.h
58 lines (48 loc) · 1.88 KB
/
genhash.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
tdiff - tree diffs
Prototypes for a generic hash.
Copyright (C) 1999, 2014, 2019 Philippe Troin <phil+github-commits@fifi.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GENHASH_H
#define GENHASH_H
#include "config.h"
#include <sys/types.h>
/* Generic hash types */
typedef struct genhash_s genhash_t;
#if SIZEOF_SHORT==SIZEOF_VOID_P
typedef unsigned short hashval_t;
#elif SIZEOF_INT==SIZEOF_VOID_P
typedef unsigned int hashval_t;
#elif SIZEOF_LONG==SIZEOF_VOID_P
typedef unsigned long hashval_t;
#elif SIZEOF_LONG_LONG==SIZEOF_VOID_P
typedef unsigned long long hashval_t;
#else
# error Cannot find pointer-sized integral type !
#endif
/* Generic hash interface */
genhash_t* gh_new(hashval_t(*)(const void*),
int(*)(const void*, const void*),
void (*)(void*),
void (*)(void*));
int gh_insert(genhash_t*, void*, void*);
int gh_find(const genhash_t*, const void*, void**);
void gh_delete(genhash_t* gh);
void gh_stats(const genhash_t *gh, const char* name);
/* Hash and equality functions for strings, identify */
hashval_t gh_string_hash(const void*);
hashval_t gh_binary_hash(const void*, size_t);
hashval_t gh_identity_hash(const void*);
int gh_string_equal(const void*, const void*);
int gh_identity_equal(const void*, const void*);
#endif /* ndef GENHASH_H */