]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
hobject_t: conditional Comparator object
authorSage Weil <sage@redhat.com>
Thu, 23 Jul 2015 20:23:14 +0000 (16:23 -0400)
committerSage Weil <sage@redhat.com>
Fri, 7 Aug 2015 14:16:04 +0000 (10:16 -0400)
This one can go either bitwise or nibblewise, depending on what you give
pass to the STL container constructor.  E.g.,

 map<hobject_t, int, hobject_t::Comparator> mymap(hobject_t::Comparator(bitwise));

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/hobject.h

index d1d9c02abac06f0a60663bfe616b1d82e4a05ebd..01f0f2dc10e3de09743eb6b66ea548c01737cf3e 100644 (file)
@@ -273,6 +273,17 @@ public:
       return cmp_bitwise(l, r) < 0;
     }
   };
+
+  struct Comparator {
+    bool bitwise;
+    Comparator(bool b) : bitwise(b) {}
+    bool operator()(const hobject_t& l, const hobject_t& r) const {
+      if (bitwise)
+       return cmp_bitwise(l, r) < 0;
+      else
+       return cmp_nibblewise(l, r) < 0;
+    }
+  };
 };
 WRITE_CLASS_ENCODER(hobject_t)
 
@@ -428,6 +439,17 @@ public:
       return cmp_bitwise(l, r) < 0;
     }
   };
+
+  struct Comparator {
+    bool bitwise;
+    Comparator(bool b) : bitwise(b) {}
+    bool operator()(const ghobject_t& l, const ghobject_t& r) const {
+         if (bitwise)
+       return cmp_bitwise(l, r) < 0;
+      else
+       return cmp_nibblewise(l, r) < 0;
+    }
+  };
 };
 WRITE_CLASS_ENCODER(ghobject_t)