rocksdb/db/wide/wide_columns_helper.cc
Levi Tamasi 346055a9ea Generalize and move the wide-column Find method to facilitate reuse (#13168)
Summary:
Pull Request resolved: https://github.com/facebook/rocksdb/pull/13168

The patch moves `WideColumnSerialization::Find` to `WideColumnsHelper` to facilitate reuse in non-serialization-related contexts. It also generalizes the method to take a range of iterators, and templatizes it on the iterator type to enable using it with both `const` and non-`const` iterators. Finally, it adds an assertion to ensure the method is called with a properly sorted range, which is a precondition for binary search.

Reviewed By: jaykorean

Differential Revision: D66602558

fbshipit-source-id: 841a885af31e183edeb7e3314167c55f8ed53ff1
2024-12-02 12:02:22 -08:00

44 lines
1.2 KiB
C++

// Copyright (c) Meta Platforms, Inc. and affiliates.
// This source code is licensed under both the GPLv2 (found in the
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
#include "db/wide/wide_columns_helper.h"
#include <ios>
#include "db/wide/wide_column_serialization.h"
namespace ROCKSDB_NAMESPACE {
void WideColumnsHelper::DumpWideColumns(const WideColumns& columns,
std::ostream& os, bool hex) {
if (columns.empty()) {
return;
}
const std::ios_base::fmtflags orig_flags = os.flags();
if (hex) {
os << std::hex;
}
auto it = columns.begin();
os << *it;
for (++it; it != columns.end(); ++it) {
os << ' ' << *it;
}
os.flags(orig_flags);
}
Status WideColumnsHelper::DumpSliceAsWideColumns(const Slice& value,
std::ostream& os, bool hex) {
WideColumns columns;
Slice value_copy = value;
const Status s = WideColumnSerialization::Deserialize(value_copy, columns);
if (s.ok()) {
DumpWideColumns(columns, os, hex);
}
return s;
}
} // namespace ROCKSDB_NAMESPACE