Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/adt/hash_table.h

    r82cbf8c6 r9d58539  
    11/*
    22 * Copyright (c) 2006 Jakub Jermar
    3  * Copyright (c) 2012 Adam Hraska
    4  *
    53 * All rights reserved.
    64 *
     
    2927 */
    3028
    31 /** @addtogroup libc
     29/** @addtogroup genericadt
    3230 * @{
    3331 */
     
    3533 */
    3634
    37 #ifndef LIBC_HASH_TABLE_H_
    38 #define LIBC_HASH_TABLE_H_
     35#ifndef KERN_HASH_TABLE_H_
     36#define KERN_HASH_TABLE_H_
    3937
    4038#include <adt/list.h>
    41 #include <stdbool.h>
    42 #include <macros.h>
    43 
    44 /** Opaque hash table link type. */
    45 typedef struct ht_link {
    46         link_t link;
    47 } ht_link_t;
     39#include <typedefs.h>
    4840
    4941/** Set of operations for hash table. */
    5042typedef struct {
    51         /** Returns the hash of the key stored in the item (ie its lookup key). */
    52         size_t (*hash)(const ht_link_t *item);
     43        /** Hash function.
     44         *
     45         * @param key   Array of keys needed to compute hash index. All keys must
     46         *              be passed.
     47         *
     48         * @return Index into hash table.
     49         */
     50        size_t (* hash)(sysarg_t key[]);
    5351       
    54         /** Returns the hash of the key. */
    55         size_t (*key_hash)(void *key);
    56        
    57         /** True if the items are equal (have the same lookup keys). */
    58         bool (*equal)(const ht_link_t *item1, const ht_link_t *item2);
    59 
    60         /** Returns true if the key is equal to the item's lookup key. */
    61         bool (*key_equal)(void *key, const ht_link_t *item);
     52        /** Hash table item comparison function.
     53         *
     54         * @param key   Array of keys that will be compared with item. It is not
     55         *              necessary to pass all keys.
     56         *
     57         * @return true if the keys match, false otherwise.
     58        */
     59        bool (*compare)(sysarg_t key[], size_t keys, link_t *item);
    6260
    6361        /** Hash table item removal callback.
    64          *
    65          * Must not invoke any mutating functions of the hash table.
    6662         *
    6763         * @param item Item that was removed from the hash table.
    6864         */
    69         void (*remove_callback)(ht_link_t *item);
    70 } hash_table_ops_t;
     65        void (*remove_callback)(link_t *item);
     66} hash_table_operations_t;
    7167
    7268/** Hash table structure. */
    7369typedef struct {
    74         hash_table_ops_t *op;
    75         list_t *bucket;
    76         size_t bucket_cnt;
    77         size_t full_item_cnt;
    78         size_t item_cnt;
    79         size_t max_load;
    80         bool apply_ongoing;
     70        list_t *entry;
     71        size_t entries;
     72        size_t max_keys;
     73        hash_table_operations_t *op;
    8174} hash_table_t;
    8275
    83 #define hash_table_get_inst(item, type, member) \
    84         member_to_inst((item), type, member)
     76#define hash_table_get_instance(item, type, member) \
     77        list_get_instance((item), type, member)
    8578
    86 extern bool hash_table_create(hash_table_t *, size_t, size_t,
    87         hash_table_ops_t *);
    88 extern void hash_table_destroy(hash_table_t *);
    89 
    90 extern bool hash_table_empty(hash_table_t *);
    91 extern size_t hash_table_size(hash_table_t *);
    92 
    93 extern void hash_table_clear(hash_table_t *);
    94 extern void hash_table_insert(hash_table_t *, ht_link_t *);
    95 extern bool hash_table_insert_unique(hash_table_t *, ht_link_t *);
    96 extern ht_link_t *hash_table_find(const hash_table_t *, void *);
    97 extern ht_link_t *hash_table_find_next(const hash_table_t *, ht_link_t *);
    98 extern size_t hash_table_remove(hash_table_t *, void *);
    99 extern void hash_table_remove_item(hash_table_t *, ht_link_t *);
    100 extern void hash_table_apply(hash_table_t *, bool (*)(ht_link_t *, void *),
    101         void *);
    102 
     79extern void hash_table_create(hash_table_t *h, size_t m, size_t max_keys,
     80    hash_table_operations_t *op);
     81extern void hash_table_insert(hash_table_t *h, sysarg_t key[], link_t *item);
     82extern link_t *hash_table_find(hash_table_t *h, sysarg_t key[]);
     83extern void hash_table_remove(hash_table_t *h, sysarg_t key[], size_t keys);
    10384
    10485#endif
Note: See TracChangeset for help on using the changeset viewer.