17 #include "TDictionary.h"
18 #include "TTreeReaderValue.h"
33 template <
typename T,
typename...
Args>
35 std::vector<T>* vector =
new std::vector<T>(std::forward<Args>(
args)...);
36 std::function<void()> deleter = [vector] {
delete vector; };
37 return std::make_pair(
47 other.m_vector =
nullptr;
53 m_vector = other.m_vector;
55 other.m_vector =
nullptr;
66 if (m_vector !=
nullptr) {
73 AnyVector(
void* vector, std::function<
void()>&& deleter)
76 void* m_vector{
nullptr};
83 enum class Ordering { SMALLER, EQUAL, GREATER };
90 return Ordering::SMALLER;
92 return Ordering::EQUAL;
94 return Ordering::GREATER;
101 if (std::isless(x, y)) {
102 return Ordering::SMALLER;
103 }
else if (std::isgreater(x, y)) {
104 return Ordering::GREATER;
106 return Ordering::EQUAL;
122 template <
typename U>
125 if (v1.size() < v2.size()) {
126 return Ordering::SMALLER;
127 }
else if (v1.size() > v2.size()) {
128 return Ordering::GREATER;
133 for (std::size_t
i = 0;
i < v1.size(); ++
i) {
135 return Ordering::SMALLER;
136 }
else if (v1[i] > v2[i]) {
137 return Ordering::GREATER;
142 return Ordering::EQUAL;
156 void selectionSort(
const std::size_t firstIndex,
const std::size_t lastIndex,
159 for (
size_t targetIndex = firstIndex; targetIndex < lastIndex;
161 size_t minIndex = targetIndex;
162 for (std::size_t readIndex = targetIndex + 1; readIndex <= lastIndex;
164 if (
compare(readIndex, minIndex) == Ordering::SMALLER) {
165 minIndex = readIndex;
168 if (minIndex != targetIndex) {
169 swap(minIndex, targetIndex);
175 void quickSort(
const std::size_t firstIndex,
const std::size_t lastIndex,
179 static const std::size_t NON_RECURSIVE_THRESHOLD = 25;
180 if (lastIndex - firstIndex < NON_RECURSIVE_THRESHOLD) {
188 std::size_t pivotIndex = firstIndex + (lastIndex - firstIndex) / 2;
191 std::size_t splitIndex;
194 std::size_t
i = firstIndex - 1;
195 std::size_t
j = lastIndex + 1;
201 }
while (
compare(i, pivotIndex) == Ordering::SMALLER);
207 }
while (
compare(j, pivotIndex) == Ordering::GREATER);
217 if (i == pivotIndex) {
219 }
else if (j == pivotIndex) {
233 if (splitIndex - firstIndex <= lastIndex - splitIndex - 1) {
234 quickSort(firstIndex, splitIndex, compare, swap);
235 quickSort(splitIndex + 1, lastIndex, compare, swap);
237 quickSort(splitIndex + 1, lastIndex, compare, swap);
238 quickSort(firstIndex, splitIndex, compare, swap);
290 const EDataType dataType,
294 return BranchComparisonHarness::create<char>(treeMetadata,
branchName);
296 return BranchComparisonHarness::create<unsigned char>(treeMetadata,
299 return BranchComparisonHarness::create<short>(treeMetadata,
branchName);
301 return BranchComparisonHarness::create<unsigned short>(treeMetadata,
304 return BranchComparisonHarness::create<int>(treeMetadata,
branchName);
306 return BranchComparisonHarness::create<unsigned int>(treeMetadata,
309 return BranchComparisonHarness::create<long>(treeMetadata,
branchName);
311 return BranchComparisonHarness::create<unsigned long>(treeMetadata,
314 return BranchComparisonHarness::create<unsigned long long>(treeMetadata,
318 return BranchComparisonHarness::create<float>(treeMetadata,
branchName);
320 return BranchComparisonHarness::create<double>(treeMetadata,
323 return BranchComparisonHarness::create<bool>(treeMetadata,
branchName);
325 if (className.substr(0, 6) ==
"vector") {
326 std::string elementType = className.substr(7, className.size() - 8);
340 template <
typename T>
350 auto tree1DataStorage = AnyVector::create<T>();
351 auto tree2DataStorage = AnyVector::create<T>();
354 std::vector<T>& tree1Data = *tree1DataStorage.second;
355 std::vector<T>& tree2Data = *tree2DataStorage.second;
369 [&tree1Data](std::size_t
i, std::size_t
j) ->
Ordering {
370 return compare(tree1Data[i], tree1Data[j]);
372 [&tree1Data](std::size_t
i, std::size_t
j) {
376 [&tree2Data](std::size_t i, std::size_t j) ->
Ordering {
377 return compare(tree2Data[i], tree2Data[j]);
379 [&tree2Data](std::size_t
i, std::size_t
j) {
385 for (std::size_t i = 0; i < tree1Data.size(); ++
i) {
386 if (
compare(tree1Data[i], tree2Data[i]) != Ordering::EQUAL) {
395 std::cout <<
"File 1 \tFile 2" << std::endl;
396 for (std::size_t i = 0; i < tree1Data.size(); ++
i) {
397 std::cout <<
toString(tree1Data[i]) <<
" \t"
398 <<
toString(tree2Data[i]) << std::endl;
416 template <
typename T>
421 std::vector<T>& tree2Data)
446 #define CREATE_VECTOR__HANDLE_TYPE(type_name) \
447 if (elemType == #type_name) { \
448 return BranchComparisonHarness::create<std::vector<type_name>>( \
449 treeMetadata, branchName); \
460 #define CREATE_VECTOR__HANDLE_INTEGER_TYPE(integer_type_name) \
461 CREATE_VECTOR__HANDLE_TYPE(integer_type_name) \
462 else CREATE_VECTOR__HANDLE_TYPE(unsigned integer_type_name)
474 template <
typename T>
476 std::ostringstream oss;
481 template <
typename U>
483 std::ostringstream oss{
"{ "};
484 for (
const auto&
data : vector) {
485 oss <<
data <<
" \t";