diff --git a/src/hash_table/hash_table.c b/src/hash_table/hash_table.c new file mode 100644 index 00000000000..b49ce11cde7 --- /dev/null +++ b/src/hash_table/hash_table.c @@ -0,0 +1,50 @@ +/* -*- mode: C; c-basic-offset: 4 -*- */ +#ident "Copyright (c) 2007-8 Tokutek Inc. All rights reserved." + +#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it." + +/** + \file hash_table.h + \brief Hash table + +*/ + +//Defines BOOL data type. +#include + +typedef u_int32_t uint32; + +/* TODO: reallocate the hash table if it grows too big. Perhaps, use toku_get_prime in newbrt/primes.c */ +const uint32 __toku_rth_init_size = 521; + +typedef struct __toku_rt_forest toku_rt_forest; +struct __toku_rt_forest { + toku_range_tree* selfread; + toku_range_tree* selfwrite; +}; + +typedef struct __toku_rth_elt toku_rth_elt; +struct __toku_rth_elt { + DB_TXN* key; + toku_range_forest value; + toku_rth_elt* next; +}; + +typedef struct { + uint32 index; + toku_rth_elt* next; +} toku_rth_finger; + +typedef struct __toku_rt_hash_elt toku_rt_hash_elt; +struct toku_rt_hashtable { + toku_rth_elt** table; + uint32 num_keys; + uint32 array_size; +}; + +int toku_rth_create(toku_rt_hashtable** ptable); + +int toku_rth_find(toku_rt_hashtable* table, DB_TXN* key, toku_rt_forest* value, BOOL* found); +int toku_rth_scan(toku_rt_hashtable* table, toku_rt_forest* value, toku_rth_finger* finger); +int toku_rth_delete(toku_rt_hashtable* table, DB_TXN* key); +int toku_rth_close(toku_rt_hashtable* table); diff --git a/src/hash_table/hash_table.h b/src/hash_table/hash_table.h new file mode 100644 index 00000000000..b49ce11cde7 --- /dev/null +++ b/src/hash_table/hash_table.h @@ -0,0 +1,50 @@ +/* -*- mode: C; c-basic-offset: 4 -*- */ +#ident "Copyright (c) 2007-8 Tokutek Inc. All rights reserved." + +#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it." + +/** + \file hash_table.h + \brief Hash table + +*/ + +//Defines BOOL data type. +#include + +typedef u_int32_t uint32; + +/* TODO: reallocate the hash table if it grows too big. Perhaps, use toku_get_prime in newbrt/primes.c */ +const uint32 __toku_rth_init_size = 521; + +typedef struct __toku_rt_forest toku_rt_forest; +struct __toku_rt_forest { + toku_range_tree* selfread; + toku_range_tree* selfwrite; +}; + +typedef struct __toku_rth_elt toku_rth_elt; +struct __toku_rth_elt { + DB_TXN* key; + toku_range_forest value; + toku_rth_elt* next; +}; + +typedef struct { + uint32 index; + toku_rth_elt* next; +} toku_rth_finger; + +typedef struct __toku_rt_hash_elt toku_rt_hash_elt; +struct toku_rt_hashtable { + toku_rth_elt** table; + uint32 num_keys; + uint32 array_size; +}; + +int toku_rth_create(toku_rt_hashtable** ptable); + +int toku_rth_find(toku_rt_hashtable* table, DB_TXN* key, toku_rt_forest* value, BOOL* found); +int toku_rth_scan(toku_rt_hashtable* table, toku_rt_forest* value, toku_rth_finger* finger); +int toku_rth_delete(toku_rt_hashtable* table, DB_TXN* key); +int toku_rth_close(toku_rt_hashtable* table); diff --git a/src/hash_table/hashtable.c b/src/hash_table/hashtable.c index 361d9051aa7..325df66d508 100755 --- a/src/hash_table/hashtable.c +++ b/src/hash_table/hashtable.c @@ -65,16 +65,10 @@ int toku_hashtable_create (HASHTABLE *h) { assert(sizeof(*tab->array)==sizeof(void*)); tab->array = toku_calloc(tab->arraysize, sizeof(*tab->array)); for (i=0; iarraysize; i++) tab->array[i]=0; - tab->allow_dups = 1; *h=tab; return 0; } -int toku_hashtable_set_dups (HASHTABLE tab, unsigned int allow_dups) { - tab->allow_dups = allow_dups; - return 0; -} - static void hash_find_internal (HASHTABLE tab, unsigned int hash, const unsigned char *key, ITEMLEN keylen, HASHDUP *dup_ptr, HASHDUP **prev_ptr) { unsigned int h = hash % tab->arraysize; HASHDUP dup; @@ -88,7 +82,7 @@ static void hash_find_internal (HASHTABLE tab, unsigned int hash, const unsigned } } *prev_ptr = prev; - *dup_ptr = 0; + *dup_ptr = NULL; } int toku_hash_find_idx (HASHTABLE tab, bytevec key, ITEMLEN keylen, int idx, bytevec *data, ITEMLEN *datalen, int *type) { @@ -114,7 +108,7 @@ int toku_hash_find_idx (HASHTABLE tab, bytevec key, ITEMLEN keylen, int idx, byt int toku_hash_find (HASHTABLE tab, bytevec key, ITEMLEN keylen, bytevec *data, ITEMLEN *datalen, int *type) { HASHDUP dup, *prev; hash_find_internal(tab, hash_key (key, keylen), key, keylen, &dup, &prev); - if (dup==0) { + if (dup==NULL) { return -1; } else { HASHELT he = hashelt_list_peek(&dup->kdlist); diff --git a/src/hash_table/hashtable.h b/src/hash_table/hashtable.h index 314e31d0dfd..c7c02c47c71 100755 --- a/src/hash_table/hashtable.h +++ b/src/hash_table/hashtable.h @@ -13,11 +13,6 @@ typedef struct hashtable *HASHTABLE; int toku_hashtable_create (HASHTABLE*); -/* Configure the hash table for duplicate keys. - allow_dups != 0 -> duplications allowed, allow_dups == 0 -> no duplicates */ - -int toku_hashtable_set_dups (HASHTABLE, unsigned int allow_dups); - /* Return 0 if the key is found in the hashtable, -1 otherwise. */ /* Warning: The data returned points to the internals of the hashtable. It is set to "const" to try to prevent you from messing it up. */ int toku_hash_find (HASHTABLE tab, bytevec key, ITEMLEN keylen, bytevec *data, ITEMLEN *datalen, int *type); @@ -75,7 +70,6 @@ struct hashtable { unsigned int n_keys; unsigned int arraysize; unsigned int primeidx; - unsigned int allow_dups; }; /* You cannot add or delete elements from the hashtable while iterating. */