Ignore:
Timestamp:
2017-10-08T19:37:24Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2fd26bb
Parents:
81b9d3e
Message:

Replace the old hash table implementation in the kernel with the newer one

This replaces the original hash table implementation with the resizable one
already used in uspace. Along the way, the IRQ hash table code was streamlined
and cleaned up.

File:
1 edited

Legend:

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

    r81b9d3e r82cbf8c6  
    11/*
    22 * Copyright (c) 2006 Jakub Jermar
     3 * Copyright (c) 2012 Adam Hraska
     4 *
    35 * All rights reserved.
    46 *
     
    2729 */
    2830
    29 /** @addtogroup genericadt
     31/** @addtogroup libc
    3032 * @{
    3133 */
     
    3335 */
    3436
    35 #ifndef KERN_HASH_TABLE_H_
    36 #define KERN_HASH_TABLE_H_
     37#ifndef LIBC_HASH_TABLE_H_
     38#define LIBC_HASH_TABLE_H_
    3739
    3840#include <adt/list.h>
    39 #include <typedefs.h>
     41#include <stdbool.h>
     42#include <macros.h>
     43
     44/** Opaque hash table link type. */
     45typedef struct ht_link {
     46        link_t link;
     47} ht_link_t;
    4048
    4149/** Set of operations for hash table. */
    4250typedef struct {
    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[]);
     51        /** Returns the hash of the key stored in the item (ie its lookup key). */
     52        size_t (*hash)(const ht_link_t *item);
    5153       
    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);
     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);
    6062
    6163        /** Hash table item removal callback.
     64         *
     65         * Must not invoke any mutating functions of the hash table.
    6266         *
    6367         * @param item Item that was removed from the hash table.
    6468         */
    65         void (*remove_callback)(link_t *item);
    66 } hash_table_operations_t;
     69        void (*remove_callback)(ht_link_t *item);
     70} hash_table_ops_t;
    6771
    6872/** Hash table structure. */
    6973typedef struct {
    70         list_t *entry;
    71         size_t entries;
    72         size_t max_keys;
    73         hash_table_operations_t *op;
     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;
    7481} hash_table_t;
    7582
    76 #define hash_table_get_instance(item, type, member) \
    77         list_get_instance((item), type, member)
     83#define hash_table_get_inst(item, type, member) \
     84        member_to_inst((item), type, member)
    7885
    79 extern void hash_table_create(hash_table_t *h, size_t m, size_t max_keys,
    80     hash_table_operations_t *op);
    81 extern void hash_table_insert(hash_table_t *h, sysarg_t key[], link_t *item);
    82 extern link_t *hash_table_find(hash_table_t *h, sysarg_t key[]);
    83 extern void hash_table_remove(hash_table_t *h, sysarg_t key[], size_t keys);
    84 extern void hash_table_remove_item(hash_table_t *h, link_t *item);
     86extern bool hash_table_create(hash_table_t *, size_t, size_t,
     87        hash_table_ops_t *);
     88extern void hash_table_destroy(hash_table_t *);
     89
     90extern bool hash_table_empty(hash_table_t *);
     91extern size_t hash_table_size(hash_table_t *);
     92
     93extern void hash_table_clear(hash_table_t *);
     94extern void hash_table_insert(hash_table_t *, ht_link_t *);
     95extern bool hash_table_insert_unique(hash_table_t *, ht_link_t *);
     96extern ht_link_t *hash_table_find(const hash_table_t *, void *);
     97extern ht_link_t *hash_table_find_next(const hash_table_t *, ht_link_t *);
     98extern size_t hash_table_remove(hash_table_t *, void *);
     99extern void hash_table_remove_item(hash_table_t *, ht_link_t *);
     100extern void hash_table_apply(hash_table_t *, bool (*)(ht_link_t *, void *),
     101        void *);
     102
    85103
    86104#endif
Note: See TracChangeset for help on using the changeset viewer.