|
Packit |
da78c2 |
/*
|
|
Packit |
da78c2 |
* hashtable.h
|
|
Packit |
da78c2 |
* header file for really simple hash table implementation
|
|
Packit |
da78c2 |
*
|
|
Packit |
da78c2 |
* Copyright (c) 2011-2016 Nikias Bassen, All Rights Reserved.
|
|
Packit |
da78c2 |
*
|
|
Packit |
da78c2 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
da78c2 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
da78c2 |
* License as published by the Free Software Foundation; either
|
|
Packit |
da78c2 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
da78c2 |
*
|
|
Packit |
da78c2 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
da78c2 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
da78c2 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
da78c2 |
* Lesser General Public License for more details.
|
|
Packit |
da78c2 |
*
|
|
Packit |
da78c2 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
da78c2 |
* License along with this library; if not, write to the Free Software
|
|
Packit |
da78c2 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
da78c2 |
*/
|
|
Packit |
da78c2 |
#ifndef HASHTABLE_H
|
|
Packit |
da78c2 |
#define HASHTABLE_H
|
|
Packit |
da78c2 |
#include <stdlib.h>
|
|
Packit |
da78c2 |
|
|
Packit |
da78c2 |
typedef struct hashentry_t {
|
|
Packit |
da78c2 |
void *key;
|
|
Packit |
da78c2 |
void *value;
|
|
Packit |
da78c2 |
void *next;
|
|
Packit |
da78c2 |
} hashentry_t;
|
|
Packit |
da78c2 |
|
|
Packit |
da78c2 |
typedef unsigned int(*hash_func_t)(const void* key);
|
|
Packit |
da78c2 |
typedef int (*compare_func_t)(const void *a, const void *b);
|
|
Packit |
da78c2 |
typedef void (*free_func_t)(void *ptr);
|
|
Packit |
da78c2 |
|
|
Packit |
da78c2 |
typedef struct hashtable_t {
|
|
Packit |
da78c2 |
hashentry_t *entries[4096];
|
|
Packit |
da78c2 |
size_t count;
|
|
Packit |
da78c2 |
hash_func_t hash_func;
|
|
Packit |
da78c2 |
compare_func_t compare_func;
|
|
Packit |
da78c2 |
free_func_t free_func;
|
|
Packit |
da78c2 |
} hashtable_t;
|
|
Packit |
da78c2 |
|
|
Packit |
da78c2 |
hashtable_t* hash_table_new(hash_func_t hash_func, compare_func_t compare_func, free_func_t free_func);
|
|
Packit |
da78c2 |
void hash_table_destroy(hashtable_t *ht);
|
|
Packit |
da78c2 |
|
|
Packit |
da78c2 |
void hash_table_insert(hashtable_t* ht, void *key, void *value);
|
|
Packit |
da78c2 |
void* hash_table_lookup(hashtable_t* ht, void *key);
|
|
Packit |
da78c2 |
void hash_table_remove(hashtable_t* ht, void *key);
|
|
Packit |
da78c2 |
|
|
Packit |
da78c2 |
#endif
|