diff options
-rw-r--r-- | document/src/vespa/document/annotation/spantree.cpp | 3 | ||||
-rw-r--r-- | storageapi/src/vespa/storageapi/app/getbucketid.cpp | 1 | ||||
-rw-r--r-- | vdslib/src/tests/container/CMakeLists.txt | 1 | ||||
-rw-r--r-- | vdslib/src/tests/container/lruordertest.cpp | 109 | ||||
-rw-r--r-- | vdslib/src/vespa/vdslib/container/lruorder.h | 161 | ||||
-rw-r--r-- | vespaclient/src/vespa/vespaclient/vespadoclocator/application.cpp | 7 |
6 files changed, 6 insertions, 276 deletions
diff --git a/document/src/vespa/document/annotation/spantree.cpp b/document/src/vespa/document/annotation/spantree.cpp index 041c2d387e5..f911acdd537 100644 --- a/document/src/vespa/document/annotation/spantree.cpp +++ b/document/src/vespa/document/annotation/spantree.cpp @@ -11,8 +11,7 @@ using vespalib::stringref; namespace document { -SpanTree::~SpanTree() { -} +SpanTree::~SpanTree() { } size_t SpanTree::annotate(Annotation::UP annotation_) { _annotations.push_back(*annotation_); diff --git a/storageapi/src/vespa/storageapi/app/getbucketid.cpp b/storageapi/src/vespa/storageapi/app/getbucketid.cpp index 49e6ecf6ec7..bb9130a49b8 100644 --- a/storageapi/src/vespa/storageapi/app/getbucketid.cpp +++ b/storageapi/src/vespa/storageapi/app/getbucketid.cpp @@ -2,6 +2,7 @@ #include <vespa/fastos/fastos.h> #include <vespa/document/bucket/bucketidfactory.h> #include <vespa/document/base/documentid.h> +#include <iostream> int main(int argc, char** argv) { 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 diff --git a/vespaclient/src/vespa/vespaclient/vespadoclocator/application.cpp b/vespaclient/src/vespa/vespaclient/vespadoclocator/application.cpp index 2719a4a5e29..48e837dbe03 100644 --- a/vespaclient/src/vespa/vespaclient/vespadoclocator/application.cpp +++ b/vespaclient/src/vespa/vespaclient/vespadoclocator/application.cpp @@ -1,11 +1,12 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> -LOG_SETUP("vespadoclocator"); - #include <boost/program_options.hpp> #include <vespa/config/common/exceptions.h> #include "application.h" +#include <iostream> +#include <vespa/log/log.h> +LOG_SETUP("vespadoclocator"); + bool Application::printDocumentLocation(Locator &locator, const std::string &docIdStr) |