summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-09-07 07:39:16 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-09-07 07:39:16 +0000
commit7092bc14ab8a99b496d1494e374e65a1734e9100 (patch)
tree40d2ee0e1a85acda1ea6ad8e2057892c33212c42 /searchlib
parent13a1c96df7ea794ceca6d1ff4d154d898cae798b (diff)
GC unused StringEnum, and avoid including config in header files.
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/stringenum.cpp76
-rw-r--r--searchlib/src/vespa/searchlib/util/stringenum.h85
7 files changed, 0 insertions, 254 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/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; }
-};
-
-}