Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GG-33927 Replace getNext with getNextSlice(s) in merge tree iterators (…
…#32)
- Loading branch information
Showing
20 changed files
with
554 additions
and
437 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright (C) GridGain Systems. All Rights Reserved. | ||
* _________ _____ __________________ _____ | ||
* __ ____/___________(_)______ /__ ____/______ ____(_)_______ | ||
* _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ | ||
* / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / | ||
* \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "DataTypes.h" | ||
|
||
#include <optional> | ||
|
||
/** Binary value for a potentially nullable column. */ | ||
using InternalSlice = std::optional<BytesView>; | ||
|
||
/** A set of binary values for whole or partial row. */ | ||
using InternalTuple = std::vector<InternalSlice>; | ||
|
||
/** | ||
* @brief Get total size of all non-null column values. | ||
* | ||
* @param tuple | ||
* @return size_t Total size of non-null values. | ||
*/ | ||
inline size_t getDataSize(const InternalTuple &tuple) { | ||
size_t size = 0; | ||
|
||
for (const InternalSlice &slice : tuple) { | ||
if (slice) | ||
size += slice->size(); | ||
} | ||
|
||
return size; | ||
} | ||
|
||
/** | ||
* @brief A whole copy of an internal tuple. | ||
* | ||
* An InternalTuple instance as such contains pointers to original values that are stored at some | ||
* other memory location. If this memory goes away then the InternalTuple instance becomes invalid. | ||
* This helper class solves the problem making a deep copy of all values into an internal buffer. | ||
*/ | ||
class InternalTupleDeepCopy : private InternalTuple { | ||
private: | ||
/** Internal buffer for values. */ | ||
std::vector<std::byte> buffer; | ||
|
||
public: | ||
InternalTupleDeepCopy() = default; | ||
|
||
InternalTupleDeepCopy(const InternalTupleDeepCopy &other) = delete; | ||
|
||
const InternalTupleDeepCopy &operator=(const InternalTupleDeepCopy &other) = delete; | ||
|
||
InternalTupleDeepCopy(const InternalTuple &tuple) { | ||
copy(tuple); | ||
} | ||
|
||
const InternalTupleDeepCopy &operator=(const InternalTuple &tuple) { | ||
clear(); | ||
|
||
buffer.clear(); | ||
|
||
copy(tuple); | ||
|
||
return *this; | ||
} | ||
|
||
// Enable access to some read-only base class members. | ||
using InternalTuple::empty; | ||
using InternalTuple::size; | ||
|
||
/** Read-only access to slices. */ | ||
const InternalSlice &operator[](size_t index) const { | ||
return InternalTuple::operator[](index); | ||
} | ||
|
||
/** Equality comparison checks all final column values via base vector comparison. */ | ||
friend bool operator==(const InternalTupleDeepCopy &lhs, const InternalTupleDeepCopy &rhs) { | ||
return static_cast<const InternalTuple &>(lhs) == static_cast<const InternalTuple &>(rhs); | ||
} | ||
|
||
private: | ||
/** Make a deep-copy of a tuple. */ | ||
void copy(const InternalTuple &tuple) { | ||
reserve(tuple.size()); | ||
|
||
buffer.reserve(getDataSize(tuple)); | ||
|
||
for (const InternalSlice &slice : tuple) { | ||
if (slice) { | ||
buffer.insert(buffer.end(), slice->begin(), slice->end()); | ||
|
||
push_back(BytesView(buffer.data() + buffer.size() - slice->size(), slice->size())); | ||
} | ||
else { | ||
push_back(std::nullopt); | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.