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 11 namespace FSShell { 12 13 // can be allocated on the stack 14 typedef struct hash_iterator { 15 void *current; 16 int bucket; 17 } hash_iterator; 18 19 typedef struct hash_table hash_table; 20 21 struct 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)); 24 int hash_uninit(struct hash_table *table); 25 fssh_status_t hash_insert(struct hash_table *table, void *_element); 26 fssh_status_t hash_remove(struct hash_table *table, void *_element); 27 void hash_remove_current(struct hash_table *table, struct hash_iterator *iterator); 28 void *hash_remove_first(struct hash_table *table, uint32_t *_cookie); 29 void *hash_find(struct hash_table *table, void *e); 30 void *hash_lookup(struct hash_table *table, const void *key); 31 struct hash_iterator *hash_open(struct hash_table *table, struct hash_iterator *i); 32 void hash_close(struct hash_table *table, struct hash_iterator *i, bool free_iterator); 33 void *hash_next(struct hash_table *table, struct hash_iterator *i); 34 void 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 47 uint32_t hash_hash_string(const char *str); 48 49 } // namespace FSShell 50 51 #endif /* _FSSH_HASH_H */ 52