LcsHashTable Class Reference

LcsHashTable implements a hash table that fits the hash entries and the overflow nodes into one scratch buffer of size hashBlockSize. More...

#include <LcsHash.h>

List of all members.

Public Member Functions

 LcsHashTable ()
void init (PBuffer hashBlockInit, uint hashBlockSizeInit)
 Sets up fields in LcsHashTable.
void resetHash ()
 Resets the hash table to prepare for encoding the next page.
void resetBatch ()
 Resets the entries present in the current batch to prepare for encoding the next batch.
uint numHashEntries ()
 Returns the hash table size.
LcsHashValueNodegetNewValueNode ()
 Gives out the next hash value node for the caller to fill in interesting information.
void insertNewValueNode (uint key, LcsHashValueNode *newNode)
 Inserts a new node into the overflow chain.
void undoNewValueNode (uint key)
 Undoes the most recent insert.
LcsHashValueNodegetFirstValueNode (uint key)
 Returns the first value node having a certain key value.
LcsHashValueNodegetNextValueNode (LcsHashValueNode *pValueNode)
 Returns the next value node following a value node.
bool isFull (uint leftOvers=0)
 Checks if hash table is full.

Public Attributes

uint16_tentry
 Array indexed by the hash key value.
LcsHashValueNodevalueNodes
 List of hash value nodes.

Private Attributes

PBuffer hashBlock
 Buffer to fit the hash entry array and hash value nodes in.
uint hashBlockSize
 Size of the buffer.
uint hashTableSize
 Size of the hash table, i.e.
uint nextValueNode
 Index of next hash value node to allocate.


Detailed Description

LcsHashTable implements a hash table that fits the hash entries and the overflow nodes into one scratch buffer of size hashBlockSize.

The overflow nodes are of type LcsHashValueNode.

Definition at line 130 of file LcsHash.h.


Constructor & Destructor Documentation

LcsHashTable::LcsHashTable (  )  [inline, explicit]

Definition at line 782 of file LcsHash.h.

References hashBlock, hashTableSize, and nextValueNode.

00783 {
00784     hashBlock = NULL;
00785     hashTableSize = 0;
00786     nextValueNode = 0;
00787 }


Member Function Documentation

void LcsHashTable::init ( PBuffer  hashBlockInit,
uint  hashBlockSizeInit 
)

Sets up fields in LcsHashTable.

Parameters:
[in] hashBlockInit buffer to fit the variable length fields entry and valueNodes
[in] hashBlockSizeInit size of the buffer

Definition at line 535 of file LcsHash.cpp.

References entry, hashBlock, hashBlockSize, hashTableSize, nextValueNode, and valueNodes.

Referenced by LcsHash::init().

00536 {
00537     hashBlock     = hashBlockInit;
00538     hashBlockSize = hashBlockSizeInit;
00539     memset(hashBlock, 0, hashBlockSize);
00540 
00541     /*
00542      * hashTableSize is the size for entry array. Reserve space assuming no
00543      * one valueNode for each entry(no empty entry, and no overflow).
00544      */
00545     hashTableSize = hashBlockSize /
00546         (sizeof(uint16_t) + sizeof(LcsHashValueNode));
00547 
00548     /*
00549      * entry points to the beginning of the hashBlock
00550      */
00551     entry = (uint16_t *)hashBlock;
00552 
00553     /*
00554      * valueNodes follow the entry array.
00555      */
00556     valueNodes = reinterpret_cast<LcsHashValueNode *>(
00557         hashBlock + sizeof(uint16_t) * hashTableSize);
00558 
00559     /*
00560      * Starts from the very first valueNodes.
00561      */
00562     nextValueNode = 0;
00563 }

void LcsHashTable::resetHash (  )  [inline]

Resets the hash table to prepare for encoding the next page.

Definition at line 789 of file LcsHash.h.

References hashBlock, hashBlockSize, and nextValueNode.

Referenced by LcsHash::startNewBatch().

00790 {
00791     memset(hashBlock, 0, hashBlockSize);
00792     nextValueNode = 0;
00793 }

void LcsHashTable::resetBatch (  )  [inline]

Resets the entries present in the current batch to prepare for encoding the next batch.

Definition at line 795 of file LcsHash.h.

References nextValueNode, and valueNodes.

Referenced by LcsHash::startNewBatch().

00796 {
00797     for (int i = 0; i < nextValueNode; i++) {
00798         (&(valueNodes[i].valueOrd))->clearValueInBatch();
00799     }
00800 }

uint LcsHashTable::numHashEntries (  )  [inline]

Returns the hash table size.

Definition at line 802 of file LcsHash.h.

References hashTableSize.

Referenced by LcsHash::computeKey().

00803 {
00804     return hashTableSize;
00805 }

LcsHashValueNode * LcsHashTable::getNewValueNode (  )  [inline]

Gives out the next hash value node for the caller to fill in interesting information.

Definition at line 807 of file LcsHash.h.

References nextValueNode, and valueNodes.

Referenced by LcsHash::insert(), and LcsHash::restore().

00808 {
00809     return &(valueNodes[nextValueNode]);
00810 }

void LcsHashTable::insertNewValueNode ( uint  key,
LcsHashValueNode newNode 
) [inline]

Inserts a new node into the overflow chain.

Parameters:
[in] key hash key of the newNode
[in] newNode the new node to insert

