]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/interval_set.h: add move_into() and new ctor
authorPiotr Dałek <piotr.dalek@corp.ovh.com>
Tue, 18 Apr 2017 11:46:11 +0000 (13:46 +0200)
committerPiotr Dałek <piotr.dalek@corp.ovh.com>
Thu, 20 Apr 2017 15:18:54 +0000 (17:18 +0200)
move_into() will be used to move data from internal (private)
std::map into other, external std::map, without exposing internal one
to public. New ctor improves moving data from external map to internal
one.

Signed-off-by: Piotr Dałek <piotr.dalek@corp.ovh.com>
src/include/interval_set.h

index 9fa2d4a8bec867c70e2be9a003afcc5cc9c88660..52c3f57ac4f1092eb54d1d3f82049e9fe7641c9e 100644 (file)
@@ -153,6 +153,13 @@ class interval_set {
   };
 
   interval_set() : _size(0) {}
+  interval_set(std::map<T,T>& other) {
+    m.swap(other);
+    _size = 0;
+    for (auto& i : m) {
+      _size += i.second;
+    }
+  }
 
   int num_intervals() const
   {
@@ -548,6 +555,14 @@ class interval_set {
     }
   }
 
+  /*
+   * Move contents of m into another std::map<T,T>. Use that instead of
+   * encoding interval_set into bufferlist then decoding it back into std::map.
+   */
+  void move_into(std::map<T,T>& other) {
+    other = std::move(m);
+  }
+
 private:
   // data
   int64_t _size;