souffle  2.0.2-371-g6315b36
Public Member Functions | Protected Member Functions
souffle::ram::transform::EliminateDuplicatesTransformer Class Reference

Eliminates duplicated conjunctive terms. More...

#include <EliminateDuplicates.h>

Inheritance diagram for souffle::ram::transform::EliminateDuplicatesTransformer:
Inheritance graph
Collaboration diagram for souffle::ram::transform::EliminateDuplicatesTransformer:
Collaboration graph

Public Member Functions

bool eliminateDuplicates (Program &program)
 Eliminate duplicated conjunctive terms. More...
 
std::string getName () const override
 @Brief get name of the transformer More...
 
- Public Member Functions inherited from souffle::ram::transform::Transformer
bool apply (TranslationUnit &translationUnit)
 @Brief apply the transformer to a translation unit @Param translationUnit that will be transformed. More...
 
virtual ~Transformer ()=default
 

Protected Member Functions

bool transform (TranslationUnit &translationUnit) override
 @Brief transform the translation unit / used by apply @Param translationUnit that will be transformed. More...
 

Detailed Description

Eliminates duplicated conjunctive terms.

For example ..

QUERY
...
IF C1 /\ C2 /\ ... /\ CN
...

will be rewritten to

QUERY
...
IF C2 /\ ... /\ CN then
...

assuming that C1 and C2 are equal.

Definition at line 53 of file EliminateDuplicates.h.

Member Function Documentation

◆ eliminateDuplicates()

bool souffle::ram::transform::EliminateDuplicatesTransformer::eliminateDuplicates ( Program program)

Eliminate duplicated conjunctive terms.

Parameters
programProgram that is transformed
Returns
Flag showing whether the program has been changed by the transformation

Definition at line 35 of file EliminateDuplicates.cpp.

35  {
36  const Condition* condition = &filter->getCondition();
37  VecOwn<Condition> conds = toConjunctionList(condition);
38  bool eliminatedDuplicate = false;
39  for (std::size_t i = 0; i < conds.size(); i++) {
40  for (std::size_t j = i + 1; j < conds.size(); j++) {
41  if (*conds[i] == *conds[j]) {
42  conds.erase(conds.begin() + j);
43  i = -1;
44  eliminatedDuplicate = true;
45  break;
46  }
47  }
48  }
49  if (eliminatedDuplicate) {
50  changed = true;
51  node = mk<Filter>(
52  Own<Condition>(toCondition(conds)), souffle::clone(&filter->getOperation()));
53  }
54  }
55  node->apply(makeLambdaRamMapper(filterRewriter));
56  return node;
57  };
58  const_cast<Query*>(&query)->apply(makeLambdaRamMapper(filterRewriter));
59  });
60  return changed;
61 }
62 
63 } // namespace souffle::ram::transform

References souffle::clone(), souffle::filter(), i, j, souffle::ram::toCondition(), and souffle::ram::toConjunctionList().

Here is the call graph for this function:

◆ getName()

std::string souffle::ram::transform::EliminateDuplicatesTransformer::getName ( ) const
inlineoverridevirtual

@Brief get name of the transformer

Implements souffle::ram::transform::Transformer.

Definition at line 55 of file EliminateDuplicates.h.

62  :
63  bool transform(TranslationUnit& translationUnit) override {

◆ transform()

bool souffle::ram::transform::EliminateDuplicatesTransformer::transform ( TranslationUnit translationUnit)
inlineoverrideprotectedvirtual

@Brief transform the translation unit / used by apply @Param translationUnit that will be transformed.

@Return flag reporting whether the RAM program has changed

Implements souffle::ram::transform::Transformer.

Definition at line 67 of file EliminateDuplicates.h.


The documentation for this class was generated from the following files:
souffle::ram::toCondition
Own< Condition > toCondition(const VecOwn< Condition > &conds)
Convert list of conditions to a conjunction.
Definition: Utils.h:84
souffle::ram::toConjunctionList
VecOwn< Condition > toConjunctionList(const Condition *condition)
Convert terms of a conjunction to a list.
Definition: Utils.h:57
souffle::ram::transform::Transformer::apply
bool apply(TranslationUnit &translationUnit)
@Brief apply the transformer to a translation unit @Param translationUnit that will be transformed.
Definition: Transformer.cpp:39
j
var j
Definition: htmlJsChartistMin.h:15
souffle::ram::transform::EliminateDuplicatesTransformer::transform
bool transform(TranslationUnit &translationUnit) override
@Brief transform the translation unit / used by apply @Param translationUnit that will be transformed...
Definition: EliminateDuplicates.h:67
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
i
size_t i
Definition: json11.h:663
souffle::filter
std::vector< A > filter(std::vector< A > xs, F &&f)
Filter a vector to include certain elements.
Definition: FunctionalUtil.h:155
souffle::ram::makeLambdaRamMapper
LambdaNodeMapper< Lambda > makeLambdaRamMapper(const Lambda &lambda)
Creates a node mapper based on a corresponding lambda expression.
Definition: LambdaNodeMapper.h:67