Commit 2ac3d9fd authored by Vincenzo Liberatore's avatar Vincenzo Liberatore

Addresses #329

Header file

git-svn-id: file:///svn/tokudb@2040 c7de825b-a66e-492c-adef-691d508d4ae1
parent 9cb0598c
/* -*- 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 <brttypes.h>
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);
/* -*- 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 <brttypes.h>
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);
......@@ -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; i<tab->arraysize; 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);
......
......@@ -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. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment