]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/seastore:: add binary search for lba and omap iterator search 43157/head
authorchunmei-liu <chunmei.liu@intel.com>
Mon, 13 Sep 2021 23:02:57 +0000 (16:02 -0700)
committerchunmei-liu <chunmei.liu@intel.com>
Wed, 15 Sep 2021 01:05:31 +0000 (18:05 -0700)
Signed-off-by: chunmei-liu <chunmei.liu@intel.com>
src/crimson/common/fixed_kv_node_layout.h
src/crimson/os/seastore/omap_manager/btree/string_kv_node_layout.h

index b13302881b82dedacc8f210544caa66cbc4054bb..d2b0f88495ed9a475823e4e98cf717030fadfa36 100644 (file)
@@ -3,8 +3,11 @@
 
 #pragma once
 
+#include <algorithm>
 #include <iostream>
 
+#include <boost/iterator/counting_iterator.hpp>
+
 #include "include/byteorder.h"
 
 #include "crimson/common/layout.h"
@@ -386,26 +389,32 @@ public:
   }
 
   const_iterator lower_bound(K l) const {
-    auto ret = begin();
-    for (; ret != end(); ++ret) {
-      if (ret->get_key() >= l)
-       break;
-    }
-    return ret;
+    auto it = std::lower_bound(boost::make_counting_iterator<uint16_t>(0),
+                              boost::make_counting_iterator<uint16_t>(get_size()),
+                              l,
+                              [this](uint16_t i, K key) {
+                                const_iterator iter(this, i);
+                                return iter->get_key() < key;
+                              });
+    return const_iterator(this, *it);
   }
+
   iterator lower_bound(K l) {
     const auto &tref = *this;
     return iterator(this, tref.lower_bound(l).offset);
   }
 
   const_iterator upper_bound(K l) const {
-    auto ret = begin();
-    for (; ret != end(); ++ret) {
-      if (ret->get_key() > l)
-       break;
-    }
-    return ret;
+    auto it = std::upper_bound(boost::make_counting_iterator<uint16_t>(0),
+                              boost::make_counting_iterator<uint16_t>(get_size()),
+                              l,
+                              [this](K key, uint16_t i) {
+                                const_iterator iter(this, i);
+                                return key < iter->get_key();
+                              });
+    return const_iterator(this, *it);
   }
+
   iterator upper_bound(K l) {
     const auto &tref = *this;
     return iterator(this, tref.upper_bound(l).offset);
index 92ef56f46481254e909b4ce9c1f240195fdbe399..9948a4292fd985c4876641d2d768c328728f57b4 100644 (file)
@@ -559,20 +559,14 @@ public:
   }
 
   const_iterator string_lower_bound(std::string_view str) const {
-    uint16_t start = 0, end = get_size();
-    while (start != end) {
-      unsigned mid = (start + end) / 2;
-      const_iterator iter(this, mid);
-      std::string s = iter->get_key();
-      if (s < str) {
-        start = ++mid;
-      } else if ( s > str) {
-        end = mid;
-      } else {
-        return iter;
-      }
-    }
-    return const_iterator(this, start);
+    auto it = std::lower_bound(boost::make_counting_iterator<uint16_t>(0),
+                               boost::make_counting_iterator<uint16_t>(get_size()),
+                               str,
+                               [this](uint16_t i, std::string_view str) {
+                                 const_iterator iter(this, i);
+                                 return iter->get_key() < str;
+                               });
+    return const_iterator(this, *it);
   }
 
   iterator string_lower_bound(std::string_view str) {
@@ -581,13 +575,14 @@ public:
   }
 
   const_iterator string_upper_bound(std::string_view str) const {
-    auto ret = iter_begin();
-    for (; ret != iter_end(); ++ret) {
-      std::string s = ret->get_key();
-      if (s > str)
-        break;
-    }
-    return ret;
+    auto it = std::upper_bound(boost::make_counting_iterator<uint16_t>(0),
+                               boost::make_counting_iterator<uint16_t>(get_size()),
+                               str,
+                               [this](std::string_view str, uint16_t i) {
+                                 const_iterator iter(this, i);
+                                 return str < iter->get_key();
+                               });
+    return const_iterator(this, *it);
   }
 
   iterator string_upper_bound(std::string_view str) {