summaryrefslogtreecommitdiffstats
path: root/searchcommon
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@yahoo-inc.com>2016-11-21 13:16:12 +0000
committerTor Egge <Tor.Egge@yahoo-inc.com>2016-11-21 13:50:54 +0000
commit8f62920d1e33c9019d9bc2ebff4ed59dd58fb9b7 (patch)
treeb330a7e699f479f7da17f1a644f3256d07d04a5b /searchcommon
parentdb47bb5d6d7a5a6deeefb4c5f94e031e1d972848 (diff)
Add compaction strategy.
Diffstat (limited to 'searchcommon')
-rw-r--r--searchcommon/src/vespa/searchcommon/attribute/config.cpp4
-rw-r--r--searchcommon/src/vespa/searchcommon/attribute/config.h5
-rw-r--r--searchcommon/src/vespa/searchcommon/common/compaction_strategy.h32
3 files changed, 41 insertions, 0 deletions
diff --git a/searchcommon/src/vespa/searchcommon/attribute/config.cpp b/searchcommon/src/vespa/searchcommon/attribute/config.cpp
index 17f758770be..ac7fe34e06b 100644
--- a/searchcommon/src/vespa/searchcommon/attribute/config.cpp
+++ b/searchcommon/src/vespa/searchcommon/attribute/config.cpp
@@ -17,6 +17,8 @@ Config::Config() :
_isFilter(false),
_fastAccess(false),
_maxInternalBlobSize(defaultMaxInternalBlobSize),
+ _growStrategy(),
+ _compactionStrategy(),
_arity(8),
_lower_bound(LLONG_MIN),
_upper_bound(LLONG_MAX),
@@ -38,6 +40,8 @@ Config::Config(BasicType bt,
_isFilter(false),
_fastAccess(false),
_maxInternalBlobSize(defaultMaxInternalBlobSize),
+ _growStrategy(),
+ _compactionStrategy(),
_arity(8),
_lower_bound(LLONG_MIN),
_upper_bound(LLONG_MAX),
diff --git a/searchcommon/src/vespa/searchcommon/attribute/config.h b/searchcommon/src/vespa/searchcommon/attribute/config.h
index b346799b2ea..d26cf1da930 100644
--- a/searchcommon/src/vespa/searchcommon/attribute/config.h
+++ b/searchcommon/src/vespa/searchcommon/attribute/config.h
@@ -5,6 +5,7 @@
#include <vespa/searchcommon/attribute/basictype.h>
#include <vespa/searchcommon/attribute/collectiontype.h>
#include <vespa/searchcommon/common/growstrategy.h>
+#include <vespa/searchcommon/common/compaction_strategy.h>
#include <vespa/vespalib/eval/value_type.h>
namespace search {
@@ -66,6 +67,7 @@ public:
bool fastAccess() const { return _fastAccess; }
const GrowStrategy & getGrowStrategy() const { return _growStrategy; }
+ const CompactionStrategy &getCompactionStrategy() const { return _compactionStrategy; }
void setHuge(bool v) { _huge = v; }
void setFastSearch(bool v) { _fastSearch = v; }
void setMaxInternalBlobSize(size_t v) { _maxInternalBlobSize = v; }
@@ -110,6 +112,7 @@ public:
void setFastAccess(bool v) { _fastAccess = v; }
Config & setGrowStrategy(const GrowStrategy &gs) { _growStrategy = gs; return *this; }
+ Config &setCompactionStrategy(const CompactionStrategy &compactionStrategy) { _compactionStrategy = compactionStrategy; return *this; }
bool operator!=(const Config &b) const { return !(operator==(b)); }
bool
@@ -125,6 +128,7 @@ public:
_fastAccess == b._fastAccess &&
_maxInternalBlobSize == b._maxInternalBlobSize &&
_growStrategy == b._growStrategy &&
+ _compactionStrategy == b._compactionStrategy &&
_arity == b._arity &&
_lower_bound == b._lower_bound &&
_upper_bound == b._upper_bound &&
@@ -144,6 +148,7 @@ private:
bool _fastAccess;
size_t _maxInternalBlobSize;
GrowStrategy _growStrategy;
+ CompactionStrategy _compactionStrategy;
uint32_t _arity;
int64_t _lower_bound;
int64_t _upper_bound;
diff --git a/searchcommon/src/vespa/searchcommon/common/compaction_strategy.h b/searchcommon/src/vespa/searchcommon/common/compaction_strategy.h
new file mode 100644
index 00000000000..b67afac8f5e
--- /dev/null
+++ b/searchcommon/src/vespa/searchcommon/common/compaction_strategy.h
@@ -0,0 +1,32 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <stdint.h>
+
+namespace search {
+
+/*
+ * Class describing compaction strategy for a compactable data structure.
+ */
+class CompactionStrategy
+{
+private:
+ double _maxDeadRatio; // Max ratio of dead bytes before compaction
+public:
+ CompactionStrategy()
+ : _maxDeadRatio(0.2)
+ {
+ }
+ CompactionStrategy(double maxDeadRatio)
+ : _maxDeadRatio(maxDeadRatio)
+ {
+ }
+ double getMaxDeadRatio() const { return _maxDeadRatio; }
+ bool operator==(const CompactionStrategy & rhs) const {
+ return _maxDeadRatio == rhs._maxDeadRatio;
+ }
+ bool operator!=(const CompactionStrategy & rhs) const { return !(operator==(rhs)); }
+};
+
+} // namespace search