summaryrefslogtreecommitdiffstats
path: root/searchlib/src
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-04-25 18:24:30 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-04-25 18:24:30 +0000
commitcecee3ace6e275a343ac14759bf7def8aac19ad9 (patch)
tree499bb99be88ccda40965d300b801ca92b05f3c16 /searchlib/src
parent84748cbcf542a69810b8ea45c5a992366718fdaa (diff)
- Add non-folded prefix.
- Make methods in stateless FoldedStringCompare static.
Diffstat (limited to 'searchlib/src')
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumcomparator.cpp20
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumstore.h1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/stringattribute.h1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/stringbase.h1
-rw-r--r--searchlib/src/vespa/searchlib/util/foldedstringcompare.cpp36
-rw-r--r--searchlib/src/vespa/searchlib/util/foldedstringcompare.h22
6 files changed, 43 insertions, 38 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/enumcomparator.cpp b/searchlib/src/vespa/searchlib/attribute/enumcomparator.cpp
index 335a53d3ae8..74eae51729f 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumcomparator.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/enumcomparator.cpp
@@ -5,12 +5,6 @@
namespace search {
-namespace {
-
-FoldedStringCompare _strCmp;
-
-}
-
template <typename EntryT>
EnumStoreComparator<EntryT>::EnumStoreComparator(const DataStoreType& data_store, const EntryT& fallback_value)
: ParentType(data_store, fallback_value)
@@ -53,7 +47,7 @@ EnumStoreStringComparator::EnumStoreStringComparator(const DataStoreType& data_s
_prefix_len(0)
{
if (use_prefix()) {
- _prefix_len = _strCmp.size(fallback_value);
+ _prefix_len = FoldedStringCompare::size(fallback_value);
}
}
@@ -61,17 +55,19 @@ bool
EnumStoreStringComparator::less(const vespalib::datastore::EntryRef lhs, const vespalib::datastore::EntryRef rhs) const {
return _fold
? (use_prefix()
- ? (_strCmp.compareFoldedPrefix(get(lhs), get(rhs), _prefix_len) < 0)
- : (_strCmp.compareFolded(get(lhs), get(rhs)) < 0))
- : (_strCmp.compare(get(lhs), get(rhs)) < 0);
+ ? (FoldedStringCompare::compareFoldedPrefix(get(lhs), get(rhs), _prefix_len) < 0)
+ : (FoldedStringCompare::compareFolded(get(lhs), get(rhs)) < 0))
+ : (use_prefix()
+ ? (FoldedStringCompare::comparePrefix(get(lhs), get(rhs), _prefix_len) < 0)
+ : (FoldedStringCompare::compare(get(lhs), get(rhs)) < 0));
}
bool
EnumStoreStringComparator::equal(const vespalib::datastore::EntryRef lhs, const vespalib::datastore::EntryRef rhs) const {
return _fold
- ? (_strCmp.compareFolded(get(lhs), get(rhs)) == 0)
- : (_strCmp.compare(get(lhs), get(rhs)) == 0);
+ ? (FoldedStringCompare::compareFolded(get(lhs), get(rhs)) == 0)
+ : (FoldedStringCompare::compare(get(lhs), get(rhs)) == 0);
}
template class EnumStoreComparator<int8_t>;
diff --git a/searchlib/src/vespa/searchlib/attribute/enumstore.h b/searchlib/src/vespa/searchlib/attribute/enumstore.h
index d83382e18d0..326e0916039 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumstore.h
+++ b/searchlib/src/vespa/searchlib/attribute/enumstore.h
@@ -8,7 +8,6 @@
#include "i_enum_store.h"
#include "loadedenumvalue.h"
#include <vespa/searchcommon/common/dictionary_config.h>
-#include <vespa/searchlib/util/foldedstringcompare.h>
#include <vespa/vespalib/btree/btreenode.h>
#include <vespa/vespalib/btree/btreenodeallocator.h>
#include <vespa/vespalib/btree/btree.h>
diff --git a/searchlib/src/vespa/searchlib/attribute/stringattribute.h b/searchlib/src/vespa/searchlib/attribute/stringattribute.h
index 795e4c74467..9c6d2d40f73 100644
--- a/searchlib/src/vespa/searchlib/attribute/stringattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/stringattribute.h
@@ -4,7 +4,6 @@
#include <vespa/searchlib/attribute/stringbase.h>
#include <vespa/searchlib/attribute/enumstore.h>
-#include <vespa/searchlib/util/foldedstringcompare.h>
namespace search {
diff --git a/searchlib/src/vespa/searchlib/attribute/stringbase.h b/searchlib/src/vespa/searchlib/attribute/stringbase.h
index 38fbf1b5002..b15dc597fe9 100644
--- a/searchlib/src/vespa/searchlib/attribute/stringbase.h
+++ b/searchlib/src/vespa/searchlib/attribute/stringbase.h
@@ -8,7 +8,6 @@
#include <vespa/searchlib/attribute/changevector.h>
#include <vespa/searchlib/attribute/i_enum_store.h>
#include <vespa/searchlib/attribute/loadedenumvalue.h>
-#include <vespa/searchlib/util/foldedstringcompare.h>
#include <vespa/vespalib/regex/regex.h>
#include <vespa/vespalib/text/lowercase.h>
#include <vespa/vespalib/text/utf8.h>
diff --git a/searchlib/src/vespa/searchlib/util/foldedstringcompare.cpp b/searchlib/src/vespa/searchlib/util/foldedstringcompare.cpp
index aaecd174112..234b880bf23 100644
--- a/searchlib/src/vespa/searchlib/util/foldedstringcompare.cpp
+++ b/searchlib/src/vespa/searchlib/util/foldedstringcompare.cpp
@@ -5,22 +5,22 @@
#include <vespa/vespalib/text/lowercase.h>
using vespalib::LowerCase;
-
+using vespalib::Utf8ReaderForZTS;
namespace search {
size_t
FoldedStringCompare::
-size(const char *key) const
+size(const char *key)
{
- return vespalib::Utf8ReaderForZTS::countChars(key);
+ return Utf8ReaderForZTS::countChars(key);
}
int
FoldedStringCompare::
-compareFolded(const char *key, const char *okey) const
+compareFolded(const char *key, const char *okey)
{
- vespalib::Utf8ReaderForZTS kreader(key);
- vespalib::Utf8ReaderForZTS oreader(okey);
+ Utf8ReaderForZTS kreader(key);
+ Utf8ReaderForZTS oreader(okey);
for (;;) {
uint32_t kval = LowerCase::convert(kreader.getChar());
@@ -42,10 +42,10 @@ compareFolded(const char *key, const char *okey) const
int
FoldedStringCompare::
-compareFoldedPrefix(const char *key, const char *okey, size_t prefixLen) const
+compareFoldedPrefix(const char *key, const char *okey, size_t prefixLen)
{
- vespalib::Utf8ReaderForZTS kreader(key);
- vespalib::Utf8ReaderForZTS oreader(okey);
+ Utf8ReaderForZTS kreader(key);
+ Utf8ReaderForZTS oreader(okey);
for (size_t j = 0; j < prefixLen; ++j ) {
uint32_t kval = LowerCase::convert(kreader.getChar());
@@ -64,16 +64,22 @@ compareFoldedPrefix(const char *key, const char *okey, size_t prefixLen) const
return 0;
}
-
int
FoldedStringCompare::
-compare(const char *key, const char *okey) const
+comparePrefix(const char *key, const char *okey, size_t prefixLen)
{
- int res;
+ int res = compareFoldedPrefix(key, okey, prefixLen);
+ if (res != 0) return res;
+ return strncmp(key, okey, prefixLen);
+}
+
- res = compareFolded(key, okey);
- if (res != 0)
- return res;
+int
+FoldedStringCompare::
+compare(const char *key, const char *okey)
+{
+ int res = compareFolded(key, okey);
+ if (res != 0) return res;
return strcmp(key, okey);
}
diff --git a/searchlib/src/vespa/searchlib/util/foldedstringcompare.h b/searchlib/src/vespa/searchlib/util/foldedstringcompare.h
index 5da198ddc55..76267c26801 100644
--- a/searchlib/src/vespa/searchlib/util/foldedstringcompare.h
+++ b/searchlib/src/vespa/searchlib/util/foldedstringcompare.h
@@ -9,15 +9,13 @@ namespace search {
class FoldedStringCompare
{
public:
- FoldedStringCompare() {}
-
/**
* count number of UCS-4 characters in utf8 string
*
* @param key NUL terminated utf8 string
* @return integer number of symbols in utf8 string before NUL
*/
- size_t size(const char *key) const;
+ static size_t size(const char *key);
/**
* Compare utf8 key with utf8 other key after folding both
@@ -26,7 +24,7 @@ public:
* @param okey NUL terminated utf8 string
* @return integer -1 if key < okey, 0 if key == okey, 1 if key > okey
**/
- int compareFolded(const char *key, const char *okey) const;
+ static int compareFolded(const char *key, const char *okey);
/**
* Compare utf8 key with utf8 other key after folding both.
@@ -38,9 +36,7 @@ public:
*
* @return integer -1 if key < okey, 0 if key == okey, 1 if key > okey
*/
- int compareFoldedPrefix(const char *key,
- const char *okey,
- size_t prefixLen) const;
+ static int compareFoldedPrefix(const char *key, const char *okey, size_t prefixLen);
/*
* Compare utf8 key with utf8 other key after folding both, if
@@ -50,7 +46,17 @@ public:
* @param okey NUL terminated utf8 string
* @return integer -1 if key < okey, 0 if key == okey, 1 if key > okey
*/
- int compare(const char *key, const char *okey) const;
+ static int compare(const char *key, const char *okey);
+
+ /*
+ * Compare utf8 key with utf8 other key after folding both for prefix, if
+ * they seem equal then fall back to comparing without folding.
+ *
+ * @param key NUL terminated utf8 string
+ * @param okey NUL terminated utf8 string
+ * @return integer -1 if key < okey, 0 if key == okey, 1 if key > okey
+ */
+ static int comparePrefix(const char *key, const char *okey, size_t prefixLen);
};
} // namespace search