Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * This file is part of the cvc5 project. 3 : : * 4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS 5 : : * in the top-level source directory and their institutional affiliations. 6 : : * All rights reserved. See the file COPYING in the top-level source 7 : : * directory for licensing information. 8 : : * **************************************************************************** 9 : : * 10 : : * The cardinality constraint operator 11 : : */ 12 : : 13 : : #include "expr/cardinality_constraint.h" 14 : : 15 : : #include <iostream> 16 : : 17 : : #include "expr/type_node.h" 18 : : 19 : : namespace cvc5::internal { 20 : : 21 : 1879 : CardinalityConstraint::CardinalityConstraint(const TypeNode& type, 22 : 1879 : const Integer& ub) 23 : 1879 : : d_type(new TypeNode(type)), d_ubound(ub) 24 : : { 25 [ - + ][ - + ]: 1879 : AlwaysAssert(type.isUninterpretedSort()) [ - - ] 26 : 0 : << "Unexpected cardinality constraints for " << type; 27 : 1879 : } 28 : : 29 : 1581 : CardinalityConstraint::CardinalityConstraint(const CardinalityConstraint& other) 30 : 1581 : : d_type(new TypeNode(other.getType())), d_ubound(other.getUpperBound()) 31 : : { 32 : 1581 : } 33 : : 34 : 3445 : CardinalityConstraint::~CardinalityConstraint() {} 35 : : 36 : 45092 : const TypeNode& CardinalityConstraint::getType() const { return *d_type; } 37 : : 38 : 29125 : const Integer& CardinalityConstraint::getUpperBound() const { return d_ubound; } 39 : : 40 : 3438 : bool CardinalityConstraint::operator==(const CardinalityConstraint& cc) const 41 : : { 42 [ + + ][ + - ]: 3438 : return getType() == cc.getType() && getUpperBound() == cc.getUpperBound(); 43 : : } 44 : : 45 : 0 : bool CardinalityConstraint::operator!=(const CardinalityConstraint& cc) const 46 : : { 47 : 0 : return !(*this == cc); 48 : : } 49 : : 50 : 0 : std::ostream& operator<<(std::ostream& out, const CardinalityConstraint& cc) 51 : : { 52 : 0 : return out << "(_ fmf.card " << cc.getType() << " " << cc.getUpperBound() 53 : 0 : << ')'; 54 : : } 55 : : 56 : 8173 : size_t CardinalityConstraintHashFunction::operator()( 57 : : const CardinalityConstraint& cc) const 58 : : { 59 : 8173 : return std::hash<TypeNode>()(cc.getType()) 60 : 8173 : * std::hash<Integer>()(cc.getUpperBound()); 61 : : } 62 : : 63 : 1221 : CombinedCardinalityConstraint::CombinedCardinalityConstraint(const Integer& ub) 64 : 1221 : : d_ubound(ub) 65 : : { 66 : 1221 : } 67 : : 68 : 1031 : CombinedCardinalityConstraint::CombinedCardinalityConstraint( 69 : 1031 : const CombinedCardinalityConstraint& other) 70 : 1031 : : d_ubound(other.getUpperBound()) 71 : : { 72 : 1031 : } 73 : : 74 : 2248 : CombinedCardinalityConstraint::~CombinedCardinalityConstraint() {} 75 : : 76 : 16395 : const Integer& CombinedCardinalityConstraint::getUpperBound() const 77 : : { 78 : 16395 : return d_ubound; 79 : : } 80 : : 81 : 2268 : bool CombinedCardinalityConstraint::operator==( 82 : : const CombinedCardinalityConstraint& cc) const 83 : : { 84 : 2268 : return getUpperBound() == cc.getUpperBound(); 85 : : } 86 : : 87 : 0 : bool CombinedCardinalityConstraint::operator!=( 88 : : const CombinedCardinalityConstraint& cc) const 89 : : { 90 : 0 : return !(*this == cc); 91 : : } 92 : : 93 : 0 : std::ostream& operator<<(std::ostream& out, 94 : : const CombinedCardinalityConstraint& cc) 95 : : { 96 : 0 : return out << "fmf.card(" << cc.getUpperBound() << ')'; 97 : : } 98 : : 99 : 5337 : size_t CombinedCardinalityConstraintHashFunction::operator()( 100 : : const CombinedCardinalityConstraint& cc) const 101 : : { 102 : 5337 : return cc.getUpperBound().hash(); 103 : : } 104 : : 105 : : } // namespace cvc5::internal