summaryrefslogtreecommitdiff
path: root/src/expr/cardinality_constraint.cpp
blob: 695f5d4a3bd1a9035a0dace515b68e38e5d1f545 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/******************************************************************************
 * Top contributors (to current version):
 *   Andrew Reynolds
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
 * in the top-level source directory and their institutional affiliations.
 * All rights reserved.  See the file COPYING in the top-level source
 * directory for licensing information.
 * ****************************************************************************
 *
 * The cardinality constraint operator
 */

#include "expr/cardinality_constraint.h"

#include <iostream>

#include "expr/type_node.h"

namespace cvc5 {

CardinalityConstraint::CardinalityConstraint(const TypeNode& type,
                                             const Integer& ub)
    : d_type(new TypeNode(type)), d_ubound(ub)
{
  AlwaysAssert(type.isSort())
      << "Unexpected cardinality constraints for " << type;
}

CardinalityConstraint::CardinalityConstraint(const CardinalityConstraint& other)
    : d_type(new TypeNode(other.getType())), d_ubound(other.getUpperBound())
{
}

CardinalityConstraint::~CardinalityConstraint() {}

const TypeNode& CardinalityConstraint::getType() const { return *d_type; }

const Integer& CardinalityConstraint::getUpperBound() const { return d_ubound; }

bool CardinalityConstraint::operator==(const CardinalityConstraint& cc) const
{
  return getType() == cc.getType() && getUpperBound() == cc.getUpperBound();
}

bool CardinalityConstraint::operator!=(const CardinalityConstraint& cc) const
{
  return !(*this == cc);
}

std::ostream& operator<<(std::ostream& out, const CardinalityConstraint& cc)
{
  return out << "fmf.card(" << cc.getType() << ", " << cc.getUpperBound()
             << ')';
}

size_t CardinalityConstraintHashFunction::operator()(
    const CardinalityConstraint& cc) const
{
  return std::hash<TypeNode>()(cc.getType())
         * IntegerHashFunction()(cc.getUpperBound());
}

CombinedCardinalityConstraint::CombinedCardinalityConstraint(const Integer& ub)
    : d_ubound(ub)
{
}

CombinedCardinalityConstraint::CombinedCardinalityConstraint(
    const CombinedCardinalityConstraint& other)
    : d_ubound(other.getUpperBound())
{
}

CombinedCardinalityConstraint::~CombinedCardinalityConstraint() {}

const Integer& CombinedCardinalityConstraint::getUpperBound() const
{
  return d_ubound;
}

bool CombinedCardinalityConstraint::operator==(
    const CombinedCardinalityConstraint& cc) const
{
  return getUpperBound() == cc.getUpperBound();
}

bool CombinedCardinalityConstraint::operator!=(
    const CombinedCardinalityConstraint& cc) const
{
  return !(*this == cc);
}

std::ostream& operator<<(std::ostream& out,
                         const CombinedCardinalityConstraint& cc)
{
  return out << "fmf.card(" << cc.getUpperBound() << ')';
}

size_t CombinedCardinalityConstraintHashFunction::operator()(
    const CombinedCardinalityConstraint& cc) const
{
  return cc.getUpperBound().hash();
}

}  // namespace cvc5
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback