Archived
1
0
Fork 0
This repository has been archived on 2026-05-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
dlight/hash.h
Henrik Hautakoski 223706d52f hash: Replace struct with a primitive type for hash values.
Remove the struct hash_entry and define a new type for hash values.
Most likely we will only need one member in this struct. and instead
of just using unsinged int. let's name a new type for clarity.
2012-08-22 15:42:20 +02:00

51 lines
1.4 KiB
C

/* hash.h
*
* Copyright (C) 2011-2012 Henrik Hautakoski <henrik@fiktivkod.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#ifndef HASH_H
#define HASH_H
#include <stddef.h>
typedef unsigned int hash_t;
struct hash_table {
hash_t **ptr;
unsigned size;
unsigned count;
};
#define HASH_TABLE_INIT { NULL, 0, 0 }
#define hash_entry(t, i) \
((void*) *((char**) (t)->ptr + (i)))
/* general hash functions */
hash_t hash_sdbm(const char *s);
void hash_init(struct hash_table *table);
void hash_free(struct hash_table *table);
void* hash_lookup(const struct hash_table *t, hash_t hash);
void* hash_insert(struct hash_table *t, hash_t hash, void *ptr);
void* hash_remove(struct hash_table *t, hash_t hash);
#endif /* HASH_H */