]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
buffer: class for efficiently calculating CRC32 of >= 1 bufferlist
authorMike Ryan <mike.ryan@inktank.com>
Tue, 31 Jul 2012 21:21:43 +0000 (14:21 -0700)
committerMike Ryan <mike.ryan@inktank.com>
Wed, 5 Sep 2012 21:19:19 +0000 (14:19 -0700)
Signed-off-by: Mike Ryan <mike.ryan@inktank.com>
src/include/buffer.h

index b2f1325eef7193b8d8d95672710c4c0cdb9d905d..f063c7ca64bc2c721fdd01b9c2e3771f4d25bf09 100644 (file)
@@ -427,10 +427,30 @@ public:
     }
 
   };
+
+  /*
+   * efficient hash of one or more bufferlists
+   */
+
+  class hash {
+    __u32 crc;
+
+  public:
+    hash() : crc(0) { }
+
+    void update(buffer::list& bl) {
+      crc = bl.crc32c(crc);
+    }
+
+    __u32 digest() {
+      return crc;
+    }
+  };
 };
 
 typedef buffer::ptr bufferptr;
 typedef buffer::list bufferlist;
+typedef buffer::hash bufferhash;
 
 
 inline bool operator>(bufferlist& l, bufferlist& r) {
@@ -497,6 +517,11 @@ inline std::ostream& operator<<(std::ostream& out, buffer::error& e)
   return out << e.what();
 }
 
+inline bufferhash& operator<<(bufferhash& l, bufferlist &r) {
+  l.update(r);
+  return l;
+}
+
 }
 
 #endif