-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a variant comparer and std::set to finish array predicate
Signed-off-by: Kunlin Yu <[email protected]>
- Loading branch information
Showing
6 changed files
with
196 additions
and
35 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* File Name: value_compare.h | ||
* | ||
* Copyright (c) 2024 IndoorSpatial | ||
* | ||
* Author: Kunlin Yu <[email protected]> | ||
* Create Date: 2024/12/31 | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
// #include <functional> | ||
|
||
#include "value.h" | ||
|
||
namespace cql2cpp { | ||
|
||
static const double kEpsilon = 1e-5; | ||
|
||
template <typename T> | ||
inline bool TypedEqual(const ValueT& a, const ValueT& b) { | ||
return std::get<T>(a) == std::get<T>(b); | ||
} | ||
|
||
inline bool isVariantEqual(const ValueT& a, const ValueT& b) { | ||
if (a.index() != b.index()) return false; | ||
|
||
if (std::holds_alternative<bool>(a)) return TypedEqual<bool>(a, b); | ||
|
||
if (std::holds_alternative<int64_t>(a)) return TypedEqual<int64_t>(a, b); | ||
|
||
if (std::holds_alternative<uint64_t>(a)) return TypedEqual<uint64_t>(a, b); | ||
|
||
if (std::holds_alternative<double>(a)) | ||
return fabs(std::get<double>(a) - std::get<double>(b)) < kEpsilon; | ||
|
||
if (std::holds_alternative<std::string>(a)) | ||
return TypedEqual<std::string>(a, b); | ||
|
||
return false; | ||
} | ||
|
||
} // namespace cql2cpp |
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,37 @@ | ||
/* | ||
* File Name: value_type.cc | ||
* | ||
* Copyright (c) 2024 IndoorSpatial | ||
* | ||
* Author: Kunlin Yu <[email protected]> | ||
* Create Date: 2024/12/31 | ||
* | ||
*/ | ||
|
||
#include <cql2cpp/value.h> | ||
|
||
namespace cql2cpp { | ||
|
||
bool ArrayElementComp::operator()(const ArrayElement& lhs, | ||
const ArrayElement& rhs) const { | ||
const auto& a = lhs.value; | ||
const auto& b = rhs.value; | ||
if (a.index() != b.index()) return std::less()(a.index(), b.index()); | ||
|
||
if (std::holds_alternative<NullStruct>(a)) return less<NullStruct>(a, b); | ||
if (std::holds_alternative<bool>(a)) return less<bool>(a, b); | ||
if (std::holds_alternative<int64_t>(a)) return less<int64_t>(a, b); | ||
if (std::holds_alternative<uint64_t>(a)) return less<uint64_t>(a, b); | ||
if (std::holds_alternative<std::string>(a)) return less<std::string>(a, b); | ||
|
||
if (std::holds_alternative<double>(a)) { | ||
double d_a = std::get<double>(a); | ||
double d_b = std::get<double>(b); | ||
if (std::fabs(d_a - d_b) < tolerance) return false; | ||
return std::less()(d_a, d_b); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} // namespace cql2cpp |