souffle  2.0.2-371-g6315b36
EmptinessCheck.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file EmptinessCheck.h
12  *
13  * Defines a class for evaluating conditions in the Relational Algebra
14  * Machine.
15  *
16  ***********************************************************************/
17 
18 #pragma once
19 
20 #include "ram/Condition.h"
21 #include "ram/Node.h"
22 #include "ram/Relation.h"
23 #include "ram/utility/NodeMapper.h"
26 #include <cassert>
27 #include <memory>
28 #include <sstream>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
33 namespace souffle::ram {
34 
35 /**
36  * @class EmptinessCheck
37  * @brief Emptiness check for a relation
38  *
39  * Evaluates to true if the given relation is the empty set
40  *
41  * For example:
42  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
43  * (B = ∅)
44  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
45  */
46 class EmptinessCheck : public Condition {
47 public:
48  EmptinessCheck(std::string rel) : relation(std::move(rel)) {}
49 
50  /** @brief Get relation */
51  const std::string& getRelation() const {
52  return relation;
53  }
54 
55  EmptinessCheck* clone() const override {
56  return new EmptinessCheck(relation);
57  }
58 
59 protected:
60  void print(std::ostream& os) const override {
61  os << "(" << relation << " = ∅)";
62  }
63 
64  bool equal(const Node& node) const override {
65  const auto& other = static_cast<const EmptinessCheck&>(node);
66  return relation == other.relation;
67  }
68 
69  /** Relation */
70  const std::string relation;
71 };
72 
73 } // namespace souffle::ram
souffle::ram::EmptinessCheck::print
void print(std::ostream &os) const override
Print RAM node.
Definition: EmptinessCheck.h:67
MiscUtil.h
souffle::ram::EmptinessCheck::getRelation
const std::string & getRelation() const
Get relation.
Definition: EmptinessCheck.h:58
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::Node
Node is a superclass for all RAM IR classes.
Definition: Node.h:42
NodeMapper.h
souffle::ram::EmptinessCheck::clone
EmptinessCheck * clone() const override
Create a clone (i.e.
Definition: EmptinessCheck.h:62
ContainerUtil.h
souffle::ram::EmptinessCheck::equal
bool equal(const Node &node) const override
Equality check for two RAM nodes.
Definition: EmptinessCheck.h:71
Relation.h
Condition.h
souffle::ram::EmptinessCheck
Emptiness check for a relation.
Definition: EmptinessCheck.h:53
souffle::ram::EmptinessCheck::relation
const std::string relation
Relation.
Definition: EmptinessCheck.h:77
Node.h
std
Definition: Brie.h:3053
souffle::ram::EmptinessCheck::EmptinessCheck
EmptinessCheck(std::string rel)
Definition: EmptinessCheck.h:55
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086