1/*
2** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
3** Distributed under the terms of the NewOS License.
4*/
5#ifndef _FSSH_HASH_H
6#define _FSSH_HASH_H
7
8#include "fssh_types.h"
9
10
11namespace FSShell {
12
13// can be allocated on the stack
14typedef struct hash_iterator {
15	void *current;
16	int bucket;
17} hash_iterator;
18
19typedef struct hash_table hash_table;
20
21struct hash_table *hash_init(uint32_t table_size, int next_ptr_offset,
22	int compare_func(void *element, const void *key),
23	uint32_t hash_func(void *element, const void *key, uint32_t range));
24int hash_uninit(struct hash_table *table);
25fssh_status_t hash_insert(struct hash_table *table, void *_element);
26fssh_status_t hash_remove(struct hash_table *table, void *_element);
27void hash_remove_current(struct hash_table *table, struct hash_iterator *iterator);
28void *hash_remove_first(struct hash_table *table, uint32_t *_cookie);
29void *hash_find(struct hash_table *table, void *e);
30void *hash_lookup(struct hash_table *table, const void *key);
31struct hash_iterator *hash_open(struct hash_table *table, struct hash_iterator *i);
32void hash_close(struct hash_table *table, struct hash_iterator *i, bool free_iterator);
33void *hash_next(struct hash_table *table, struct hash_iterator *i);
34void hash_rewind(struct hash_table *table, struct hash_iterator *i);
35
36/* function pointers must look like this:
37 *
38 * uint32 hash_func(void *e, const void *key, uint32 range);
39 *		hash function should calculate hash on either e or key,
40 *		depending on which one is not NULL - they also need
41 *		to make sure the returned value is within range.
42 * int compare_func(void *e, const void *key);
43 *		compare function should compare the element with
44 *		the key, returning 0 if equal, other if not
45 */
46
47uint32_t hash_hash_string(const char *str);
48
49}	// namespace FSShell
50
51#endif	/* _FSSH_HASH_H */
52