Cyclone Scheme  0.28.0
hashset.h
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * Copyright 2012 Couchbase, Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef HASHSET_H
19 #define HASHSET_H 1
20 
21 #include <stdlib.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27  struct hashset_st {
28  size_t nbits;
29  size_t mask;
30 
31  size_t capacity;
32  size_t *items;
33  size_t nitems;
35  };
36 
37  typedef struct hashset_st *hashset_t;
38 
39  /* create hashset instance */
41 
42  /* destroy hashset instance */
43  void hashset_destroy(hashset_t set);
44 
45  size_t hashset_num_items(hashset_t set);
46 
47  /* add item into the hashset.
48  *
49  * @note 0 and 1 is special values, meaning nil and deleted items. the
50  * function will return -1 indicating error.
51  *
52  * returns zero if the item already in the set and non-zero otherwise
53  */
54  int hashset_add(hashset_t set, void *item);
55 
56  /* remove item from the hashset
57  *
58  * returns non-zero if the item was removed and zero if the item wasn't
59  * exist
60  */
61  int hashset_remove(hashset_t set, void *item);
62 
63  /* check if existence of the item
64  *
65  * returns non-zero if the item exists and zero otherwise
66  */
67  int hashset_is_member(hashset_t set, void *item);
68 
69  void hashset_to_array(hashset_t set, void **items);
70 
71 #ifdef __cplusplus
72 }
73 #endif
74 
75 #endif
hashset_st::nbits
size_t nbits
Definition: hashset.h:28
hashset_is_member
int hashset_is_member(hashset_t set, void *item)
Definition: hashset.c:132
hashset_st::n_deleted_items
size_t n_deleted_items
Definition: hashset.h:34
hashset_st::nitems
size_t nitems
Definition: hashset.h:33
hashset_st::mask
size_t mask
Definition: hashset.h:29
hashset_t
struct hashset_st * hashset_t
Definition: hashset.h:37
hashset_st::capacity
size_t capacity
Definition: hashset.h:31
hashset_destroy
void hashset_destroy(hashset_t set)
Definition: hashset.c:49
hashset_st
Definition: hashset.h:27
hashset_st::items
size_t * items
Definition: hashset.h:32
hashset_create
hashset_t hashset_create(void)
Definition: hashset.c:24
hashset_to_array
void hashset_to_array(hashset_t set, void **items)
Definition: hashset.c:147
hashset_num_items
size_t hashset_num_items(hashset_t set)
Definition: hashset.c:44
hashset_remove
int hashset_remove(hashset_t set, void *item)
Definition: hashset.c:114
hashset_add
int hashset_add(hashset_t set, void *item)
Definition: hashset.c:107