From: hama Date: Tue, 13 Jan 2015 23:18:44 +0000 (+0100) Subject: Refactoring: ReSeqList to ReSeqArray, test of binarySearch() X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=e199707fef44317ad4beb7db81129f205465d682;p=crepublib Refactoring: ReSeqList to ReSeqArray, test of binarySearch() --- diff --git a/base/ReHashList.cpp b/base/ReHashList.cpp index abcfd02..1b32acc 100644 --- a/base/ReHashList.cpp +++ b/base/ReHashList.cpp @@ -25,14 +25,14 @@ ReArrayPosition::ReArrayPosition() : * Calling ReHashList::prior() returns the last element. */ void ReArrayPosition::behindLast(){ - m_position = (ReSeqList::Index) -2; + m_position = (ReSeqArray::Index) -2; } /** * Sets the cursor behind the last position. * Calling ReHashList::next() returns the first element. */ void ReArrayPosition::priorFirst(){ - m_position = (ReSeqList::Index) -1; + m_position = (ReSeqArray::Index) -1; } /** Constructor. @@ -81,11 +81,11 @@ int ReHashList::find(const Byte* key, size_t length) const{ */ bool ReHashList::get(const Byte* key, size_t keyLength, ReByteBuffer& value) const{ - ReSeqList::Index index; - ReSeqList::Tag tag; + ReSeqArray::Index index; + ReSeqArray::Tag tag; bool rc = m_keys.binarySearch(key, keyLength, index, &tag); if (rc){ - m_values.get(ReSeqList::Index(tag), value); + m_values.get(ReSeqArray::Index(tag), value); } return rc; } @@ -117,7 +117,7 @@ bool ReHashList::next(ReArrayPosition& position, ReByteBuffer* key, bool rc = position.m_position < m_keys.count(); if (rc){ ReByteBuffer dummy; - ReSeqList::Tag tag; + ReSeqArray::Tag tag; if (key == NULL) key = &dummy; if (! m_keys.get(++position.m_position, *key, &tag)){ @@ -146,14 +146,14 @@ void ReHashList::put(const Byte* key, size_t keyLength, keyLength = strlen(key); if (valueLength == (size_t) -1) valueLength = strlen(value); - ReSeqList::Index index; - ReSeqList::Tag tag; + ReSeqArray::Index index; + ReSeqArray::Tag tag; if (m_keys.binarySearch(key, keyLength, index, &tag)){ // replace the value: - m_values.set((ReSeqList::Index) tag, value, valueLength, 0); + m_values.set((ReSeqArray::Index) tag, value, valueLength, 0); } else { // insert a new value. - tag = (ReSeqList::Tag) m_values.count(); + tag = (ReSeqArray::Tag) m_values.count(); m_values.add(-1, value, valueLength); m_keys.add(index, key, keyLength, tag); } diff --git a/base/ReHashList.hpp b/base/ReHashList.hpp index 719f519..9eaf36c 100644 --- a/base/ReHashList.hpp +++ b/base/ReHashList.hpp @@ -15,7 +15,7 @@ public: void behindLast(); void priorFirst(); public: - ReSeqList::Index m_position; + ReSeqArray::Index m_position; bool m_forward; }; /** @brief A simple associative array. @@ -27,7 +27,7 @@ public: class ReHashList { public: typedef char Byte; - typedef ReSeqList::Sequence Sequence; + typedef ReSeqArray::Sequence Sequence; public: ReHashList(bool ignoreCase = false, int keyTagSize = 1, int contentLengthSize = 1, int keyLengthSize = 1); @@ -45,10 +45,10 @@ protected: protected: //@ Containing an array of keys. - ReSeqList m_keys; + ReSeqArray m_keys; //@ Containing the values. The tag of m_key is the index //@ in m_values. - ReSeqList m_values; + ReSeqArray m_values; }; #endif /* REHASHLIST_H_ */ diff --git a/base/ReSeqArray.cpp b/base/ReSeqArray.cpp new file mode 100644 index 0000000..e266dcd --- /dev/null +++ b/base/ReSeqArray.cpp @@ -0,0 +1,661 @@ +/* + * ReSeqArray.cpp + * + * Created on: 19.05.2010 + * Author: wk + */ + +#include "base/rebase.hpp" + +enum RELOC_SEQARRAY { + LC_SET_SIZES_1 = LC_SEQARRAY + 1, // 50201 + LC_SET_SIZES_2, // 50202 + LC_SET_SIZES_3, // 50203 +}; +/** + * @file + * Implementation: + * ReSeqArray is a storage for byte sequences. + * Each stored element is accessible by its index. + * + * A Sequence is a tuple (m_index, m_length, m_tag). + *