summaryrefslogtreecommitdiffstats
path: root/vdslib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-11-18 10:26:01 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2016-11-18 10:26:01 +0000
commit1cac46a96fe85d5c879f14749584bd19b41b5ca5 (patch)
tree0d151d96beb8aa10e8cde6e3bde8b4c887e20ac5 /vdslib
parent0160d4213e6ebb4ddd0cdd00267d12a085afc091 (diff)
Include iostream and remove unused code.
Diffstat (limited to 'vdslib')
-rw-r--r--vdslib/src/tests/container/CMakeLists.txt1
-rw-r--r--vdslib/src/tests/container/lruordertest.cpp109
-rw-r--r--vdslib/src/vespa/vdslib/container/lruorder.h161
3 files changed, 0 insertions, 271 deletions
diff --git a/vdslib/src/tests/container/CMakeLists.txt b/vdslib/src/tests/container/CMakeLists.txt
index a869d0fd40b..6247e7f72cc 100644
--- a/vdslib/src/tests/container/CMakeLists.txt
+++ b/vdslib/src/tests/container/CMakeLists.txt
@@ -5,7 +5,6 @@ vespa_add_library(vdslib_containertest
parameterstest.cpp
searchresulttest.cpp
documentsummarytest.cpp
- lruordertest.cpp
DEPENDS
vdslib
)
diff --git a/vdslib/src/tests/container/lruordertest.cpp b/vdslib/src/tests/container/lruordertest.cpp
deleted file mode 100644
index 57e990dee29..00000000000
--- a/vdslib/src/tests/container/lruordertest.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include <vespa/vdslib/container/lruorder.h>
-#include <vespa/vdstestlib/cppunit/macros.h>
-
-namespace storage {
-namespace lib {
-
-struct LruOrderTest : public CppUnit::TestFixture {
-
- void testSimple();
-
- CPPUNIT_TEST_SUITE(LruOrderTest);
- CPPUNIT_TEST(testSimple);
- CPPUNIT_TEST_SUITE_END();
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(LruOrderTest);
-
-namespace {
-
- struct LruMap {
- struct Entry {
- std::string _value;
- LruOrder<int, LruMap>::EntryRef _order;
- };
- std::map<int, Entry> _map;
- LruOrder<int, LruMap> _order;
-
- LruMap(uint32_t size) : _order(size, *this) {}
-
- void removedFromOrder(int i) {
- _map.erase(i);
- }
-
- std::string& operator[](int i) {
- std::map<int, Entry>::iterator it(_map.find(i));
- if (it == _map.end()) {
- Entry e;
- e._order = _order.add(i);
- _map[i] = e;
- return _map[i]._value;
- } else {
- _order.moveToStart(it->second._order);
- return it->second._value;
- }
- }
-
- void remove(int i) {
- std::map<int, Entry>::iterator it(_map.find(i));
- if (it != _map.end()) {
- _order.remove(it->second._order);
- }
- }
-
- void clear() {
- _map.clear();
- _order.clear();
- }
- };
-
-}
-
-void
-LruOrderTest::testSimple()
-{
- LruMap map(3);
- CPPUNIT_ASSERT_EQUAL(std::string("[]"), map._order.toString());
-
- map[3] = "1";
- CPPUNIT_ASSERT_EQUAL(std::string("[3]"), map._order.toString());
-
- map[7] = "2";
- CPPUNIT_ASSERT_EQUAL(std::string("[7, 3]"), map._order.toString());
-
- map[9] = "3";
- CPPUNIT_ASSERT_EQUAL(std::string("[9, 7, 3]"), map._order.toString());
-
- map[13] = "4";
- CPPUNIT_ASSERT_EQUAL(std::string("[13, 9, 7]"), map._order.toString());
-
- map[9];
- CPPUNIT_ASSERT_EQUAL(std::string("[9, 13, 7]"), map._order.toString());
-
- map.remove(13);
- CPPUNIT_ASSERT_EQUAL(std::string("[9, 7]"), map._order.toString());
-
- map.clear();
- CPPUNIT_ASSERT_EQUAL(std::string("[]"), map._order.toString());
-
- map[4] = "3";
- CPPUNIT_ASSERT_EQUAL(std::string("[4]"), map._order.toString());
-
- map[2] = "4";
- CPPUNIT_ASSERT_EQUAL(std::string("[2, 4]"), map._order.toString());
-
- map[4] = "4";
- CPPUNIT_ASSERT_EQUAL(std::string("[4, 2]"), map._order.toString());
-
- map[7] = "4";
- CPPUNIT_ASSERT_EQUAL(std::string("[7, 4, 2]"), map._order.toString());
-
- map[8] = "4";
- CPPUNIT_ASSERT_EQUAL(std::string("[8, 7, 4]"), map._order.toString());
-}
-
-
-} // lib
-} // storage
diff --git a/vdslib/src/vespa/vdslib/container/lruorder.h b/vdslib/src/vespa/vdslib/container/lruorder.h
deleted file mode 100644
index 026b8189ae0..00000000000
--- a/vdslib/src/vespa/vdslib/container/lruorder.h
+++ /dev/null
@@ -1,161 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/**
- * Keep an LRU order of a given size. This is a utility class for adding a
- * secondary order to some other container.
- */
-#pragma once
-
-#include <vespa/document/util/printable.h>
-#include <vector>
-#include <vespa/vespalib/util/exceptions.h>
-
-namespace storage {
-namespace lib {
-
-template<typename Value, typename RemoveFunctor, bool staticSize = true>
-class LruOrder : public document::Printable {
-public:
- class EntryRef {
- uint32_t _entryIndex;
- public:
- EntryRef() : _entryIndex(0xffffffffu) {}
- EntryRef(uint32_t index) : _entryIndex(index) {}
- friend class LruOrder;
- };
-
-private:
- struct Entry {
- Value _value;
- bool _inUse;
- uint32_t _previous;
- uint32_t _next;
-
- public:
- Entry() : _value(), _inUse(false),
- _previous(0xffffffffu), _next(0xffffffffu) {}
- };
-
- RemoveFunctor& _removeFunctor;
- std::vector<Entry> _entries;
-
- Entry& first() { return _entries[0]; }
- Entry& last() { return _entries[1]; }
- Entry& previous(Entry& e) { return _entries[e._previous]; }
- Entry& next(Entry& e) { return _entries[e._next]; }
- uint32_t getIndex(Entry& e) { return next(e)._previous; }
- Entry& get(const EntryRef& e) { return _entries[e._entryIndex]; }
-
-public:
- LruOrder(uint32_t size, RemoveFunctor& rf)
- : _removeFunctor(rf), _entries(size + 2)
- {
- initializeOrderVector();
- }
-
- /**
- * Clear all entries. Invalidates all previously returned entry references.
- */
- void clear() {
- for (uint32_t i=2, n=_entries.size(); i<n; ++i) {
- _entries[i]._inUse = false;
- }
- }
-
- /**
- * Adds a value to the order index. Return a reference to an object that
- * can be used to refer to the value.
- */
- EntryRef add(const Value& k) {
- Entry& e(previous(last()));
- if (e._inUse) {
- _removeFunctor.removedFromOrder(e._value);
- }
- e._value = k;
- e._inUse = true;
- moveToStart(EntryRef(getIndex(e)));
- return EntryRef(getIndex(e));
- }
-
- void remove(EntryRef ref) {
- uint32_t index(ref._entryIndex);
- Entry& e(get(ref));
- e._inUse = false;
- // Remove entry from current place in sequence
- next(e)._previous = e._previous;
- previous(e)._next = e._next;
- // Make entry fit being at end.
- e._next = 1;
- e._previous = last()._previous;
- // Insert at end
- previous(last())._next = index;
- last()._previous = index;
- }
-
- /**
- * Move given entry to the start of the order.
- */
- void moveToStart(EntryRef ref) {
- uint32_t index(ref._entryIndex);
- Entry& e(get(ref));
- // Remove entry from current place in sequence
- next(e)._previous = e._previous;
- previous(e)._next = e._next;
- // Make entry fit being at start.
- e._next = first()._next;
- e._previous = 0;
- // Insert at beginning
- next(first())._previous = index;
- first()._next = index;
- }
-
-private:
- void initializeOrderVector() {
- if (_entries.size() < 1 || _entries.size() > 0xffffffffu - 3) {
- throw vespalib::IllegalArgumentException(
- "LruOrder size needs to be between 1 and 3 below max "
- "uint32_t value, as it needs to reserve 3 values.",
- VESPA_STRLOC);
- }
- _entries[0]._next = 2; // First token
- _entries[1]._previous = _entries.size() - 1; // Last token
- for (uint32_t i=2, n=_entries.size(); i<n; ++i) {
- _entries[i]._next = i+1;
- _entries[i]._previous = i-1;
- }
- // Make first and last actual elements point to first and last.
- _entries[2]._previous = 0;
- _entries[_entries.size() - 1]._next = 1;
- }
-
- void print(std::ostream& out, bool verbose, const std::string& indent) const
- {
- if (verbose) {
- out << "LruOrder(" << (staticSize ? "static" : "dynamic") << "size "
- << (_entries.size() - 2) << ") {";
- for (uint32_t i=0; i<_entries.size(); ++i) {
- const Entry& e(_entries[i]);
- out << "\n" << indent << " " << i << ": <- " << e._previous
- << " " << e._next << " -> ";
- if (e._inUse) {
- out << "(" << e._value << ")";
- }
- }
- out << "\n" << indent << "}";
- } else {
- out << "[";
- const Entry* e = &_entries[_entries[0]._next];
- if (e->_inUse) {
- out << e->_value;
- }
- while (true) {
- e = &_entries[e->_next];
- if (!e->_inUse) break;
- out << ", " << e->_value;
- }
- out << "]";
- }
- }
-};
-
-} // lib
-} // storage