Changeset bc216a0 in mainline for uspace/lib/c/include/adt/hash_table.h
- Timestamp:
- 2012-08-07T22:13:44Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- da68871a
- Parents:
- b17518e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/adt/hash_table.h
rb17518e rbc216a0 1 1 /* 2 2 * Copyright (c) 2006 Jakub Jermar 3 * Copyright (c) 2012 Adam Hraska 4 * 3 5 * All rights reserved. 4 6 * … … 39 41 #include <unistd.h> 40 42 #include <bool.h> 43 #include <macros.h> 41 44 45 /** Opaque hash table link type. */ 46 typedef struct ht_link { 47 link_t link; 48 } ht_link_t; 42 49 43 50 /** Set of operations for hash table. */ 44 51 typedef struct { 45 /** Returns the hash of the key stored in the item. 46 */ 47 size_t (*hash)(const link_t *item); 52 /** Returns the hash of the key stored in the item (ie its lookup key). */ 53 size_t (*hash)(const ht_link_t *item); 48 54 49 /** Returns the hash of the key. 50 */ 51 size_t (*key_hash)(unsigned long key[]); 55 /** Returns the hash of the key. */ 56 size_t (*key_hash)(void *key); 52 57 53 /** Hash table item match function. 54 * 55 * @param key Array of keys that will be compared with item. It is 56 * not necessary to pass all keys. 57 * 58 * @return True if the keys match, false otherwise. 59 * 60 */ 61 bool (*match)(unsigned long key[], size_t keys, const link_t *item); 58 /** True if the items are equal (have the same lookup keys). */ 59 bool (*equal)(const ht_link_t *item1, const ht_link_t *item2); 62 60 63 /** 64 */ 65 bool (*equal)(const link_t *item1, const link_t *item2); 66 61 /** Returns true if the key is equal to the item's lookup key. */ 62 bool (*key_equal)(void *key, const ht_link_t *item); 63 67 64 /** Hash table item removal callback. 68 65 * … … 71 68 * @param item Item that was removed from the hash table. 72 69 */ 73 void (*remove_callback)( link_t *item);70 void (*remove_callback)(ht_link_t *item); 74 71 } hash_table_ops_t; 75 72 76 73 /** Hash table structure. */ 77 74 typedef struct { 75 hash_table_ops_t *op; 78 76 list_t *bucket; 79 77 size_t bucket_cnt; 80 size_t max_keys; 81 size_t items; 82 hash_table_ops_t *op; 78 size_t full_item_cnt; 79 size_t item_cnt; 80 size_t max_load; 81 bool apply_ongoing; 83 82 } hash_table_t; 84 83 85 #define hash_table_get_inst ance(item, type, member) \86 list_get_instance((item), type, member)84 #define hash_table_get_inst(item, type, member) \ 85 member_to_inst((item), type, member) 87 86 88 87 extern bool hash_table_create(hash_table_t *, size_t, size_t, 89 88 hash_table_ops_t *); 89 extern void hash_table_destroy(hash_table_t *); 90 91 extern bool hash_table_empty(hash_table_t *); 92 extern size_t hash_table_size(hash_table_t *); 93 90 94 extern void hash_table_clear(hash_table_t *); 91 extern void hash_table_insert(hash_table_t *, link_t *);92 extern bool hash_table_insert_unique(hash_table_t *, link_t *);93 extern link_t *hash_table_find(const hash_table_t *, unsigned long []);94 extern size_t hash_table_remove(hash_table_t *, unsigned long [], size_t);95 extern void hash_table_remove_item(hash_table_t *, link_t*);96 extern void hash_table_ destroy(hash_table_t *);97 extern void hash_table_apply(hash_table_t *, bool (*)( link_t *, void *),95 extern void hash_table_insert(hash_table_t *, ht_link_t *); 96 extern bool hash_table_insert_unique(hash_table_t *, ht_link_t *); 97 extern ht_link_t *hash_table_find(const hash_table_t *, void *); 98 extern ht_link_t *hash_table_find_next(const hash_table_t *, ht_link_t *); 99 extern size_t hash_table_remove(hash_table_t *, void *); 100 extern void hash_table_remove_item(hash_table_t *, ht_link_t *); 101 extern void hash_table_apply(hash_table_t *, bool (*)(ht_link_t *, void *), 98 102 void *); 99 103
Note:
See TracChangeset
for help on using the changeset viewer.