hash_set.h
Go to the documentation of this file.
1 /*
2  Copyright 2010 SINTEF ICT, Applied Mathematics.
3 
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM 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  OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef OPM_HASH_SET_HEADER_INCLUDED
21 #define OPM_HASH_SET_HEADER_INCLUDED
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #include <stddef.h>
28 
29 
30 /* ---------------------------------------------------------------------- */
31 /* Poor-man's unordered set (ind. key insert/all key extract only). */
32 /* ---------------------------------------------------------------------- */
33 struct hash_set {
34  size_t m; /* Table/set capacity (1<<p for some p) */
35  int *s; /* Set representation */
36 };
37 
38 
39 /* ---------------------------------------------------------------------- */
40 /* Release dynamic memory resources for hash set 's'. */
41 /* ---------------------------------------------------------------------- */
42 void
43 hash_set_deallocate(struct hash_set *s);
44 
45 
46 /* ---------------------------------------------------------------------- */
47 /* Construct an emtpy hash set capable of holding 'm' elements */
48 /* ---------------------------------------------------------------------- */
49 struct hash_set *
50 hash_set_allocate(int m);
51 
52 
53 /* ---------------------------------------------------------------------- */
54 /* Insert element 'k' into hash set 's'. */
55 /* ---------------------------------------------------------------------- */
56 int
57 hash_set_insert(int k, struct hash_set *s);
58 
59 
60 /* ---------------------------------------------------------------------- */
61 /* Count number of valid keys in a hash set. */
62 /* ---------------------------------------------------------------------- */
63 size_t
64 hash_set_count_elms(const struct hash_set *set);
65 
66 #ifdef __cplusplus
67 }
68 #endif
69 
70 #endif /* OPM_HASH_SET_HEADER_INCLUDED */
Definition: hash_set.h:33
size_t hash_set_count_elms(const struct hash_set *set)
struct hash_set * hash_set_allocate(int m)
int * s
Definition: hash_set.h:35
int hash_set_insert(int k, struct hash_set *s)
void hash_set_deallocate(struct hash_set *s)
size_t m
Definition: hash_set.h:34