LibRCG  3.1.1
hashmap.h
Go to the documentation of this file.
1 
56 #ifndef _HASHMAP_H_
57 #define _HASHMAP_H_
58 
59 #include "iterator.h"
60 
64 typedef struct sHashNode
65 {
67  void* key;
69  void* value;
71  struct sHashNode* next;
72 }SHashNode;
73 
78 
82 typedef struct sHashMap
83 {
85  int(*hash)(void*);
87  int(*equals)(void*,void*);
89  int size;
91  int length;
93  float factor;
96 }SHashMap;
97 
101 typedef SHashMap* HashMap;
102 
103 //==============================================================================
104 
122 HashMap newHash(int size,float factor
123  ,int(*hash)(void*)
124  ,int(*equals)(void*,void*)
125  );
126 
137 int hashSetHash(HashMap hmap,int(*hash)(void*));
138 
149 int hashSetEquals(HashMap hmap,int(*equals)(void*,void*));
150 
163 int hashSetFactor(HashMap hmap,int factor);
164 
174 void hashDelete(HashMap hmap);
175 
193 int hashInsert(HashMap hmap,void* key,void* value,int replace);
194 
216 int hashRemove(HashMap hmap,void* key,void** value,void(*del)(void*));
217 
239 int hashGet(HashMap hmap,void* key,void** value);
240 
249 int hashSize(HashMap hmap);
250 
263 
276 
277 #endif
int hashSetHash(HashMap hmap, int(*hash)(void *))
Sets the hash function of a hash table.
Definition: hashmap.c:80
void hashDelete(HashMap hmap)
Deletes a hash table.
Definition: hashmap.c:110
int hashInsert(HashMap hmap, void *key, void *value, int replace)
Associates a value to a key in a hash table.
Definition: hashmap.c:129
int hashSize(HashMap hmap)
Returns the number of elements present in a hash table.
Definition: hashmap.c:211
void * value
Node's value.
Definition: hashmap.h:69
void * key
Node's key.
Definition: hashmap.h:67
int hashGet(HashMap hmap, void *key, void **value)
Provides the mapping for a key from a hash table.
Definition: hashmap.c:193
Iterator hashValues(HashMap hmap)
Creates an iterator from the values of a hash table.
Definition: hashmap.c:239
int hashSetFactor(HashMap hmap, int factor)
Sets the load factor of a hash table.
Definition: hashmap.c:100
float factor
Load factor.
Definition: hashmap.h:93
Iterator structure.
Definition: iterator.h:17
struct sHashNode * next
Next node.
Definition: hashmap.h:71
HashNode * elems
Buckets of this hash table.
Definition: hashmap.h:95
int length
Number of buckets of this hash table.
Definition: hashmap.h:91
SHashNode * HashNode
Hash table node definition.
Definition: hashmap.h:77
Hash table structure.
Definition: hashmap.h:82
Iterator hashKeys(HashMap hmap)
Creates an iterator from the keys of a hash table.
Definition: hashmap.c:218
SHashMap * HashMap
Hash table definition.
Definition: hashmap.h:101
int size
Number of elements of this hash table.
Definition: hashmap.h:89
HashMap newHash(int size, float factor, int(*hash)(void *), int(*equals)(void *, void *))
Creates a hash table.
Definition: hashmap.c:52
Hash table node structure.
Definition: hashmap.h:64
Implementation of an iterator.
int hashSetEquals(HashMap hmap, int(*equals)(void *, void *))
Sets the comparison function of a hash table.
Definition: hashmap.c:90
int hashRemove(HashMap hmap, void *key, void **value, void(*del)(void *))
Removes the mapping for a key from a hash table.
Definition: hashmap.c:167

LibRCG © 2004-2015   Rui Carlos Gonçalves