diff options
author | Geir Storli <geirst@yahooinc.com> | 2022-03-29 12:55:13 +0000 |
---|---|---|
committer | Geir Storli <geirst@yahooinc.com> | 2022-03-29 12:55:13 +0000 |
commit | f18559088933e5c7309c33455fbe222fdbb476ab (patch) | |
tree | d69188573561cf8a4f386f1d45dad53c47640737 /searchcommon | |
parent | d826275fe2b951ae5cdf26bb5e295d17e2fbaf70 (diff) |
Move multivalue.h from searchlib to searchcommon.
Diffstat (limited to 'searchcommon')
-rw-r--r-- | searchcommon/src/vespa/searchcommon/attribute/multivalue.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/searchcommon/src/vespa/searchcommon/attribute/multivalue.h b/searchcommon/src/vespa/searchcommon/attribute/multivalue.h new file mode 100644 index 00000000000..780e8627b91 --- /dev/null +++ b/searchcommon/src/vespa/searchcommon/attribute/multivalue.h @@ -0,0 +1,60 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include <cstdint> + +namespace search::multivalue { + +template <typename T> +class Value { +public: + typedef T ValueType; + Value() noexcept : _v() {} + Value(T v) noexcept : _v(v) { } + Value(T v, int32_t w) noexcept : _v(v) { (void) w; } + T value() const { return _v; } + const T& value_ref() const { return _v; } + T& value_ref() { return _v; } + operator T () const { return _v; } + operator T & () { return _v; } + int32_t weight() const { return 1; } + void setWeight(int32_t w) { (void) w; } + void incWeight(int32_t w) { (void) w; } + bool operator ==(const Value<T> & rhs) const { return _v == rhs._v; } + bool operator <(const Value<T> & rhs) const { return _v < rhs._v; } + bool operator >(const Value<T> & rhs) const { return _v > rhs._v; } + static bool hasWeight() { return false; } + + static constexpr bool _hasWeight = false; +private: + T _v; +}; + +template <typename T> +class WeightedValue { +public: + typedef T ValueType; + WeightedValue() noexcept : _v(), _w(1) { } + WeightedValue(T v, int32_t w) noexcept : _v(v), _w(w) { } + T value() const { return _v; } + const T& value_ref() const { return _v; } + T& value_ref() { return _v; } + operator T () const { return _v; } + operator T & () { return _v; } + int32_t weight() const { return _w; } + void setWeight(int32_t w) { _w = w; } + void incWeight(int32_t w) { _w += w; } + + bool operator==(const WeightedValue<T> & rhs) const { return _v == rhs._v; } + bool operator <(const WeightedValue<T> & rhs) const { return _v < rhs._v; } + bool operator >(const WeightedValue<T> & rhs) const { return _v > rhs._v; } + static bool hasWeight() { return true; } + + static constexpr bool _hasWeight = true; +private: + T _v; + int32_t _w; +}; + +} |