summaryrefslogtreecommitdiffstats
path: root/src/common/CDC.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/common/CDC.cc
parentInitial commit. (diff)
downloadceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.tar.xz
ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/common/CDC.cc')
-rw-r--r--src/common/CDC.cc45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/common/CDC.cc b/src/common/CDC.cc
new file mode 100644
index 000000000..e478ba46e
--- /dev/null
+++ b/src/common/CDC.cc
@@ -0,0 +1,45 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include <random>
+
+#include "CDC.h"
+#include "FastCDC.h"
+#include "FixedCDC.h"
+
+std::unique_ptr<CDC> CDC::create(
+ const std::string& type,
+ int bits,
+ int windowbits)
+{
+ if (type == "fastcdc") {
+ return std::unique_ptr<CDC>(new FastCDC(bits, windowbits));
+ }
+ if (type == "fixed") {
+ return std::unique_ptr<CDC>(new FixedCDC(bits, windowbits));
+ }
+ return nullptr;
+}
+
+void generate_buffer(int size, bufferlist *outbl, int seed)
+{
+ std::mt19937_64 engine, engine2;
+ engine.seed(seed);
+ engine2.seed(seed);
+
+ // assemble from randomly-sized segments!
+ outbl->clear();
+ auto left = size;
+ while (left) {
+ size_t l = std::min<size_t>((engine2() & 0xffff0) + 16, left);
+ left -= l;
+ bufferptr p(l);
+ p.set_length(l);
+ char *b = p.c_str();
+ for (size_t i = 0; i < l / sizeof(uint64_t); ++i) {
+ ((ceph_le64 *)b)[i] = init_le64(engine());
+ }
+ outbl->append(p);
+ }
+}
+