Hashtable update

- use consistent type for key by introducing a new typedef
- use unsigned types for sizes
- name parameters in foreach function typedef
This commit is contained in:
Christian Göttsche
2020-10-21 21:25:59 +02:00
committed by BenBE
parent 15eab2012d
commit 7914ec201e
5 changed files with 31 additions and 29 deletions

View File

@ -10,36 +10,38 @@ in the source distribution for its full text.
#include <stdbool.h>
typedef void(*Hashtable_PairFunction)(int, void*, void*);
typedef unsigned int hkey_t;
typedef struct HashtableItem {
unsigned int key;
typedef void(*Hashtable_PairFunction)(hkey_t key, void* value, void* userdata);
typedef struct HashtableItem_ {
hkey_t key;
void* value;
struct HashtableItem* next;
struct HashtableItem_* next;
} HashtableItem;
typedef struct Hashtable_ {
int size;
unsigned int size;
HashtableItem** buckets;
int items;
unsigned int items;
bool owner;
} Hashtable;
#ifndef NDEBUG
int Hashtable_count(Hashtable* this);
unsigned int Hashtable_count(const Hashtable* this);
#endif /* NDEBUG */
Hashtable* Hashtable_new(int size, bool owner);
Hashtable* Hashtable_new(unsigned int size, bool owner);
void Hashtable_delete(Hashtable* this);
void Hashtable_put(Hashtable* this, unsigned int key, void* value);
void Hashtable_put(Hashtable* this, hkey_t key, void* value);
void* Hashtable_remove(Hashtable* this, unsigned int key);
void* Hashtable_remove(Hashtable* this, hkey_t key);
void* Hashtable_get(Hashtable* this, unsigned int key);
void* Hashtable_get(Hashtable* this, hkey_t key);
void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData);