]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/interval_set: rename some types
authorKefu Chai <kchai@redhat.com>
Tue, 24 Dec 2019 07:19:33 +0000 (15:19 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 24 Dec 2019 16:25:39 +0000 (00:25 +0800)
to be consistent with STL conventions

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/include/interval_set.h

index a91ddfd50888e137b5e51a36233e74a6506a49f8..92d90cb5aa0981499f600897cd429c4d9d1cb354 100644 (file)
 template<typename T, typename Map = std::map<T,T>>
 class interval_set {
  public:
-  using value_type = T;
-  using interval_type = typename Map::value_type;
-  using interval_const_type = const interval_type;
+  using value_type = typename Map::value_type;
+  using offset_type = T;
+  using length_type = T;
+  using reference = value_type&;
+  using const_reference = const value_type&;
   using size_type = typename Map::size_type;
 
   class const_iterator;
@@ -59,26 +61,26 @@ class interval_set {
         }
 
         // Dereference this iterator to get a pair.
-        interval_type& operator*() const {
+        reference operator*() const {
           return *_iter;
         }
 
         // Return the interval start.
-        value_type get_start() const {
+        offset_type get_start() const {
           return _iter->first;
         }
 
         // Return the interval length.
-        value_type get_len() const {
+        length_type get_len() const {
           return _iter->second;
         }
 
-        value_type get_end() const {
+        offset_type get_end() const {
           return _iter->first + _iter->second;
         }
 
         // Set the interval length.
-        void set_len(const value_type& len) {
+        void set_len(const length_type& len) {
           _iter->second = len;
         }
 
@@ -127,20 +129,20 @@ class interval_set {
         }
 
         // Dereference this iterator to get a pair.
-        interval_const_type& operator*() const {
+        const_reference operator*() const {
           return *_iter;
         }
 
         // Return the interval start.
-        value_type get_start() const {
+        offset_type get_start() const {
           return _iter->first;
         }
-        value_type get_end() const {
+        offset_type get_end() const {
           return _iter->first + _iter->second;
         }
 
         // Return the interval length.
-        value_type get_len() const {
+        length_type get_len() const {
           return _iter->second;
         }
 
@@ -285,9 +287,8 @@ class interval_set {
       auto start = std::max<T>(ps->first, pl->first);
       auto en = std::min<T>(ps->first + ps->second, offset);
       ceph_assert(en > start);
-      auto i = interval_type{start, en - start};
-      mi = m.insert(mi, i);
-      _size += i.second;
+      mi = m.emplace_hint(mi, start, en - start);
+      _size += mi->second;
       if (ps->first + ps->second <= offset) {
         ++ps;
         if (ps == s.m.end())
@@ -409,12 +410,12 @@ class interval_set {
   bool empty() const {
     return m.empty();
   }
-  value_type range_start() const {
+  offset_type range_start() const {
     ceph_assert(!empty());
     auto p = m.begin();
     return p->first;
   }
-  value_type range_end() const {
+  offset_type range_end() const {
     ceph_assert(!empty());
     auto p = m.end();
     p--;
@@ -428,14 +429,14 @@ class interval_set {
     if (p == m.end()) return false;
     return true;
   }
-  value_type start_after(T i) const {
+  offset_type start_after(T i) const {
     ceph_assert(!contains(i));
     auto p = find_inc(i);
     return p->first;
   }
 
   // interval end that contains start
-  value_type end_after(T start) const {
+  offset_type end_after(T start) const {
     ceph_assert(contains(start));
     auto p = find_inc(start);
     return p->first+p->second;
@@ -613,9 +614,8 @@ class interval_set {
       T start = std::max(pa->first, pb->first);
       T en = std::min(pa->first+pa->second, pb->first+pb->second);
       ceph_assert(en > start);
-      auto i = interval_type{start, en - start};
-      mi = m.insert(mi, i);
-      _size += i.second;
+      mi = m.emplace_hint(mi, start, en - start);
+      _size += mi->second;
       if (pa->first+pa->second > pb->first+pb->second)
         pb++;
       else