coalescing_iterator.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (c) Meta Platforms, Inc. and affiliates.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. #include "db/coalescing_iterator.h"
  6. #include "db/wide/wide_columns_helper.h"
  7. namespace ROCKSDB_NAMESPACE {
  8. void CoalescingIterator::Coalesce(
  9. const autovector<MultiCfIteratorInfo>& items) {
  10. assert(wide_columns_.empty());
  11. MinHeap heap;
  12. for (const auto& item : items) {
  13. assert(item.iterator);
  14. for (auto& column : item.iterator->columns()) {
  15. heap.push(WideColumnWithOrder{&column, item.order});
  16. }
  17. }
  18. if (heap.empty()) {
  19. return;
  20. }
  21. wide_columns_.reserve(heap.size());
  22. auto current = heap.top();
  23. heap.pop();
  24. while (!heap.empty()) {
  25. int comparison = current.column->name().compare(heap.top().column->name());
  26. if (comparison < 0) {
  27. wide_columns_.push_back(*current.column);
  28. } else if (comparison > 0) {
  29. // Shouldn't reach here.
  30. // Current item in the heap is greater than the top item in the min heap
  31. assert(false);
  32. }
  33. current = heap.top();
  34. heap.pop();
  35. }
  36. wide_columns_.push_back(*current.column);
  37. if (WideColumnsHelper::HasDefaultColumn(wide_columns_)) {
  38. value_ = WideColumnsHelper::GetDefaultColumn(wide_columns_);
  39. }
  40. }
  41. } // namespace ROCKSDB_NAMESPACE