m_keys.setIgnoreCase(ignoreCase);
m_keys.setSorted(true);
m_keys.setSizes(keyTagSize, keyLengthSize);
- m_keys.setSizes(0, contentLengthSize);
+ m_values.setSizes(0, contentLengthSize);
}
/** Destructor
*/
*/
void ReHashList::put(const Byte* key, size_t keyLength,
const Byte* value, size_t valueLength){
- if (keyLength == (size_t) -1)
- keyLength = strlen(key);
- if (valueLength == (size_t) -1)
- valueLength = strlen(value);
ReSeqArray::Index index;
ReSeqArray::Tag tag;
if (m_keys.binarySearch(key, keyLength, index, &tag)){
m_values.set((ReSeqArray::Index) tag, value, valueLength, 0);
} else {
// insert a new value.
- tag = (ReSeqArray::Tag) m_values.count();
- m_values.add(-1, value, valueLength);
+ tag = (ReSeqArray::Tag) m_values.add(-1, value, valueLength);
m_keys.add(index, key, keyLength, tag);
}
}
m_list.insert(rc * m_entrySize, (Byte*) &seq, m_entrySize);
} else {
if (index >= count()){
- rc = m_content.length();
+ rc = count();
m_list.append((Byte*) &seq, m_entrySize);
}else{
m_list.insert(index * m_entrySize, (Byte*) &seq, m_entrySize);
bool rc = false;
int lbound = 0;
int theCount = count();
- int ubound = theCount;
+ int ubound = theCount - 1;
int compareRc = 0;
// binary search over the sorted vector:
while(lbound <= ubound){
else {
rc = true;
index = half;
+ if (tag != NULL)
+ getLengthAndTag(seq, *tag);
break;
}
}
* @param sizeOfLength 0: no length stored (constant length, stored in
* m_commonSize).
* Otherwise: length in byte: 1, 2, 3, 4 or 5
- * @param constantSize 0 or the size of the sequence if the length is not
+ * @param constantSize INDIVIDUAL_SIZE: the length will be stored in each element
+ * 0 or the size of the sequence if the length is not
* indiviually stored. <br>
* If > 0 <code>sizeOfLength</code>must be 0!
*/
-void ReSeqArray::setSizes(int sizeOfTag, int sizeOfLength, int constantSize){
+void ReSeqArray::setSizes(int sizeOfTag, int sizeOfLength, size_t constantSize){
switch(m_sizeOfLength = sizeOfLength){
case 0:
case 1:
}
m_offsetOfLength = sizeof(Index);
m_offsetOfTag = sizeof(Index) + m_sizeOfLength;
- if (sizeOfLength > 0 && constantSize > 0){
+ if (sizeOfLength > 0 && constantSize != INDIVIDUAL_SIZE){
globalLogger()->sayF(LOG_ERROR | CAT_LIB, LC_SET_SIZES_1,
i18n("collision of sizeOfLength $1 and constantSize $2"))
- .arg(sizeOfLength).arg(constantSize).end();
+ .arg(sizeOfLength).arg((int) constantSize).end();
constantSize = 0;
}
m_commonSize = constantSize;
ReSeqArray(const ReSeqArray& source);
ReSeqArray& operator = (const ReSeqArray& source);
public:
- Index add(Index index, const Byte* source, size_t sourceLength, Tag tag = 0);
+ Index add(Index index, const Byte* source, size_t sourceLength,
+ Tag tag = 0);
bool binarySearch(const Byte* toFind, int length, Index& index,
- Tag* tag = NULL) const;
+ Tag* tag = NULL) const;
void clear();
int compare(Index index1, Index index2);
/** @brief Returns the count of defined entries in the list.
}
void remove(Index index);
void set(Index index, const Byte* source, size_t sourceLength, Tag tag);
- void setSizes(int sizeOfTag, int sizeOfLength, int constantLength = 0);
+ void setSizes(int sizeOfTag, int sizeOfLength, size_t constantLength = INDIVIDUAL_SIZE);
void setSorted(bool onNotOff);
void setIgnoreCase(bool onNotOff);
void sort();
return m_content.buffer();
}
friend class ReHashList;
- friend class ReStringList;
/** @brief Returns the info of an entry of the list.
* @param index The index of the wanted entry.
* @return The pointer of the entry.
list.add(ix, value.str(), -1, (ReSeqArray::Tag) ix*10);
}
for (int ix = 0; ix <= count; ix++){
+ if (count == 2 && ix == 2)
+ ix = 2;
value.setLength(2);
value.buffer()[0] = 'a' + ix;
value.buffer()[1] = 'a';
list.add(-1, "abc", -1, 300);
list.add(-1, "abc", -1, 350);
list.add(-1, "cde", -1, 400);
- log(false, "unsorted:");
- list.dump(stdout);
+ //log(false, "unsorted:");
+ //list.dump(stdout);
list.setSorted(true);
- log(false, "sorted:");
- list.dump(stdout);
+ //log(false, "sorted:");
+ //list.dump(stdout);
checkElement(list, 0U, "AbC", 350);
checkElement(list, 1U, "AbC", 300);
checkElement(list, 2U, "AbCd", 100);
ReByteBuffer value, expectedValue;
list.add(-1, "bcd", -1, 200);
list.add(0, "abc", -1, 100);
- list.dump(stdout);
+ // list.dump(stdout);
checkEqu(0U, list.find("AbC", -1));
checkEqu(1U, list.find("BCD", -1));
}
if (expectedTag != tag)
checkEqu(expectedTag, tag);
}
- list.dump(stdout);
+ //list.dump(stdout);
expectedValue.setLength(0);
for (size_t ix = 0; ix < maxIx; ix++){
expectedTag = -1;
void testBase(){
extern void testReHashList(void);
- //testReHashList();
- extern void testReSeqArray();
- testReSeqArray();
+ testReHashList();
+
extern void testReTestUnit();
// testReTestUnit();
extern void testReByteBuffer();