diff options
author | Geir Storli <geirst@oath.com> | 2018-01-16 14:10:27 +0000 |
---|---|---|
committer | Geir Storli <geirst@oath.com> | 2018-01-16 14:10:27 +0000 |
commit | e549c4c805f6ef919d776e1a2d96fca4089a4b81 (patch) | |
tree | bd96da0823690a32716f6b9d6c9575ba41947e85 /searchlib | |
parent | 2d42426cbdd8573f4e15125fd82ee36a59369c3f (diff) |
Use FreeListAllocator in free list unit test and remove unused function.
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/tests/datastore/datastore/datastore_test.cpp | 52 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/datastore/datastore.h | 5 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/datastore/datastore.hpp | 25 |
3 files changed, 43 insertions, 39 deletions
diff --git a/searchlib/src/tests/datastore/datastore/datastore_test.cpp b/searchlib/src/tests/datastore/datastore/datastore_test.cpp index 7d990bc392e..8a4896ea323 100644 --- a/searchlib/src/tests/datastore/datastore/datastore_test.cpp +++ b/searchlib/src/tests/datastore/datastore/datastore_test.cpp @@ -11,6 +11,11 @@ LOG_SETUP("datastore_test"); namespace search { namespace datastore { +struct IntReclaimer +{ + static void reclaim(int *) {} +}; + class MyStore : public DataStore<int, EntryRefT<3, 2> > { private: typedef DataStore<int, EntryRefT<3, 2> > ParentType; @@ -336,35 +341,42 @@ Test::requireThatWeCanHoldAndTrimElements() EXPECT_EQUAL(0, s.getEntry(r3)); } +MyRef +toRef(Handle<int> handle) +{ + return MyRef(handle.ref); +} + void Test::requireThatWeCanUseFreeLists() { MyStore s; s.enableFreeLists(); - MyRef r1 = s.addEntry2(1); - s.holdElem(r1, 1); + auto allocator = s.freeListAllocator<IntReclaimer>(); + auto h1 = allocator.alloc(1); + s.holdElem(h1.ref, 1); s.transferHoldLists(10); - MyRef r2 = s.addEntry2(2); - s.holdElem(r2, 1); + auto h2 = allocator.alloc(2); + s.holdElem(h2.ref, 1); s.transferHoldLists(20); s.trimElemHoldList(11); - MyRef r3 = s.addEntry2(3); // reuse r1 - EXPECT_EQUAL(r1.offset(), r3.offset()); - EXPECT_EQUAL(r1.bufferId(), r3.bufferId()); - MyRef r4 = s.addEntry2(4); - EXPECT_EQUAL(r2.offset() + 1, r4.offset()); + auto h3 = allocator.alloc(3); // reuse h1.ref + EXPECT_EQUAL(toRef(h1).offset(), toRef(h3).offset()); + EXPECT_EQUAL(toRef(h1).bufferId(), toRef(h3).bufferId()); + auto h4 = allocator.alloc(4); + EXPECT_EQUAL(toRef(h2).offset() + 1, toRef(h4).offset()); s.trimElemHoldList(21); - MyRef r5 = s.addEntry2(5); // reuse r2 - EXPECT_EQUAL(r2.offset(), r5.offset()); - EXPECT_EQUAL(r2.bufferId(), r5.bufferId()); - MyRef r6 = s.addEntry2(6); - EXPECT_EQUAL(r4.offset() + 1, r6.offset()); - EXPECT_EQUAL(3, s.getEntry(r1)); - EXPECT_EQUAL(5, s.getEntry(r2)); - EXPECT_EQUAL(3, s.getEntry(r3)); - EXPECT_EQUAL(4, s.getEntry(r4)); - EXPECT_EQUAL(5, s.getEntry(r5)); - EXPECT_EQUAL(6, s.getEntry(r6)); + auto h5 = allocator.alloc(5); // reuse h2.ref + EXPECT_EQUAL(toRef(h2).offset(), toRef(h5).offset()); + EXPECT_EQUAL(toRef(h2).bufferId(), toRef(h5).bufferId()); + auto h6 = allocator.alloc(6); + EXPECT_EQUAL(toRef(h4).offset() + 1, toRef(h6).offset()); + EXPECT_EQUAL(3, s.getEntry(h1.ref)); + EXPECT_EQUAL(5, s.getEntry(h2.ref)); + EXPECT_EQUAL(3, s.getEntry(h3.ref)); + EXPECT_EQUAL(4, s.getEntry(h4.ref)); + EXPECT_EQUAL(5, s.getEntry(h5.ref)); + EXPECT_EQUAL(6, s.getEntry(h6.ref)); } void diff --git a/searchlib/src/vespa/searchlib/datastore/datastore.h b/searchlib/src/vespa/searchlib/datastore/datastore.h index 926503e5816..accff67e2fa 100644 --- a/searchlib/src/vespa/searchlib/datastore/datastore.h +++ b/searchlib/src/vespa/searchlib/datastore/datastore.h @@ -84,7 +84,6 @@ class DataStore : public DataStoreT<RefT> protected: typedef DataStoreT<RefT> ParentType; using ParentType::ensureBufferCapacity; - // using ParentType::activeBuffer; using ParentType::_activeBufferIds; using ParentType::_freeListLists; using ParentType::getBufferEntry; @@ -101,8 +100,10 @@ public: ~DataStore(); EntryRef addEntry(const EntryType &e); - EntryRef addEntry2(const EntryType &e); const EntryType &getEntry(EntryRef ref) const; + + template <typename ReclaimerT> + FreeListAllocator<EntryType, RefT, ReclaimerT> freeListAllocator(); }; extern template class DataStoreT<EntryRefT<22> >; diff --git a/searchlib/src/vespa/searchlib/datastore/datastore.hpp b/searchlib/src/vespa/searchlib/datastore/datastore.hpp index f01129803ce..74e3d9be2e0 100644 --- a/searchlib/src/vespa/searchlib/datastore/datastore.hpp +++ b/searchlib/src/vespa/searchlib/datastore/datastore.hpp @@ -163,23 +163,6 @@ DataStore<EntryType, RefT>::addEntry(const EntryType &e) } template <typename EntryType, typename RefT> -EntryRef -DataStore<EntryType, RefT>::addEntry2(const EntryType &e) -{ - BufferState::FreeListList &freeListList = _freeListLists[0]; - if (freeListList._head == NULL) - return addEntry(e); - BufferState &state = *freeListList._head; - assert(state.isActive()); - RefType ref(state.popFreeList()); - EntryType *be = - this->template - getBufferEntry<EntryType>(ref.bufferId(), ref.offset()); - *be = e; - return ref; -} - -template <typename EntryType, typename RefT> const EntryType & DataStore<EntryType, RefT>::getEntry(EntryRef ref) const { @@ -190,6 +173,14 @@ DataStore<EntryType, RefT>::getEntry(EntryRef ref) const return *be; } +template <typename EntryType, typename RefT> +template <typename ReclaimerT> +FreeListAllocator<EntryType, RefT, ReclaimerT> +DataStore<EntryType, RefT>::freeListAllocator() +{ + return FreeListAllocator<EntryType, RefT, ReclaimerT>(*this, 0); +} + extern template class DataStoreT<EntryRefT<22> >; } |