2007-08-14 01:17:31 +00:00
|
|
|
/**
|
2005-01-20 21:19:47 +00:00
|
|
|
@file
|
|
|
|
|
2008-11-13 00:12:19 +00:00
|
|
|
@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.
|
2005-01-20 21:19:47 +00:00
|
|
|
|
|
|
|
The implementation uses a linear hash function, allowing the
|
|
|
|
bucket list to be resized dynamically. Because the bucket list is
|
|
|
|
built on top of arrayList, all operations are O(1), assuming the
|
|
|
|
hash function behaves correctly. Currently, linkedListNTA
|
|
|
|
implements the bucket lists.
|
|
|
|
|
|
|
|
@see nestedTopAction.h, linkedListNTA.h, arrayList.h
|
|
|
|
|
2008-11-13 00:12:19 +00:00
|
|
|
@ingroup COLLECTIONS
|
2005-01-20 21:19:47 +00:00
|
|
|
|
|
|
|
$id$
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2007-06-11 21:36:57 +00:00
|
|
|
#include <stasis/iterator.h>
|
2005-03-10 03:19:04 +00:00
|
|
|
|
2005-01-14 01:52:53 +00:00
|
|
|
#ifndef __LINEAR_HASH_NTA_H
|
|
|
|
#define __LINEAR_HASH_NTA_H
|
2008-11-13 00:12:19 +00:00
|
|
|
|
|
|
|
/** @ingroup ARRAY_LIST */
|
|
|
|
/** @{ */
|
|
|
|
|
2005-01-28 21:28:23 +00:00
|
|
|
|
|
|
|
/** 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
|
2005-01-14 01:52:53 +00:00
|
|
|
|
2008-11-13 00:12:19 +00:00
|
|
|
/** 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
|
|
|
|
|
2011-06-12 08:13:34 +00:00
|
|
|
recordid ThashCreate(int xid, int keySize, int valSize);
|
|
|
|
void ThashDelete(int xid, recordid hash);
|
2008-11-06 07:19:02 +00:00
|
|
|
/**
|
|
|
|
Insert key, value pair into hash, overwriting the existing value,
|
|
|
|
if any.
|
|
|
|
|
|
|
|
@param xid transaction id
|
|
|
|
@param hash recordid returned by ThashDelete
|
|
|
|
@param key array of bytes that define key
|
|
|
|
@param keySize length of key in bytes
|
|
|
|
@param value array of bytes
|
|
|
|
@param valueSize length of key in bytes
|
|
|
|
@return 1 if the key was defined, 0 otherwise
|
|
|
|
*/
|
2011-06-12 08:13:34 +00:00
|
|
|
int ThashInsert(int xid, recordid hash,
|
2008-11-06 07:19:02 +00:00
|
|
|
const byte* key, int keySize,
|
|
|
|
const byte* value, int valueSize);
|
|
|
|
/**
|
|
|
|
Remove existing key, value pair from hash.
|
|
|
|
|
|
|
|
@param xid transaction id
|
|
|
|
@param hash recordid returned by ThashDelete
|
|
|
|
@param key array of bytes that define key
|
|
|
|
@param keySize length of key in bytes
|
|
|
|
@return 1 if the key was defined, 0 otherwise
|
|
|
|
*/
|
2011-06-12 08:13:34 +00:00
|
|
|
int ThashRemove(int xid, recordid hash,
|
2008-11-06 07:19:02 +00:00
|
|
|
const byte* key, int keySize);
|
|
|
|
|
|
|
|
/** @return size of the value associated with key, or -1 if key not found.
|
|
|
|
(a return value of zero means the key is associated with an
|
|
|
|
empty value.) */
|
2011-06-12 08:13:34 +00:00
|
|
|
int ThashLookup(int xid, recordid hash, const byte* key, int keySize, byte ** value);
|
2008-11-13 00:12:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
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);
|
|
|
|
|
2009-03-31 05:02:54 +00:00
|
|
|
stasis_operation_impl stasis_op_impl_linear_hash_insert();
|
|
|
|
stasis_operation_impl stasis_op_impl_linear_hash_remove();
|
2008-11-13 00:12:19 +00:00
|
|
|
|
|
|
|
void LinearHashNTAInit();
|
2011-02-02 21:20:18 +00:00
|
|
|
void LinearHashNTADeinit();
|
2008-11-13 00:12:19 +00:00
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
@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
|
|
|
|
|
2005-01-21 02:13:17 +00:00
|
|
|
/**
|
|
|
|
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,
|
|
|
|
it is automatically freed. Otherwise, it should be manually freed with free().
|
|
|
|
@param xid transaction id
|
2008-11-03 21:42:42 +00:00
|
|
|
@param hash the recordid returned by ThashCreate()
|
|
|
|
@param keySize the same as the value passed into ThashCreate()
|
|
|
|
@param valueSize the same as the value passed into ThashCreate()
|
2005-03-10 03:19:04 +00:00
|
|
|
@deprecated @see interator.h. Use the linearHash implementation of that interface instead.
|
2005-01-21 02:13:17 +00:00
|
|
|
*/
|
2005-01-15 01:45:27 +00:00
|
|
|
lladd_hash_iterator * ThashIterator(int xid, recordid hash, int keySize, int valueSize);
|
2005-01-21 02:13:17 +00:00
|
|
|
/**
|
|
|
|
Obtain the next value in the hash table.
|
|
|
|
|
|
|
|
@return 1 if another value exists; 0 if the iterator is done, and has been deallocated.
|
2008-10-01 20:32:02 +00:00
|
|
|
|
|
|
|
@param xid Transaction id
|
|
|
|
@param it The iterator that will be traversed. @see ThashIterator().
|
2005-01-21 02:13:17 +00:00
|
|
|
@param key a pointer to an uninitialized pointer value. If another entry is
|
|
|
|
encountered, then the uninitialized pointer value will be set to point
|
2012-11-15 02:35:45 +00:00
|
|
|
to a malloc'ed region of memory that contains the value's key. This
|
2005-01-21 02:13:17 +00:00
|
|
|
region of memory should be manually free()'ed by the application. LLADD
|
|
|
|
normally leaves memory management to the application. However, once
|
|
|
|
hashes with variable size entries are supported, it would be extremely
|
|
|
|
difficult for the application to malloc an appropriate buffer for the
|
|
|
|
iterator, so this function call does not obey normal LLADD calling
|
|
|
|
semantics.
|
2008-10-01 20:32:02 +00:00
|
|
|
@param keySize The address of a valid integer. It's initial value is ignored,
|
|
|
|
and will be overwritten by the length of the key.
|
2005-01-21 02:13:17 +00:00
|
|
|
@param value analagous to value.
|
|
|
|
@param valueSize analagous to keySize
|
2005-03-10 03:19:04 +00:00
|
|
|
|
2008-10-01 20:32:02 +00:00
|
|
|
@deprecated Use iterator.h's linearHash implementation instead.
|
2005-01-21 02:13:17 +00:00
|
|
|
*/
|
2005-01-15 01:45:27 +00:00
|
|
|
int ThashNext(int xid, lladd_hash_iterator * it, byte ** key, int * keySize, byte** value, int * valueSize);
|
|
|
|
|
2005-02-16 04:11:14 +00:00
|
|
|
|
2005-03-10 03:19:04 +00:00
|
|
|
/** Free the hash iterator and its associated resources.
|
|
|
|
@deprecated @see interator.h. Use the linearHash implementation of that interface instead.
|
|
|
|
|
|
|
|
*/
|
2005-02-16 04:11:14 +00:00
|
|
|
void ThashDone(int xid, lladd_hash_iterator * it);
|
|
|
|
|
2008-11-13 00:12:19 +00:00
|
|
|
/** @todo these should be in linearHashNTA.c but they've been moved
|
2005-03-14 00:25:29 +00:00
|
|
|
here so that multiplexer.c can (temoprarily) implement a
|
|
|
|
multiplexer for logical hash operations. */
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
recordid hashHeader;
|
|
|
|
int keySize;
|
|
|
|
} linearHash_insert_arg;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
recordid hashHeader;
|
|
|
|
int keySize;
|
|
|
|
int valueSize;
|
|
|
|
} linearHash_remove_arg;
|
|
|
|
|
2005-01-14 01:52:53 +00:00
|
|
|
#endif // __LINEAR_HASH_NTA_H
|