summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2023-03-21 14:27:31 +0100
committerTor Egge <Tor.Egge@online.no>2023-03-21 14:27:57 +0100
commitb551696935ace371ce1358cb98e76c783c2d16c2 (patch)
tree88afea256c0041e2c062324461838a56bf183c51 /searchlib
parente563f06421b67f69246b86d7dc6b556a80e517ae (diff)
Factor out portion of SingleRawAttribute to RawAttribute.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/attribute/CMakeLists.txt1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/raw_attribute.cpp42
-rw-r--r--searchlib/src/vespa/searchlib/attribute/raw_attribute.h22
-rw-r--r--searchlib/src/vespa/searchlib/attribute/single_raw_attribute.cpp38
-rw-r--r--searchlib/src/vespa/searchlib/attribute/single_raw_attribute.h6
5 files changed, 68 insertions, 41 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt
index c966c4f81b6..db5cf43050e 100644
--- a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt
+++ b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt
@@ -105,6 +105,7 @@ vespa_add_library(searchlib_attribute OBJECT
postinglisttraits.cpp
postingstore.cpp
predicate_attribute.cpp
+ raw_attribute.cpp
raw_buffer_store.cpp
raw_buffer_store_reader.cpp
raw_buffer_store_writer.cpp
diff --git a/searchlib/src/vespa/searchlib/attribute/raw_attribute.cpp b/searchlib/src/vespa/searchlib/attribute/raw_attribute.cpp
new file mode 100644
index 00000000000..65841f59827
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/attribute/raw_attribute.cpp
@@ -0,0 +1,42 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "raw_attribute.h"
+
+namespace search::attribute {
+
+RawAttribute::RawAttribute(const vespalib::string& name, const Config& config)
+ : NotImplementedAttribute(name, config)
+{
+}
+
+RawAttribute::~RawAttribute() = default;
+
+long
+RawAttribute::onSerializeForAscendingSort(DocId doc, void* serTo, long available, const common::BlobConverter*) const
+{
+ auto raw = get_raw(doc);
+ if (available >= (long)raw.size()) {
+ memcpy(serTo, raw.data(), raw.size());
+ } else {
+ return -1;
+ }
+ return raw.size();
+}
+
+long
+RawAttribute::onSerializeForDescendingSort(DocId doc, void* serTo, long available, const common::BlobConverter*) const
+{
+ auto raw = get_raw(doc);
+ if (available >= (long)raw.size()) {
+ auto *dst = static_cast<unsigned char *>(serTo);
+ const auto * src(reinterpret_cast<const uint8_t *>(raw.data()));
+ for (size_t i(0); i < raw.size(); ++i) {
+ dst[i] = 0xff - src[i];
+ }
+ } else {
+ return -1;
+ }
+ return raw.size();
+}
+
+}
diff --git a/searchlib/src/vespa/searchlib/attribute/raw_attribute.h b/searchlib/src/vespa/searchlib/attribute/raw_attribute.h
new file mode 100644
index 00000000000..6ba709786e5
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/attribute/raw_attribute.h
@@ -0,0 +1,22 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "not_implemented_attribute.h"
+
+namespace search::attribute {
+
+/**
+ * Base class for all raw attributes.
+ */
+class RawAttribute : public NotImplementedAttribute
+{
+public:
+ RawAttribute(const vespalib::string& name, const Config& config);
+ ~RawAttribute() override;
+
+ long onSerializeForAscendingSort(DocId doc, void* serTo, long available, const common::BlobConverter*) const override;
+ long onSerializeForDescendingSort(DocId doc, void* serTo, long available, const common::BlobConverter*) const override;
+};
+
+}
diff --git a/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.cpp b/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.cpp
index 67bbd3c945d..f3be30b44d1 100644
--- a/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.cpp
@@ -20,7 +20,7 @@ constexpr uint32_t max_small_buffer_type_id = 500u;
namespace search::attribute {
SingleRawAttribute::SingleRawAttribute(const vespalib::string& name, const Config& config)
- : NotImplementedAttribute(name, config),
+ : RawAttribute(name, config),
_ref_vector(config.getGrowStrategy(), getGenerationHolder()),
_raw_store(get_memory_allocator(), max_small_buffer_type_id, mapper_grow_factor)
{
@@ -137,42 +137,6 @@ SingleRawAttribute::clearDoc(DocId docId)
return 0u;
}
-long
-SingleRawAttribute::onSerializeForAscendingSort(DocId doc, void * serTo, long available, const common::BlobConverter * bc) const
-{
- auto raw = get_raw(doc);
- vespalib::ConstBufferRef buf(raw.data(), raw.size());
- if (bc != nullptr) {
- buf = bc->convert(buf);
- }
- if (available >= (long)buf.size()) {
- memcpy(serTo, buf.data(), buf.size());
- } else {
- return -1;
- }
- return buf.size();
-}
-
-long
-SingleRawAttribute::onSerializeForDescendingSort(DocId doc, void * serTo, long available, const common::BlobConverter * bc) const
-{
- auto raw = get_raw(doc);
- vespalib::ConstBufferRef buf(raw.data(), raw.size());
- if (bc != nullptr) {
- buf = bc->convert(buf);
- }
- if (available >= (long)buf.size()) {
- auto *dst = static_cast<unsigned char *>(serTo);
- const auto * src(static_cast<const uint8_t *>(buf.data()));
- for (size_t i(0); i < buf.size(); ++i) {
- dst[i] = 0xff - src[i];
- }
- } else {
- return -1;
- }
- return buf.size();
-}
-
std::unique_ptr<AttributeSaver>
SingleRawAttribute::onInitSave(vespalib::stringref fileName)
{
diff --git a/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.h b/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.h
index fe7c873c277..681cb0397d2 100644
--- a/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/single_raw_attribute.h
@@ -2,7 +2,7 @@
#pragma once
-#include "not_implemented_attribute.h"
+#include "raw_attribute.h"
#include "raw_buffer_store.h"
#include <vespa/vespalib/util/rcuvector.h>
@@ -11,7 +11,7 @@ namespace search::attribute {
/**
* Attribute vector storing a single raw value per document.
*/
-class SingleRawAttribute : public NotImplementedAttribute
+class SingleRawAttribute : public RawAttribute
{
using AtomicEntryRef = vespalib::datastore::AtomicEntryRef;
using EntryRef = vespalib::datastore::EntryRef;
@@ -43,8 +43,6 @@ public:
}
bool isUndefined(DocId docid) const override;
uint32_t clearDoc(DocId docId) override;
- long onSerializeForAscendingSort(DocId, void *, long, const common::BlobConverter *) const override;
- long onSerializeForDescendingSort(DocId, void *, long, const common::BlobConverter *) const override;
};
}