1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* The cardinality constraint operator |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "expr/cardinality_constraint.h" |
17 |
|
|
18 |
|
#include <iostream> |
19 |
|
|
20 |
|
#include "expr/type_node.h" |
21 |
|
|
22 |
|
namespace cvc5 { |
23 |
|
|
24 |
1146 |
CardinalityConstraint::CardinalityConstraint(const TypeNode& type, |
25 |
1146 |
const Integer& ub) |
26 |
1146 |
: d_type(new TypeNode(type)), d_ubound(ub) |
27 |
|
{ |
28 |
1146 |
AlwaysAssert(type.isSort()) |
29 |
|
<< "Unexpected cardinality constraints for " << type; |
30 |
1146 |
} |
31 |
|
|
32 |
909 |
CardinalityConstraint::CardinalityConstraint(const CardinalityConstraint& other) |
33 |
909 |
: d_type(new TypeNode(other.getType())), d_ubound(other.getUpperBound()) |
34 |
|
{ |
35 |
909 |
} |
36 |
|
|
37 |
2055 |
CardinalityConstraint::~CardinalityConstraint() {} |
38 |
|
|
39 |
30594 |
const TypeNode& CardinalityConstraint::getType() const { return *d_type; } |
40 |
|
|
41 |
18947 |
const Integer& CardinalityConstraint::getUpperBound() const { return d_ubound; } |
42 |
|
|
43 |
2055 |
bool CardinalityConstraint::operator==(const CardinalityConstraint& cc) const |
44 |
|
{ |
45 |
2055 |
return getType() == cc.getType() && getUpperBound() == cc.getUpperBound(); |
46 |
|
} |
47 |
|
|
48 |
|
bool CardinalityConstraint::operator!=(const CardinalityConstraint& cc) const |
49 |
|
{ |
50 |
|
return !(*this == cc); |
51 |
|
} |
52 |
|
|
53 |
|
std::ostream& operator<<(std::ostream& out, const CardinalityConstraint& cc) |
54 |
|
{ |
55 |
|
return out << "fmf.card(" << cc.getType() << ", " << cc.getUpperBound() |
56 |
|
<< ')'; |
57 |
|
} |
58 |
|
|
59 |
4782 |
size_t CardinalityConstraintHashFunction::operator()( |
60 |
|
const CardinalityConstraint& cc) const |
61 |
|
{ |
62 |
9564 |
return std::hash<TypeNode>()(cc.getType()) |
63 |
9564 |
* IntegerHashFunction()(cc.getUpperBound()); |
64 |
|
} |
65 |
|
|
66 |
806 |
CombinedCardinalityConstraint::CombinedCardinalityConstraint(const Integer& ub) |
67 |
806 |
: d_ubound(ub) |
68 |
|
{ |
69 |
806 |
} |
70 |
|
|
71 |
641 |
CombinedCardinalityConstraint::CombinedCardinalityConstraint( |
72 |
641 |
const CombinedCardinalityConstraint& other) |
73 |
641 |
: d_ubound(other.getUpperBound()) |
74 |
|
{ |
75 |
641 |
} |
76 |
|
|
77 |
1447 |
CombinedCardinalityConstraint::~CombinedCardinalityConstraint() {} |
78 |
|
|
79 |
10535 |
const Integer& CombinedCardinalityConstraint::getUpperBound() const |
80 |
|
{ |
81 |
10535 |
return d_ubound; |
82 |
|
} |
83 |
|
|
84 |
1460 |
bool CombinedCardinalityConstraint::operator==( |
85 |
|
const CombinedCardinalityConstraint& cc) const |
86 |
|
{ |
87 |
1460 |
return getUpperBound() == cc.getUpperBound(); |
88 |
|
} |
89 |
|
|
90 |
|
bool CombinedCardinalityConstraint::operator!=( |
91 |
|
const CombinedCardinalityConstraint& cc) const |
92 |
|
{ |
93 |
|
return !(*this == cc); |
94 |
|
} |
95 |
|
|
96 |
|
std::ostream& operator<<(std::ostream& out, |
97 |
|
const CombinedCardinalityConstraint& cc) |
98 |
|
{ |
99 |
|
return out << "fmf.card(" << cc.getUpperBound() << ')'; |
100 |
|
} |
101 |
|
|
102 |
3370 |
size_t CombinedCardinalityConstraintHashFunction::operator()( |
103 |
|
const CombinedCardinalityConstraint& cc) const |
104 |
|
{ |
105 |
3370 |
return cc.getUpperBound().hash(); |
106 |
|
} |
107 |
|
|
108 |
31137 |
} // namespace cvc5 |