From e199707fef44317ad4beb7db81129f205465d682 Mon Sep 17 00:00:00 2001 From: hama Date: Wed, 14 Jan 2015 00:18:44 +0100 Subject: [PATCH] Refactoring: ReSeqList to ReSeqArray, test of binarySearch() --- base/ReHashList.cpp | 20 ++-- base/ReHashList.hpp | 8 +- base/{ReSeqList.cpp => ReSeqArray.cpp} | 88 +++++++++------- base/{ReSeqList.hpp => ReSeqArray.hpp} | 14 +-- base/ReStringList.cpp | 8 +- base/ReStringList.hpp | 2 +- base/baselocations.hpp | 2 +- base/rebase.hpp | 2 +- cunit/basetest.cpp | 4 +- cunit/{cuReSeqList.cpp => cuReSeqArray.cpp} | 108 ++++++++++++++++---- cunit/testall.cpp | 8 +- 11 files changed, 171 insertions(+), 93 deletions(-) rename base/{ReSeqList.cpp => ReSeqArray.cpp} (87%) rename base/{ReSeqList.hpp => ReSeqArray.hpp} (92%) rename cunit/{cuReSeqList.cpp => cuReSeqArray.cpp} (65%) 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/ReSeqList.cpp b/base/ReSeqArray.cpp similarity index 87% rename from base/ReSeqList.cpp rename to base/ReSeqArray.cpp index bc9457a..e266dcd 100644 --- a/base/ReSeqList.cpp +++ b/base/ReSeqArray.cpp @@ -1,5 +1,5 @@ /* - * ReSeqList.cpp + * ReSeqArray.cpp * * Created on: 19.05.2010 * Author: wk @@ -7,14 +7,15 @@ #include "base/rebase.hpp" -enum RELOC_SEQLIST { - LC_SET_SIZES_1 = LC_SEQLIST + 1, // 50201 +enum RELOC_SEQARRAY { + LC_SET_SIZES_1 = LC_SEQARRAY + 1, // 50201 LC_SET_SIZES_2, // 50202 LC_SET_SIZES_3, // 50203 }; /** + * @file * Implementation: - * ReSeqList is a storage for byte sequences. + * 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). @@ -29,7 +30,7 @@ enum RELOC_SEQLIST { * The tag can be omitted if there is no need. This is controlled by * m_sequSize. * - * ReSeqList contains a content buffer (m_content) and a table of + * ReSeqArray contains a content buffer (m_content) and a table of * content (m_list). *