diff options
author | Geir Storli <geirst@yahooinc.com> | 2022-11-14 14:05:27 +0000 |
---|---|---|
committer | Geir Storli <geirst@yahooinc.com> | 2022-11-14 14:07:02 +0000 |
commit | f89b667e4e496cd45b368d69eaae9f55524638e3 (patch) | |
tree | a98e4e01dfa72aae93ccf32c91875991bdf794d6 /vespalib | |
parent | 07ba692005ba4ab27d943c66f4d4ff1b36b86832 (diff) |
Add class to track mapping from docid to [nodeid] used in hnsw index.
This class is to be used when supporting multiple vectors per document.
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/growstrategy.h | 7 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/rcuvector.hpp | 5 |
2 files changed, 9 insertions, 3 deletions
diff --git a/vespalib/src/vespa/vespalib/util/growstrategy.h b/vespalib/src/vespa/vespalib/util/growstrategy.h index c46c0b45667..02e18e44925 100644 --- a/vespalib/src/vespa/vespalib/util/growstrategy.h +++ b/vespalib/src/vespa/vespalib/util/growstrategy.h @@ -2,6 +2,7 @@ #pragma once +#include <algorithm> #include <cstddef> namespace vespalib { @@ -32,6 +33,12 @@ public: void setInitialCapacity(size_t v) noexcept { _initialCapacity = v; } void setGrowDelta(size_t v) noexcept { _growDelta = v; } + size_t calc_new_size(size_t base_size) const { + size_t delta = (base_size * getGrowFactor()) + getGrowDelta(); + size_t new_size = base_size + std::max(delta, static_cast<size_t>(1)); + return std::max(new_size, getMinimumCapacity()); + } + bool operator==(const GrowStrategy & rhs) const noexcept { return (_initialCapacity == rhs._initialCapacity && _minimumCapacity == rhs._minimumCapacity && diff --git a/vespalib/src/vespa/vespalib/util/rcuvector.hpp b/vespalib/src/vespa/vespalib/util/rcuvector.hpp index eadda8ac1e9..291738fd0c5 100644 --- a/vespalib/src/vespa/vespalib/util/rcuvector.hpp +++ b/vespalib/src/vespa/vespalib/util/rcuvector.hpp @@ -19,10 +19,9 @@ RcuVectorHeld<T>::~RcuVectorHeld() = default; template <typename T> size_t RcuVectorBase<T>::calcNewSize(size_t baseSize) const { - size_t delta = (baseSize * _growStrategy.getGrowFactor()) + _growStrategy.getGrowDelta(); - size_t newSize = baseSize + std::max(delta, static_cast<size_t>(1)); - return std::max(newSize, _growStrategy.getMinimumCapacity()); + return _growStrategy.calc_new_size(baseSize); } + template <typename T> size_t RcuVectorBase<T>::calcNewSize() const { return calcNewSize(_data.capacity()); |