7#include <unordered_map>
17template<
typename Property,
bool Ordered>
24 return id.prefix.has_value()
25 ?
murmur3_64(intptr_t(*
id.prefix) ^ intptr_t(*
id.name))
30 using map_t = std::conditional_t<Ordered, std::vector<std::pair<Schema::Identifier, Property>>,
31 std::unordered_map<Schema::Identifier, Property, IdentifierHash>>;
39 if constexpr (Ordered)
40 attrs.emplace_back(std::move(
id), std::move(P));
42 attrs.emplace_hint(it, std::move(
id), std::move(P));
49 if constexpr (Ordered) {
50 auto pred = [
this](
const auto &p) ->
bool {
return this->
find(p.first) == this->
cend(); };
51 if (not std::all_of(other.
cbegin(), other.
cend(), pred))
53 this->attrs.insert(this->
cend(), other.
begin(), other.
end());
55 this->attrs.merge(other.
attrs);
56 if (not other.
attrs.empty())
62 if constexpr (Ordered) {
63 auto pred = [&
id](
const auto &e) ->
bool {
return e.first ==
id; };
64 auto it = std::find_if(
cbegin(),
cend(), pred);
65 if (it !=
cend()
and std::find_if(std::next(it),
cend(), pred) !=
cend())
69 return attrs.find(
id);
73 void project_and_rename(
const std::vector<std::pair<Schema::Identifier, Schema::Identifier>> &old2new) {
75 for (
auto &[old_id, new_id] : old2new) {
77 auto it = old.find(old_id);
78 if (it != old.cend()) {
80 this->
add(new_id, std::move(it->second));
97template<
typename Property>
99template<
typename Property>
115 virtual std::unique_ptr<Condition>
clone()
const = 0;
124 virtual void project_and_rename(
const std::vector<std::pair<Schema::Identifier, Schema::Identifier>> &old2new) = 0;
137 std::unique_ptr<Condition>
clone()
const override {
return std::make_unique<Unsatisfiable>(); }
143 void project_and_rename(
const std::vector<std::pair<Schema::Identifier, Schema::Identifier>>&)
override { }
165 std::unique_ptr<Condition>
clone()
const override {
return std::make_unique<Sortedness>(
orders_); }
172 auto other = cast<const Sortedness>(&o);
173 if (not other)
return false;
175 for (
auto this_it = this->orders_.
begin(); this_it != this->orders_.end(); ++this_it) {
176 const auto other_it = other->orders_.find(this_it->first);
177 if (other_it == other->orders_.cend())
181 if (std::distance(this_it, this->orders_.
begin()) != std::distance(other_it, other->orders_.cbegin()))
183 if (this_it->second != other_it->second)
189 void project_and_rename(
const std::vector<std::pair<Schema::Identifier, Schema::Identifier>> &old2new)
override {
194 auto other = cast<const Sortedness>(&o);
195 if (not other)
return false;
196 return this->orders_ == other->orders_;
219 auto other = cast<const SIMD>(&o);
220 if (not other)
return false;
221 return this->num_simd_lanes_ == other->num_simd_lanes_;
224 void project_and_rename(
const std::vector<std::pair<Schema::Identifier, Schema::Identifier>>&)
override { }
227 auto other = cast<const SIMD>(&o);
228 if (not other)
return false;
229 return this->num_simd_lanes_ == other->num_simd_lanes_;
251 std::unique_ptr<Condition>
clone()
const override {
return std::make_unique<Predicated>(
predicated_); }
257 auto other = cast<const Predicated>(&o);
258 if (not other)
return false;
262 void project_and_rename(
const std::vector<std::pair<Schema::Identifier, Schema::Identifier>>&)
override { }
265 auto other = cast<const Predicated>(&o);
266 if (not other)
return false;
267 return this->predicated_ == other->predicated_;
275 std::unordered_map<std::type_index, std::unique_ptr<Condition>>
type2cond_;
281 this->type2cond_.emplace(p.first, p.second->clone());
287 template<
typename Cond>
288 requires std::is_base_of_v<Condition, Cond>
290 auto p = std::make_unique<Cond>(std::forward<Cond>(cond));
291 auto [it, res] =
type2cond_.try_emplace(
typeid(Cond), std::move(p));
293 throw invalid_argument(
"Condition of that type already exists in the ConditionSet");
296 template<
typename Cond>
297 requires std::is_base_of_v<Condition, Cond>
299 auto p = std::make_unique<Cond>(std::forward<Cond>(cond));
300 type2cond_.insert_or_assign(
typeid(Cond), std::move(p));
303 template<
typename Cond>
304 requires std::is_base_of_v<Condition, Cond>
308 return as<Cond>(*it->second);
310 template<
typename Cond>
311 requires std::is_base_of_v<Condition, Cond>
318 void project_and_rename(
const std::vector<std::pair<Schema::Identifier, Schema::Identifier>> &old2new);
uint64_t murmur3_64(uint64_t v)
This function implements the 64-bit finalizer of Murmur3_x64 by Austin Appleby, available at https://...
std::size_t operator()(const Schema::Identifier &id) const
auto find(const Schema::Identifier &id) const
std::conditional_t< Ordered, std::vector< std::pair< Schema::Identifier, Property > >, std::unordered_map< Schema::Identifier, Property, IdentifierHash > > map_t
void merge(ConditionPropertyMap &other)
void project_and_rename(const std::vector< std::pair< Schema::Identifier, Schema::Identifier > > &old2new)
void add(Schema::Identifier id, Property P)
bool operator==(const ConditionPropertyMap &other) const
std::unordered_map< std::type_index, std::unique_ptr< Condition > > type2cond_
assigns a unique identifier to each type of Condition
ConditionSet(ConditionSet &&)=default
bool operator==(const ConditionSet &other) const
static ConditionSet Make_Unsatisfiable()
void add_condition(Cond &&cond)
ConditionSet(const ConditionSet &other)
void project_and_rename(const std::vector< std::pair< Schema::Identifier, Schema::Identifier > > &old2new)
bool implied_by(const ConditionSet &other) const
ConditionSet & operator=(ConditionSet &&)=default
const Cond & get_condition() const
bool operator!=(const ConditionSet &other) const
void add_or_replace_condition(Cond &&cond)
virtual bool implied_by(const Condition &other) const =0
Checks whether this Condition is implied by other.
virtual void project_and_rename(const std::vector< std::pair< Schema::Identifier, Schema::Identifier > > &old2new)=0
Inform this Condition that Identifiers were simultaneously projected and renamed according to the map...
virtual std::unique_ptr< Condition > clone() const =0
Creates and returns a deep copy of this.
bool operator!=(const Condition &other) const
virtual bool operator==(const Condition &other) const =0
bool implied_by(const Condition &o) const override
Checks whether this Condition is implied by other.
Predicated(const Predicated &)=default
std::unique_ptr< Condition > clone() const override
Creates and returns a deep copy of this.
void project_and_rename(const std::vector< std::pair< Schema::Identifier, Schema::Identifier > > &) override
Inform this Condition that Identifiers were simultaneously projected and renamed according to the map...
Predicated(bool predicated)
Predicated(Predicated &&)=default
bool operator==(const Condition &o) const override
bool operator==(const Condition &o) const override
void project_and_rename(const std::vector< std::pair< Schema::Identifier, Schema::Identifier > > &) override
Inform this Condition that Identifiers were simultaneously projected and renamed according to the map...
std::unique_ptr< Condition > clone() const override
Creates and returns a deep copy of this.
std::size_t num_simd_lanes_
SIMD(const SIMD &)=default
SIMD(std::size_t num_simd_lanes)
bool implied_by(const Condition &o) const override
Checks whether this Condition is implied by other.
std::size_t num_simd_lanes() const
An Identifier is composed of a name and an optional prefix.
void project_and_rename(const std::vector< std::pair< Schema::Identifier, Schema::Identifier > > &old2new) override
Inform this Condition that Identifiers were simultaneously projected and renamed according to the map...
bool implied_by(const Condition &o) const override
Checks whether this Condition is implied by other.
Sortedness(const Sortedness &)=default
Sortedness(order_t orders)
const order_t & orders() const
Sortedness(Sortedness &&)=default
std::unique_ptr< Condition > clone() const override
Creates and returns a deep copy of this.
bool operator==(const Condition &o) const override
void project_and_rename(const std::vector< std::pair< Schema::Identifier, Schema::Identifier > > &) override
Inform this Condition that Identifiers were simultaneously projected and renamed according to the map...
std::unique_ptr< Condition > clone() const override
Creates and returns a deep copy of this.
Unsatisfiable(Unsatisfiable &&)=default
Unsatisfiable(const Unsatisfiable &)=default
bool operator==(const Condition &o) const override
bool implied_by(const Condition &) const override
Checks whether this Condition is implied by other.
Signals that an argument to a function of method was invalid.