Definition at line 812 of file LcsHash.h.

References entry, hashBlock, LcsHashValueNode::next, and nextValueNode.

Referenced by LcsHash::insert(), and LcsHash::restore().

00815 {
00816     newNode->next = (uint16_t)entry[key];
00817 
00818     /*
00819       Insert at the beginning.
00820     */
00821     entry[key] = (uint16_t)((uint8_t*)newNode - hashBlock);
00822 
00823     /*
00824       Bump up the value for the next node to give out.
00825     */
00826     nextValueNode++;
00827 }

void LcsHashTable::undoNewValueNode ( uint  key  )  [inline]

Undoes the most recent insert.

Parameters:
[in] key hash key of the node to remove. The most recently inserted value nodes is always at the beginning of the overflow list for a key

Definition at line 829 of file LcsHash.h.

References entry, hashBlock, and nextValueNode.

Referenced by LcsHash::undoInsert().

00830 {
00831     entry[key] = (uint16_t)
00832         ((LcsHashValueNode*)(hashBlock + entry[key]))->next;
00833     nextValueNode--;
00834 }

LcsHashValueNode * LcsHashTable::getFirstValueNode ( uint  key  )  [inline]

Returns the first value node having a certain key value.

Parameters:
[in] key hash key to locate
Returns:
pointer to the first value node

Definition at line 836 of file LcsHash.h.

References entry, and hashBlock.

Referenced by LcsHash::search().

00837 {
00838     uint16_t offset = entry[key];
00839 
00840     if (offset) {
00841         return (LcsHashValueNode*) (hashBlock + offset);
00842     } else {
00843         return NULL;
00844     }
00845 }

LcsHashValueNode * LcsHashTable::getNextValueNode ( LcsHashValueNode pValueNode  )  [inline]

Returns the next value node following a value node.

Parameters:
[in] pValueNode pointer to the current LcsHashValueNode
Returns:
pointer to the next value node

Definition at line 847 of file LcsHash.h.

References hashBlock, and LcsHashValueNode::next.

Referenced by LcsHash::search().

00849 {
00850     uint16_t offset = pValueNode->next;
00851 
00852     if (offset) {
00853         return (LcsHashValueNode*) (hashBlock + offset);
00854     } else {
00855         return NULL;
00856     }
00857 }

bool LcsHashTable::isFull ( uint  leftOvers = 0  )  [inline]

Checks if hash table is full.

Parameters:
[in] leftOvers additional value nodes to accommodate with a default value of 0
Returns:
true if hash table is full

Definition at line 859 of file LcsHash.h.

References hashBlock, hashBlockSize, nextValueNode, and valueNodes.

Referenced by LcsHash::insert(), LcsHash::isHashFull(), LcsHash::restore(), and LcsHash::startNewBatch().

00860 {
00861     /*
00862       need to leave one spot for sorting and leftsOvers that
00863       will be added
00864     */
00865     return ((PBuffer)(&(valueNodes[nextValueNode])
00866             + (leftOvers + 1) * sizeof(LcsHashValueNode))
00867         >= (PBuffer) (hashBlock + hashBlockSize));
00868 }


Member Data Documentation

PBuffer LcsHashTable::hashBlock [private]

Buffer to fit the hash entry array and hash value nodes in.

Definition at line 137 of file LcsHash.h.

Referenced by getFirstValueNode(), getNextValueNode(), init(), insertNewValueNode(), isFull(), LcsHashTable(), resetHash(), and undoNewValueNode().

uint LcsHashTable::hashBlockSize [private]

Size of the buffer.

Definition at line 142 of file LcsHash.h.

Referenced by init(), isFull(), and resetHash().

uint LcsHashTable::hashTableSize [private]

Size of the hash table, i.e.

size of the hash entry array.

Definition at line 147 of file LcsHash.h.

Referenced by init(), LcsHashTable(), and numHashEntries().

uint LcsHashTable::nextValueNode [private]

Index of next hash value node to allocate.

Definition at line 152 of file LcsHash.h.

Referenced by getNewValueNode(), init(), insertNewValueNode(), isFull(), LcsHashTable(), resetBatch(), resetHash(), and undoNewValueNode().

uint16_t* LcsHashTable::entry

Array indexed by the hash key value.

Each entry points(using offset) to a list of hash value nodes which have the same hash key.

Entry array is indexed by the hash kay and stores the first offsets of value nodes with the hash key. Though the offset value does not need to be uint16_t, it saves memory to use uint16_t than uint(32 or 64 bit) since the number of entries(i.e. hash table size) is limited to the numbers that can fit into a block. This also implied that the next field in LcsHashValueNode needs to be uint16_t.

Definition at line 167 of file LcsHash.h.

Referenced by getFirstValueNode(), init(), insertNewValueNode(), and undoNewValueNode().

LcsHashValueNode* LcsHashTable::valueNodes

List of hash value nodes.

Definition at line 172 of file LcsHash.h.

Referenced by LcsHash::clearFixedEntries(), getNewValueNode(), init(), isFull(), LcsCompareColKeyUsingOffsetIndex::lessThan(), LcsHash::prepareCompressedBatch(), LcsHash::prepareFixedOrVariableBatch(), and resetBatch().


The documentation for this class was generated from the following files:
Generated on Mon Jun 22 04:00:37 2009 for Fennel by  doxygen 1.5.1