Reworked and cleaned the khash; completely removed the new_hash_table

implementation that was buggy, not very flexible, and incomplete.
Changed some variable types, and function names.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2110 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2002-11-29 08:25:08 +00:00
parent 717eabde1f
commit ebf5be407a
+31 -61
View File
@@ -5,70 +5,40 @@
#ifndef _KERNEL_KHASH_H #ifndef _KERNEL_KHASH_H
#define _KERNEL_KHASH_H #define _KERNEL_KHASH_H
#include <pools.h> // can be allocated on the stack
typedef struct hash_iterator {
typedef struct hash_entry hash_entry; void *current;
typedef struct new_hash_table new_hash_table;
typedef struct hash_index hash_index;
struct hash_entry {
hash_entry *next;
int hash;
const void *key;
ssize_t klen;
const void *val;
};
struct hash_index {
new_hash_table *nh;
hash_entry *this_idx;
hash_entry *next;
int index;
};
struct new_hash_table {
hash_entry **array;
hash_index iterator;
int count;
int max;
struct pool_ctl *pool;
};
new_hash_table *hash_make(void);
void *hash_get(new_hash_table *, const void *, ssize_t);
void hash_set(new_hash_table *, const void *, ssize_t , const void *);
struct hash_iterator {
void *ptr;
int bucket; int bucket;
}; } hash_iterator;
void *hash_init(unsigned int table_size, int next_ptr_offset, typedef struct hash_table hash_table;
int compare_func(void *a, const void *key),
unsigned int hash_func(void *a, const void *key, unsigned int range)); struct hash_table *hash_init(uint32 table_size, int next_ptr_offset,
int hash_uninit(void *_hash_table); int compare_func(void *element, const void *key),
int hash_insert(void *_hash_table, void *_elem); uint32 hash_func(void *element, const void *key, uint32 range));
int hash_remove(void *_hash_table, void *_elem); int hash_uninit(struct hash_table *table);
void *hash_find(void *_hash_table, void *e); status_t hash_insert(struct hash_table *table, void *_element);
void *hash_lookup(void *_hash_table, const void *key); status_t hash_remove(struct hash_table *table, void *_element);
struct hash_iterator *hash_open(void *_hash_table, struct hash_iterator *i); void *hash_find(struct hash_table *table, void *e);
void hash_close(void *_hash_table, struct hash_iterator *i, bool free_iterator); void *hash_lookup(struct hash_table *table, const void *key);
void *hash_next(void *_hash_table, struct hash_iterator *i); struct hash_iterator *hash_open(struct hash_table *table, struct hash_iterator *i);
void hash_rewind(void *_hash_table, struct hash_iterator *i); void hash_close(struct hash_table *table, struct hash_iterator *i, bool free_iterator);
void *hash_next(struct hash_table *table, struct hash_iterator *i);
void hash_rewind(struct hash_table *table, struct hash_iterator *i);
/* function ptrs must look like this: /* function ptrs must look like this:
// hash function should calculate hash on either e or key, *
// depending on which one is not NULL * uint32 hash_func(void *e, const void *key, uint32 range);
unsigned int hash_func(void *e, const void *key, unsigned int range); * hash function should calculate hash on either e or key,
// compare function should compare the element with * depending on which one is not NULL
// the key, returning 0 if equal, other if not * int compare_func(void *e, const void *key);
// NOTE: compare func can be null, in which case the hash * compare function should compare the element with
// code will compare the key pointer with the target * the key, returning 0 if equal, other if not
int compare_func(void *e, const void *key); * NOTE: compare func can be null, in which case the hash
*/ * code will compare the key pointer with the target
* ToDo: check this!
*/
unsigned int hash_hash_str( const char *str ); uint32 hash_hash_string(const char *str);
#endif
#endif /* _KERNEL_KHASH_H */