mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-26 16:30:56 +00:00
1e63fc9925
Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/11823 Similarly to https://github.com/facebook/rocksdb/pull/11813, the patch is a small refactoring that eliminates some copy-paste around sorting the columns of entities by column name. Reviewed By: jaykorean Differential Revision: D49195504 fbshipit-source-id: d48c9f290e3203f838cc5949856c469ecf730008
47 lines
1.3 KiB
C++
47 lines
1.3 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 <algorithm>
|
|
|
|
#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;
|
|
}
|
|
if (hex) {
|
|
os << std::hex;
|
|
}
|
|
auto it = columns.begin();
|
|
os << *it;
|
|
for (++it; it != columns.end(); ++it) {
|
|
os << ' ' << *it;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
void WideColumnsHelper::SortColumns(WideColumns& columns) {
|
|
std::sort(columns.begin(), columns.end(),
|
|
[](const WideColumn& lhs, const WideColumn& rhs) {
|
|
return lhs.name().compare(rhs.name()) < 0;
|
|
});
|
|
}
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|