TaPAS  0.2
ccl-hash.h
Go to the documentation of this file.
1 /*
2  * ccl-hash.h -- generic hash table
3  *
4  * This file is a part of the C Common Library (CCL) project.
5  *
6  * Copyright (C) 2010 CNRS UMR 5800 & Université Bordeaux I (see AUTHORS file).
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the AltaRica Public License that comes with this
10  * package.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  */
16 
45 #ifndef __CCL_HASH_H__
46 # define __CCL_HASH_H__
47 
48 # include <ccl/ccl-common.h>
49 # include <ccl/ccl-protos.h>
50 # include <ccl/ccl-iterator.h>
51 
52 BEGIN_C_DECLS
53 
57 typedef struct ccl_hash_st ccl_hash;
58 
59 typedef struct ccl_hash_methods_st {
60  ccl_hash_func *hash;
61  ccl_compare_func *compare;
62  ccl_delete_proc *del;
63 } ccl_hash_methods;
64 
68 typedef struct ccl_hash_entry_st ccl_hash_entry;
69 struct ccl_hash_entry_st {
70  void *key;
71  void *object;
72 };
73 
78 CCL_ITERATOR_TYPEDEF (ccl_hash_entry_iterator, ccl_hash_entry);
79 
88 extern ccl_hash *
89 ccl_hash_create (ccl_hash_func *key_hash, ccl_compare_func *key_compare,
90  ccl_delete_proc *key_delete, ccl_delete_proc *object_delete);
91 
92 extern ccl_hash *
93 ccl_hash_create_methods_struct (const ccl_hash_methods *methods,
94  ccl_delete_proc *object_delete);
95 
96 extern const ccl_hash_methods *
97 ccl_hash_get_methods (const ccl_hash *ht);
98 
99 extern void
100 ccl_hash_enable_pool (ccl_hash *ht, const char *poolname, int nb_elements);
101 
112 extern void
114 
126 extern int
127 ccl_hash_find (ccl_hash *ht, void *key);
128 
129 extern int
130 ccl_hash_has (const ccl_hash *ht, const void *key);
131 
141 extern void *
142 ccl_hash_get (ccl_hash *ht);
143 
144 extern void *
145 ccl_hash_get_with_key (const ccl_hash * ht, const void * key);
146 
160 extern void
161 ccl_hash_insert (ccl_hash *ht, void *object);
162 
175 extern void
177 
184 extern int
185 ccl_hash_get_size (const ccl_hash *ht);
186 
195 extern ccl_pointer_iterator *
196 ccl_hash_get_keys (const ccl_hash *ht);
197 
206 extern ccl_pointer_iterator *
207 ccl_hash_get_elements (const ccl_hash *ht);
208 
217 extern ccl_hash_entry_iterator *
218 ccl_hash_get_entries (const ccl_hash *ht);
219 
220 END_C_DECLS
221 
222 #endif /* ! __CCL_HASH_H__ */
ccl_hash * ccl_hash_create(ccl_hash_func *key_hash, ccl_compare_func *key_compare, ccl_delete_proc *key_delete, ccl_delete_proc *object_delete)
Creates a new hash table.
void ccl_hash_insert(ccl_hash *ht, void *object)
Inserts at the cursor position the object.
void ccl_hash_remove(ccl_hash *ht)
Removes the object at the cursor position.
int ccl_hash_find(ccl_hash *ht, void *key)
Looks for key in the table ht.
Frequently used prototypes of generic functions.
A generic iterator interface.
void * ccl_hash_get(ccl_hash *ht)
Returns the object of the entry pointed by the cursor.
int ccl_compare_func(const void *ptr1, const void *ptr2)
Prototype of functions used to order two objects pointed respectively by ptr1 and ptr2...
Definition: ccl-protos.h:73
void ccl_hash_delete(ccl_hash *ht)
Deletes the table ht.
#define CCL_ITERATOR_TYPEDEF(_typename_, _eltype_)
Macro-function used to define and declare a new iterator type.
Definition: ccl-iterator.h:43
void ccl_delete_proc(void *ptr)
Prototype of procedures used to release the resources allocated to the object pointed by ptr...
Definition: ccl-protos.h:44
Some useful and common macros.
ccl_pointer_iterator * ccl_hash_get_keys(const ccl_hash *ht)
Builds an iterator over keys of ht.
ccl_pointer_iterator * ccl_hash_get_elements(const ccl_hash *ht)
Builds an iterator over objects stored in ht.
struct ccl_hash_entry_st ccl_hash_entry
Entries of the table that are returned by ad-hoc iterator.
Definition: ccl-hash.h:68
int ccl_hash_get_size(const ccl_hash *ht)
Returns the number of elements in the table.
ccl_hash_entry_iterator * ccl_hash_get_entries(const ccl_hash *ht)
Builds an iterator over entries of ht.
struct ccl_hash_st ccl_hash
abstract type of an hash table.
Definition: ccl-hash.h:57
unsigned int ccl_hash_func(const void *ptr)
Prototype of functions used to compute a hashed value from an abstract object pointed by ptr...
Definition: ccl-protos.h:32