move hash iterator code around, update documentation
This commit is contained in:
parent
dcf07c1d4c
commit
e2f604175b
3 changed files with 72 additions and 54 deletions
|
@ -15,16 +15,6 @@ void lladdIterator_register(int type, lladdIterator_def_t info) {
|
|||
static void noopTupDone(int xid, void * foo) { }
|
||||
|
||||
void iterator_init() {
|
||||
lladdIterator_def_t linearHashNTA_def = {
|
||||
linearHashNTAIterator_close,
|
||||
linearHashNTAIterator_next,
|
||||
linearHashNTAIterator_next,
|
||||
linearHashNTAIterator_key,
|
||||
linearHashNTAIterator_value,
|
||||
noopTupDone,
|
||||
noopTupDone
|
||||
};
|
||||
lladdIterator_register(LINEAR_HASH_NTA_ITERATOR, linearHashNTA_def);
|
||||
lladdIterator_def_t array_def = {
|
||||
arrayIterator_close,
|
||||
arrayIterator_next,
|
||||
|
|
|
@ -17,8 +17,13 @@
|
|||
@todo Improve concurrency of linearHashNTA and linkedListNTA by leveraging Page.impl on the data structure header page?
|
||||
*/
|
||||
|
||||
static pthread_mutex_t linear_hash_mutex;// = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||
|
||||
static void linearHashNTAIterator_close(int xid, void * it);
|
||||
static int linearHashNTAIterator_next (int xid, void * it);
|
||||
static int linearHashNTAIterator_key (int xid, void * it, byte **key);
|
||||
static int linearHashNTAIterator_value(int xid, void * it, byte **value);
|
||||
|
||||
static pthread_mutex_t linear_hash_mutex;// = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||
|
||||
typedef struct {
|
||||
recordid buckets;
|
||||
|
@ -29,6 +34,7 @@ typedef struct {
|
|||
long numEntries;
|
||||
} lladd_hash_header;
|
||||
|
||||
static void noopTupDone(int xid, void * foo) { }
|
||||
|
||||
void LinearHashNTAInit() {
|
||||
// only need this function since PTHREAD_RECURSIVE_MUTEX_INITIALIZER is really broken...
|
||||
|
@ -36,6 +42,17 @@ void LinearHashNTAInit() {
|
|||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&linear_hash_mutex, &attr);
|
||||
|
||||
lladdIterator_def_t linearHashNTA_def = {
|
||||
linearHashNTAIterator_close,
|
||||
linearHashNTAIterator_next,
|
||||
linearHashNTAIterator_next,
|
||||
linearHashNTAIterator_key,
|
||||
linearHashNTAIterator_value,
|
||||
noopTupDone,
|
||||
noopTupDone
|
||||
};
|
||||
lladdIterator_register(LINEAR_HASH_NTA_ITERATOR, linearHashNTA_def);
|
||||
}
|
||||
|
||||
|
||||
|
@ -499,7 +516,7 @@ lladdIterator_t * ThashGenericIterator(int xid, recordid hash) {
|
|||
|
||||
}
|
||||
|
||||
void linearHashNTAIterator_close(int xid, void * impl) {
|
||||
static void linearHashNTAIterator_close(int xid, void * impl) {
|
||||
lladd_linearHashNTA_generic_it * it = impl;
|
||||
|
||||
ThashDone(xid, it->hit);
|
||||
|
@ -513,7 +530,7 @@ void linearHashNTAIterator_close(int xid, void * impl) {
|
|||
free(it);
|
||||
}
|
||||
|
||||
int linearHashNTAIterator_next (int xid, void * impl) {
|
||||
static int linearHashNTAIterator_next (int xid, void * impl) {
|
||||
lladd_linearHashNTA_generic_it * it = impl;
|
||||
|
||||
if(it->lastKey) {
|
||||
|
@ -527,7 +544,7 @@ int linearHashNTAIterator_next (int xid, void * impl) {
|
|||
return ThashNext(xid, it->hit, &(it->lastKey), &it->lastKeySize, &it->lastValue, &it->lastValueSize);
|
||||
}
|
||||
|
||||
int linearHashNTAIterator_key(int xid, void * impl, byte ** key) {
|
||||
static int linearHashNTAIterator_key(int xid, void * impl, byte ** key) {
|
||||
lladd_linearHashNTA_generic_it * it = impl;
|
||||
|
||||
*key = it->lastKey;
|
||||
|
@ -535,7 +552,7 @@ int linearHashNTAIterator_key(int xid, void * impl, byte ** key) {
|
|||
return (it->lastKey == NULL) ? 0 : it->lastKeySize;
|
||||
}
|
||||
|
||||
int linearHashNTAIterator_value(int xid, void * impl, byte ** value) {
|
||||
static int linearHashNTAIterator_value(int xid, void * impl, byte ** value) {
|
||||
lladd_linearHashNTA_generic_it * it = impl;
|
||||
|
||||
*value = it->lastValue;
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
/**
|
||||
@file
|
||||
|
||||
A reliable hashtable implementation. The implementation makes
|
||||
use of nested top actions, and is reentrant.
|
||||
@ingroup LINEAR_HASH_NTA
|
||||
@defgroup LINEAR_HASH_NTA LinearHash
|
||||
|
||||
Reentrant, dynamically-resized transactional hashtable implementation
|
||||
|
||||
This hashtable makes use of nested top actions, and is reentrant.
|
||||
|
||||
The implementation uses a linear hash function, allowing the
|
||||
bucket list to be resized dynamically. Because the bucket list is
|
||||
|
@ -12,7 +16,7 @@
|
|||
|
||||
@see nestedTopAction.h, linkedListNTA.h, arrayList.h
|
||||
|
||||
@ingroup OPERATIONS
|
||||
@ingroup COLLECTIONS
|
||||
|
||||
$id$
|
||||
|
||||
|
@ -22,24 +26,21 @@
|
|||
|
||||
#ifndef __LINEAR_HASH_NTA_H
|
||||
#define __LINEAR_HASH_NTA_H
|
||||
/** Currently, only used in the type field of the iterators. */
|
||||
#define FIXED_LENGTH_HASH 0
|
||||
#define VARIABLE_LENGTH_HASH 1
|
||||
|
||||
/** @ingroup ARRAY_LIST */
|
||||
/** @{ */
|
||||
|
||||
|
||||
/** Pass this into the keySize and/or valueSize parameter of the
|
||||
constructor below if the hashtable should support variable length
|
||||
keys and/or values, respectively. */
|
||||
#define VARIABLE_LENGTH -1
|
||||
|
||||
typedef struct {
|
||||
recordid hashHeader;
|
||||
recordid bucket;
|
||||
int numBuckets;
|
||||
int keySize;
|
||||
int valueSize;
|
||||
stasis_linkedList_iterator * it;
|
||||
lladd_pagedList_iterator * pit;
|
||||
} lladd_hash_iterator;
|
||||
/** Support 16 entries by default. */
|
||||
#define HASH_INIT_BITS 4
|
||||
/** Aim to keep 0.7 items in each bucket */
|
||||
#define HASH_FILL_FACTOR 0.7
|
||||
|
||||
|
||||
compensated_function recordid ThashCreate(int xid, int keySize, int valSize);
|
||||
compensated_function void ThashDelete(int xid, recordid hash);
|
||||
|
@ -74,6 +75,39 @@ compensated_function int ThashRemove(int xid, recordid hash,
|
|||
(a return value of zero means the key is associated with an
|
||||
empty value.) */
|
||||
compensated_function int ThashLookup(int xid, recordid hash, const byte* key, int keySize, byte ** value);
|
||||
|
||||
/**
|
||||
Iterator that complies with the standard Stasis iterator interface.
|
||||
|
||||
@todo current generic linearHashIterator implemnetation is just slapped on top of old, slow interface.
|
||||
@todo rename ThashGenericIterator to ThashIterator, and remove deprecated iterator interface...
|
||||
*/
|
||||
|
||||
lladdIterator_t * ThashGenericIterator (int xid, recordid hash);
|
||||
|
||||
Operation getLinearHashInsert();
|
||||
Operation getLinearHashRemove();
|
||||
|
||||
void LinearHashNTAInit();
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
@deprecated
|
||||
*/
|
||||
typedef struct {
|
||||
recordid hashHeader;
|
||||
recordid bucket;
|
||||
int numBuckets;
|
||||
int keySize;
|
||||
int valueSize;
|
||||
stasis_linkedList_iterator * it;
|
||||
lladd_pagedList_iterator * pit;
|
||||
} lladd_hash_iterator;
|
||||
|
||||
/** Currently, only used in the type field of the iterators. */
|
||||
#define FIXED_LENGTH_HASH 0
|
||||
#define VARIABLE_LENGTH_HASH 1
|
||||
|
||||
/**
|
||||
Allocate a new hash iterator. This API is designed to eventually be
|
||||
overloaded, and is subject to change. If the iterator is run to completion,
|
||||
|
@ -117,24 +151,7 @@ int ThashNext(int xid, lladd_hash_iterator * it, byte ** key, int * keySize, byt
|
|||
*/
|
||||
void ThashDone(int xid, lladd_hash_iterator * it);
|
||||
|
||||
Operation getLinearHashInsert();
|
||||
Operation getLinearHashRemove();
|
||||
|
||||
void LinearHashNTAInit();
|
||||
|
||||
/** Iterator that complies with the standard LLADD iterator interface.
|
||||
@todo current generic linearHashIterator implemnetation is just slapped on top of old, slow interface.
|
||||
@todo rename ThashGenericIterator to ThashIterator, and remove deprecated iterator interface...
|
||||
*/
|
||||
|
||||
//void * linearHashNTAIterator_new (void * arg);
|
||||
lladdIterator_t * ThashGenericIterator (int xid, recordid hash);
|
||||
void linearHashNTAIterator_close(int xid, void * it);
|
||||
int linearHashNTAIterator_next (int xid, void * it);
|
||||
int linearHashNTAIterator_key (int xid, void * it, byte **key);
|
||||
int linearHashNTAIterator_value(int xid, void * it, byte **value);
|
||||
|
||||
/** @todo these should be in linearHashNTA.c, but they've been moved
|
||||
/** @todo these should be in linearHashNTA.c but they've been moved
|
||||
here so that multiplexer.c can (temoprarily) implement a
|
||||
multiplexer for logical hash operations. */
|
||||
|
||||
|
@ -149,10 +166,4 @@ typedef struct {
|
|||
int valueSize;
|
||||
} linearHash_remove_arg;
|
||||
|
||||
|
||||
|
||||
//Support 16 entries by default.
|
||||
#define HASH_INIT_BITS 4
|
||||
#define HASH_FILL_FACTOR 0.7
|
||||
|
||||
#endif // __LINEAR_HASH_NTA_H
|
||||
|
|
Loading…
Reference in a new issue