summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@verizonmedia.com>2019-05-24 11:06:34 +0000
committerTor Brede Vekterli <vekterli@verizonmedia.com>2019-05-24 11:52:30 +0000
commit2bf9d73149e04ee67322037ffdf686bc19ef9ac7 (patch)
tree34f876a08941c17c911ba9628a0e6f75b3359559 /vespalib
parent31f6c321cb5b130486fe267eaf8ced6878a27319 (diff)
Move `AddressSpace` from searchlib to vespalib
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/CMakeLists.txt1
-rw-r--r--vespalib/src/vespa/vespalib/util/address_space.cpp23
-rw-r--r--vespalib/src/vespa/vespalib/util/address_space.h38
3 files changed, 62 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/util/CMakeLists.txt b/vespalib/src/vespa/vespalib/util/CMakeLists.txt
index f8e06751c2a..00e232b77d4 100644
--- a/vespalib/src/vespa/vespalib/util/CMakeLists.txt
+++ b/vespalib/src/vespa/vespalib/util/CMakeLists.txt
@@ -2,6 +2,7 @@
vespa_add_library(vespalib_vespalib_util OBJECT
SOURCES
active.cpp
+ address_space.cpp
alloc.cpp
approx.cpp
array.cpp
diff --git a/vespalib/src/vespa/vespalib/util/address_space.cpp b/vespalib/src/vespa/vespalib/util/address_space.cpp
new file mode 100644
index 00000000000..058c00e835e
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/util/address_space.cpp
@@ -0,0 +1,23 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "address_space.h"
+#include <ostream>
+#include <cassert>
+
+namespace vespalib {
+
+AddressSpace::AddressSpace(size_t used_, size_t dead_, size_t limit_)
+ : _used(used_),
+ _dead(dead_),
+ _limit(limit_)
+{
+ assert(_used >= _dead);
+}
+
+std::ostream &operator << (std::ostream &out, const AddressSpace &rhs)
+{
+ return out << "used=" << rhs.used() << ", dead=" << rhs.dead() << ", limit=" << rhs.limit();
+}
+
+} // namespace vespalib
+
diff --git a/vespalib/src/vespa/vespalib/util/address_space.h b/vespalib/src/vespa/vespalib/util/address_space.h
new file mode 100644
index 00000000000..d88a5e06d80
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/util/address_space.h
@@ -0,0 +1,38 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <iosfwd>
+
+namespace vespalib {
+
+/**
+ * Represents an address space with number of bytes/entries used
+ * and the limit number of bytes/entries this address space can represent.
+ */
+class AddressSpace
+{
+private:
+ size_t _used;
+ size_t _dead;
+ size_t _limit;
+
+public:
+ AddressSpace(size_t used_, size_t dead_, size_t limit_);
+ size_t used() const { return _used; }
+ size_t dead() const { return _dead; }
+ size_t limit() const { return _limit; }
+ double usage() const {
+ if (_limit > 0) {
+ return (double)(_used - _dead) / (double)_limit;
+ }
+ return 0;
+ }
+ bool operator==(const AddressSpace &rhs) const {
+ return _used == rhs._used && _dead == rhs._dead && _limit == rhs._limit;
+ }
+};
+
+std::ostream &operator << (std::ostream &out, const AddressSpace &rhs);
+
+} // namespace search