Changeset 4f34b6a in mainline


Ignore:
Timestamp:
2006-03-14T22:55:01Z (19 years ago)
Author:
Josef Cejka <malyzelenyhnus@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
936351c1
Parents:
ee7736e
Message:

Hash_table conversion done.
Simple assert function converted from kernel.

Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • libadt/Makefile

    ree7736e r4f34b6a  
    4242
    4343GENERIC_SOURCES = \
    44         generic/list.c
     44        generic/list.c \
     45        generic/hash_table.c
    4546
    4647GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
  • libadt/generic/hash_table.c

    ree7736e r4f34b6a  
    3636#include <malloc.h>
    3737#include <assert.h>
     38#include <stdio.h>
     39#include <string.h>
    3840
    3941/** Create chained hash table.
     
    4345 * @param max_keys Maximal number of keys needed to identify an item.
    4446 * @param op Hash table operations structure.
     47 * @return true on success
    4548 */
    46 void hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys, hash_table_operations_t *op)
     49int hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys, hash_table_operations_t *op)
    4750{
    48         int i;
     51        hash_count_t i;
    4952
    50         ASSERT(h);
    51         ASSERT(op && op->hash && op->compare);
    52         ASSERT(max_keys > 0);
     53        assert(h);
     54        assert(op && op->hash && op->compare);
     55        assert(max_keys > 0);
    5356       
    54         h->entry = malloc(m * sizeof(link_t *), 0);
     57        h->entry = malloc(m * sizeof(link_t *));
    5558        if (!h->entry) {
    56                 panic("cannot allocate memory for hash table\n");
     59                printf("cannot allocate memory for hash table\n");
     60                return false;
    5761        }
    58         memsetb((__address) h->entry, m * sizeof(link_t *), 0);
     62        memset((void *) h->entry, 0,  m * sizeof(link_t *));
    5963       
    6064        for (i = 0; i < m; i++)
     
    6468        h->max_keys = max_keys;
    6569        h->op = op;
     70        return true;
    6671}
    6772
     
    7277 * @param item Item to be inserted into the hash table.
    7378 */
    74 void hash_table_insert(hash_table_t *h, __native key[], link_t *item)
     79void hash_table_insert(hash_table_t *h, unsigned long key[], link_t *item)
    7580{
    7681        hash_index_t chain;
    7782
    78         ASSERT(item);
    79         ASSERT(h && h->op && h->op->hash && h->op->compare);
     83        assert(item);
     84        assert(h && h->op && h->op->hash && h->op->compare);
    8085
    8186        chain = h->op->hash(key);
    82         ASSERT(chain < h->entries);
     87        assert(chain < h->entries);
    8388       
    8489        list_append(item, &h->entry[chain]);
     
    9297 * @return Matching item on success, NULL if there is no such item.
    9398 */
    94 link_t *hash_table_find(hash_table_t *h, __native key[])
     99link_t *hash_table_find(hash_table_t *h, unsigned long key[])
    95100{
    96101        link_t *cur;
    97102        hash_index_t chain;
    98103
    99         ASSERT(h && h->op && h->op->hash && h->op->compare);
     104        assert(h && h->op && h->op->hash && h->op->compare);
    100105
    101106        chain = h->op->hash(key);
    102         ASSERT(chain < h->entries);
     107        assert(chain < h->entries);
    103108       
    104109        /*
     
    126131 * @param keys Number of keys in the 'key' array.
    127132 */
    128 void hash_table_remove(hash_table_t *h, __native key[], hash_count_t keys)
     133void hash_table_remove(hash_table_t *h, unsigned long key[], hash_count_t keys)
    129134{
    130135        hash_index_t chain;
    131136        link_t *cur;
    132137
    133         ASSERT(h && h->op && h->op->hash && h->op->compare && h->op->remove_callback);
    134         ASSERT(keys <= h->max_keys);
     138        assert(h && h->op && h->op->hash && h->op->compare && h->op->remove_callback);
     139        assert(keys <= h->max_keys);
    135140       
    136141        if (keys == h->max_keys) {
  • libadt/include/hash_table.h

    ree7736e r4f34b6a  
    5454         * @return Index into hash table.
    5555         */
    56         hash_index_t (* hash)(int key[]);
     56        hash_index_t (* hash)(unsigned long key[]);
    5757       
    5858        /** Hash table item comparison function.
     
    6262         * @return true if the keys match, false otherwise.
    6363         */
    64         int (*compare)(int key[], hash_count_t keys, link_t *item);
     64        int (*compare)(unsigned long key[], hash_count_t keys, link_t *item);
    6565
    6666        /** Hash table item removal callback.
     
    7373#define hash_table_get_instance(item, type, member)     list_get_instance((item), type, member)
    7474
    75 extern void hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys, hash_table_operations_t *op);
    76 extern void hash_table_insert(hash_table_t *h, int key[], link_t *item);
    77 extern link_t *hash_table_find(hash_table_t *h, int key[]);
    78 extern void hash_table_remove(hash_table_t *h, int key[], hash_count_t keys);
     75extern int hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys, hash_table_operations_t *op);
     76extern void hash_table_insert(hash_table_t *h, unsigned long key[], link_t *item);
     77extern link_t *hash_table_find(hash_table_t *h, unsigned long key[]);
     78extern void hash_table_remove(hash_table_t *h, unsigned long key[], hash_count_t keys);
    7979
    8080#endif
Note: See TracChangeset for help on using the changeset viewer.