summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-09-07 12:03:07 +0200
committerGitHub <noreply@github.com>2022-09-07 12:03:07 +0200
commit2123fbfb5ad5564fb853822bdb3d7f12f9e2b69e (patch)
treea57fe1732b3f36937987fa47ac492181d5100990 /searchlib
parent88a5e95f8ce908e7f15c6c2b3f08a1fb1bd2fddd (diff)
parentf04a4642e52ac293f2a4b5248bc2d1c14233f38e (diff)
Merge branch 'master' into balder/unify-access-to-ranking-assets
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/CMakeLists.txt1
-rw-r--r--searchlib/src/tests/stringenum/.gitignore8
-rw-r--r--searchlib/src/tests/stringenum/CMakeLists.txt8
-rw-r--r--searchlib/src/tests/stringenum/stringenum_test.cpp75
-rw-r--r--searchlib/src/vespa/searchlib/util/CMakeLists.txt1
-rw-r--r--searchlib/src/vespa/searchlib/util/filekit.h2
-rw-r--r--searchlib/src/vespa/searchlib/util/filesizecalculator.h3
-rw-r--r--searchlib/src/vespa/searchlib/util/fileutil.cpp18
-rw-r--r--searchlib/src/vespa/searchlib/util/fileutil.h98
-rw-r--r--searchlib/src/vespa/searchlib/util/inline.h5
-rw-r--r--searchlib/src/vespa/searchlib/util/stringenum.cpp76
-rw-r--r--searchlib/src/vespa/searchlib/util/stringenum.h85
12 files changed, 44 insertions, 336 deletions
diff --git a/searchlib/CMakeLists.txt b/searchlib/CMakeLists.txt
index f39018846a0..4d0f520f666 100644
--- a/searchlib/CMakeLists.txt
+++ b/searchlib/CMakeLists.txt
@@ -217,7 +217,6 @@ vespa_define_module(
src/tests/sort
src/tests/sortresults
src/tests/sortspec
- src/tests/stringenum
src/tests/tensor/dense_tensor_store
src/tests/tensor/direct_tensor_store
src/tests/tensor/distance_functions
diff --git a/searchlib/src/tests/stringenum/.gitignore b/searchlib/src/tests/stringenum/.gitignore
deleted file mode 100644
index 7a2f1dd659f..00000000000
--- a/searchlib/src/tests/stringenum/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-*.core
-.depend
-Makefile
-core
-core.*
-stringenum
-tmp.enum
-searchlib_stringenum_test_app
diff --git a/searchlib/src/tests/stringenum/CMakeLists.txt b/searchlib/src/tests/stringenum/CMakeLists.txt
deleted file mode 100644
index d9c5a133c88..00000000000
--- a/searchlib/src/tests/stringenum/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-vespa_add_executable(searchlib_stringenum_test_app TEST
- SOURCES
- stringenum_test.cpp
- DEPENDS
- searchlib
-)
-vespa_add_test(NAME searchlib_stringenum_test_app COMMAND searchlib_stringenum_test_app)
diff --git a/searchlib/src/tests/stringenum/stringenum_test.cpp b/searchlib/src/tests/stringenum/stringenum_test.cpp
deleted file mode 100644
index f5915db6df0..00000000000
--- a/searchlib/src/tests/stringenum/stringenum_test.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include <vespa/log/log.h>
-#include <vespa/searchlib/util/stringenum.h>
-
-LOG_SETUP("stringenum");
-#include <vespa/vespalib/testkit/testapp.h>
-
-using namespace vespalib;
-
-void
-CheckLookup( search::util::StringEnum *strEnum, const char *str, int value)
-{
- EXPECT_EQUAL(0, strcmp(str, strEnum->Lookup(value)));
- EXPECT_EQUAL(value, strEnum->Lookup(str));
-}
-
-
-TEST("test StringEnum Add and Lookup")
-{
-
- search::util::StringEnum enum1;
-
- // check number of entries
- EXPECT_EQUAL(enum1.GetNumEntries(), 0u);
-
- // check add non-duplicates
- EXPECT_EQUAL(enum1.Add("zero"), 0);
- EXPECT_EQUAL(enum1.Add("one"), 1);
- EXPECT_EQUAL(enum1.Add("two"), 2);
- EXPECT_EQUAL(enum1.Add("three"), 3);
- EXPECT_EQUAL(enum1.Add("four"), 4);
- EXPECT_EQUAL(enum1.Add("five"), 5);
- EXPECT_EQUAL(enum1.Add("six"), 6);
- EXPECT_EQUAL(enum1.Add("seven"), 7);
- EXPECT_EQUAL(enum1.Add("eight"), 8);
- EXPECT_EQUAL(enum1.Add("nine"), 9);
-
- // check add duplicates
- EXPECT_EQUAL(enum1.Add("four"), 4);
- EXPECT_EQUAL(enum1.Add("eight"), 8);
- EXPECT_EQUAL(enum1.Add("six"), 6);
- EXPECT_EQUAL(enum1.Add("seven"), 7);
- EXPECT_EQUAL(enum1.Add("one"), 1);
- EXPECT_EQUAL(enum1.Add("nine"), 9);
- EXPECT_EQUAL(enum1.Add("five"), 5);
- EXPECT_EQUAL(enum1.Add("zero"), 0);
- EXPECT_EQUAL(enum1.Add("two"), 2);
- EXPECT_EQUAL(enum1.Add("three"), 3);
-
- // check add non-duplicate
- EXPECT_EQUAL(enum1.Add("ten"), 10);
-
- // check mapping and reverse mapping
- EXPECT_EQUAL(enum1.GetNumEntries(), 11u);
- TEST_DO(CheckLookup(&enum1, "zero", 0));
- TEST_DO(CheckLookup(&enum1, "one", 1));
- TEST_DO(CheckLookup(&enum1, "two", 2));
- TEST_DO(CheckLookup(&enum1, "three", 3));
- TEST_DO(CheckLookup(&enum1, "four", 4));
- TEST_DO(CheckLookup(&enum1, "five", 5));
- TEST_DO(CheckLookup(&enum1, "six", 6));
- TEST_DO(CheckLookup(&enum1, "seven", 7));
- TEST_DO(CheckLookup(&enum1, "eight", 8));
- TEST_DO(CheckLookup(&enum1, "nine", 9));
- TEST_DO(CheckLookup(&enum1, "ten", 10));
-
- // clear
- enum1.Clear();
-
- // check number of entries
- EXPECT_EQUAL(enum1.GetNumEntries(), 0u);
-}
-
-TEST_MAIN() { TEST_RUN_ALL(); }
diff --git a/searchlib/src/vespa/searchlib/util/CMakeLists.txt b/searchlib/src/vespa/searchlib/util/CMakeLists.txt
index 619913f9ca6..0d8c8ecb2c2 100644
--- a/searchlib/src/vespa/searchlib/util/CMakeLists.txt
+++ b/searchlib/src/vespa/searchlib/util/CMakeLists.txt
@@ -17,7 +17,6 @@ vespa_add_library(searchlib_util OBJECT
rawbuf.cpp
slime_output_raw_buf_adapter.cpp
state_explorer_utils.cpp
- stringenum.cpp
url.cpp
DEPENDS
)
diff --git a/searchlib/src/vespa/searchlib/util/filekit.h b/searchlib/src/vespa/searchlib/util/filekit.h
index 9720fc1d4a2..8c994ff5866 100644
--- a/searchlib/src/vespa/searchlib/util/filekit.h
+++ b/searchlib/src/vespa/searchlib/util/filekit.h
@@ -9,8 +9,6 @@ namespace search {
class FileKit
{
-private:
- static bool _syncFiles;
public:
static bool createStamp(const vespalib::string &name);
static bool hasStamp(const vespalib::string &name);
diff --git a/searchlib/src/vespa/searchlib/util/filesizecalculator.h b/searchlib/src/vespa/searchlib/util/filesizecalculator.h
index 590893a0704..be795b84c8b 100644
--- a/searchlib/src/vespa/searchlib/util/filesizecalculator.h
+++ b/searchlib/src/vespa/searchlib/util/filesizecalculator.h
@@ -6,8 +6,7 @@
namespace vespalib { class GenericHeader; }
-namespace search
-{
+namespace search {
/*
* Class to calculate logical file size of a file based on header tags
diff --git a/searchlib/src/vespa/searchlib/util/fileutil.cpp b/searchlib/src/vespa/searchlib/util/fileutil.cpp
index 7d65e298767..cdeca9ce95c 100644
--- a/searchlib/src/vespa/searchlib/util/fileutil.cpp
+++ b/searchlib/src/vespa/searchlib/util/fileutil.cpp
@@ -115,15 +115,6 @@ void FileReaderBase::handleError(ssize_t numRead, size_t wanted)
}
}
-void FileWriterBase::handleError(ssize_t numRead, size_t wanted)
-{
- if (numRead == 0) {
- throw std::runtime_error(vespalib::make_string("Failed writing anything to file %s", _file.GetFileName()));
- } else {
- throw std::runtime_error(vespalib::make_string("Partial read(%zd of %zu) of file %s", numRead, wanted, _file.GetFileName()));
- }
-}
-
ssize_t
FileReaderBase::read(void *buf, size_t sz) {
ssize_t numRead = _file->Read(buf, sz);
@@ -133,13 +124,4 @@ FileReaderBase::read(void *buf, size_t sz) {
return numRead;
}
-ssize_t
-FileWriterBase::write(const void *buf, size_t sz) {
- ssize_t numWritten = _file.Write2(buf, sz);
- if (numWritten != ssize_t(sz)) {
- handleError(numWritten, sz);
- }
- return numWritten;
-}
-
}
diff --git a/searchlib/src/vespa/searchlib/util/fileutil.h b/searchlib/src/vespa/searchlib/util/fileutil.h
index bb74aa47484..3ebb66c5b5e 100644
--- a/searchlib/src/vespa/searchlib/util/fileutil.h
+++ b/searchlib/src/vespa/searchlib/util/fileutil.h
@@ -9,47 +9,46 @@
using vespalib::GenericHeader;
-namespace search {
+namespace search::fileutil {
+
+class LoadedBuffer
+{
+protected:
+ void * _buffer;
+ size_t _size;
+ std::unique_ptr<GenericHeader> _header;
+public:
+ LoadedBuffer(const LoadedBuffer & rhs) = delete;
+ LoadedBuffer & operator =(const LoadedBuffer & rhs) = delete;
+ typedef std::unique_ptr<LoadedBuffer> UP;
+
+ LoadedBuffer(void * buf, size_t sz)
+ : _buffer(buf),
+ _size(sz),
+ _header(nullptr)
+ { }
+
+ virtual ~LoadedBuffer() = default;
+ const void * buffer() const { return _buffer; }
+ const char * c_str() const { return static_cast<const char *>(_buffer); }
+ size_t size() const { return _size; }
+ bool empty() const { return _size == 0; }
+ size_t size(size_t elemSize) const { return _size/elemSize; }
+ const GenericHeader &getHeader() const { return *_header; }
+};
- namespace fileutil {
-
- class LoadedBuffer
- {
- protected:
- void * _buffer;
- size_t _size;
- std::unique_ptr<GenericHeader> _header;
- public:
- LoadedBuffer(const LoadedBuffer & rhs) = delete;
- LoadedBuffer & operator =(const LoadedBuffer & rhs) = delete;
- typedef std::unique_ptr<LoadedBuffer> UP;
-
- LoadedBuffer(void * buf, size_t sz)
- : _buffer(buf),
- _size(sz),
- _header(nullptr)
- { }
-
- virtual ~LoadedBuffer() { }
- const void * buffer() const { return _buffer; }
- const char * c_str() const { return static_cast<const char *>(_buffer); }
- size_t size() const { return _size; }
- bool empty() const { return _size == 0; }
- size_t size(size_t elemSize) const { return _size/elemSize; }
- const GenericHeader &getHeader() const { return *_header; }
- };
-
- class LoadedMmap : public LoadedBuffer
- {
- void * _mapBuffer;
- size_t _mapSize;
- public:
- LoadedMmap(const vespalib::string &fileName);
-
- virtual ~LoadedMmap();
- };
+class LoadedMmap : public LoadedBuffer
+{
+ void * _mapBuffer;
+ size_t _mapSize;
+public:
+ explicit LoadedMmap(const vespalib::string &fileName);
+ ~LoadedMmap() override;
+};
- }
+}
+
+namespace search {
/**
* Util class with static functions for handling attribute data files.
**/
@@ -73,29 +72,18 @@ public:
class FileReaderBase
{
public:
- FileReaderBase(FastOS_FileInterface * file) : _file(file) { }
+ explicit FileReaderBase(FastOS_FileInterface * file) : _file(file) { }
ssize_t read(void *buf, size_t sz);
private:
void handleError(ssize_t numRead, size_t wanted);
FastOS_FileInterface * _file;
};
-class FileWriterBase
-{
-public:
- FileWriterBase(FastOS_FileInterface & file) : _file(file) { }
- ssize_t write(const void *buf, size_t sz);
-protected:
- void handleError(ssize_t numWritten, size_t wanted);
-private:
- FastOS_FileInterface & _file;
-};
-
template <typename T>
class FileReader : public FileReaderBase
{
public:
- FileReader(FastOS_FileInterface * file) : FileReaderBase(file) { }
+ explicit FileReader(FastOS_FileInterface * file) : FileReaderBase(file) { }
T readHostOrder() {
T result;
read(&result, sizeof(result));
@@ -108,7 +96,7 @@ class SequentialReadModifyWriteInterface
{
public:
typedef T Type;
- virtual ~SequentialReadModifyWriteInterface() { }
+ virtual ~SequentialReadModifyWriteInterface() = default;
virtual const T & read() = 0;
virtual void write(const T & v) = 0;
virtual bool next() = 0;
@@ -124,8 +112,8 @@ private:
typedef vespalib::Array<T> Vector;
public:
SequentialReadModifyWriteVector();
- SequentialReadModifyWriteVector(size_t sz);
- ~SequentialReadModifyWriteVector();
+ explicit SequentialReadModifyWriteVector(size_t sz);
+ ~SequentialReadModifyWriteVector() override;
const T & read() override { return (*this)[_rp]; }
void write(const T & v) override { (*this)[_wp++] = v; }
bool next() override { _rp++; return _rp < Vector::size(); }
diff --git a/searchlib/src/vespa/searchlib/util/inline.h b/searchlib/src/vespa/searchlib/util/inline.h
deleted file mode 100644
index f8485f22de7..00000000000
--- a/searchlib/src/vespa/searchlib/util/inline.h
+++ /dev/null
@@ -1,5 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#pragma once
-
-#include <vespa/vespalib/util/inline.h>
-
diff --git a/searchlib/src/vespa/searchlib/util/stringenum.cpp b/searchlib/src/vespa/searchlib/util/stringenum.cpp
deleted file mode 100644
index 116e400083a..00000000000
--- a/searchlib/src/vespa/searchlib/util/stringenum.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "stringenum.h"
-#include <vespa/vespalib/stllike/hashtable.hpp>
-#include <cassert>
-
-#include <vespa/log/log.h>
-LOG_SETUP(".seachlib.util.stringenum");
-
-namespace search::util {
-
-StringEnum::StringEnum()
- : _numEntries(0),
- _mapping(),
- _reverseMap()
-{
-}
-
-StringEnum::~StringEnum() = default;
-
-void
-StringEnum::CreateReverseMapping() const
-{
- _reverseMap.resize(_numEntries);
-
- for (Map::const_iterator it = _mapping.begin();
- it != _mapping.end();
- it++)
- {
- assert(it->second >= 0);
- assert(it->second < (int)_numEntries);
- _reverseMap[it->second] = it->first.c_str();
- }
-}
-
-void
-StringEnum::Clear()
-{
- _reverseMap.clear();
- _mapping.clear();
- _numEntries = 0;
-}
-
-int
-StringEnum::Add(const char *str)
-{
- Map::const_iterator found(_mapping.find(str));
- if (found != _mapping.end()) {
- return found->second;
- } else {
- int value = _numEntries++;
- _mapping[str] = value;
- return value;
- }
-}
-
-int
-StringEnum::Lookup(const char *str) const
-{
- Map::const_iterator found(_mapping.find(str));
- return (found != _mapping.end()) ? found->second : -1;
-}
-
-const char *
-StringEnum::Lookup(uint32_t value) const
-{
- if (value >= _numEntries)
- return nullptr;
-
- if (_numEntries > _reverseMap.size())
- CreateReverseMapping();
-
- return _reverseMap[value];
-}
-
-}
diff --git a/searchlib/src/vespa/searchlib/util/stringenum.h b/searchlib/src/vespa/searchlib/util/stringenum.h
deleted file mode 100644
index 0da79db323a..00000000000
--- a/searchlib/src/vespa/searchlib/util/stringenum.h
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include <vector>
-#include <vespa/vespalib/stllike/hash_map.h>
-
-namespace search::util {
-
-/**
- * An object of this class represents an enumeration of a set of
- * strings. This is useful for mapping a set of strings into a
- * continuous range of integers.
- **/
-class StringEnum
-{
-private:
- StringEnum(const StringEnum &);
- StringEnum& operator=(const StringEnum &);
- typedef vespalib::hash_map<vespalib::string, int> Map;
-
- uint32_t _numEntries;
- Map _mapping;
- mutable std::vector<const char *> _reverseMap;
-
- /**
- * Create a reverse mapping that enables the user to map integers
- * into strings. This method is called by the Lookup(int) method.
- **/
- void CreateReverseMapping() const;
-
-public:
-
- /**
- * Create an empty string enumeration.
- **/
- StringEnum();
-
- /**
- * Destructor.
- **/
- ~StringEnum();
-
- /**
- * Discard all entries held by this object.
- **/
- void Clear();
-
- /**
- * Add a string to this enumeration. Equal strings will get the same
- * enumerated value. Different string will get different enumerated
- * values. The set of values returned from multiple invocations of
- * this method will always be a contiuous range beginning at 0.
- *
- * @return the enumerated value for the given string.
- * @param str string you want to add.
- **/
- int Add(const char *str);
-
- /**
- * Obtain the enumerated value for the given string.
- *
- * @return enumerated value or -1 if not present.
- * @param str the string to look up.
- **/
- int Lookup(const char *str) const;
-
- /**
- * Obtain the string for the given enumerated value.
- *
- * @return string or NULL if out of range.
- * @param value the enumerated value to look up.
- **/
- const char *Lookup(uint32_t value) const;
-
- /**
- * Obtain the number of entries currently present in this
- * enumeration.
- *
- * @return current number of entries.
- **/
- uint32_t GetNumEntries() const { return _numEntries; }
-};
-
-}