This PR replaces all api::*HashFunction objects by specializations of std::hash. std::hash is meant to be extended in this way, and it allows for a much cleaner usage of std::unordered_set and std::unordered_map with these types.
-c ${CMAKE_CURRENT_BINARY_DIR}
# Tell Breathe where to find the Doxygen output
-Dbreathe_projects.cvc5=${CPP_DOXYGEN_XML_FOLDER}
+ -Dbreathe_projects.std=${CPP_DOXYGEN_XML_FOLDER}
${SPHINX_INPUT_DIR} ${SPHINX_OUTPUT_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating Sphinx Api docs")
C++ API Documentation
=====================
-Class Hierarchy
----------------
-
-* namespace ``cvc5``
-
- * namespace ``api``
-
- * class :cpp:class:`cvc5::api::CVC4ApiException`
-
- * class :cpp:class:`cvc5::api::CVC4ApiRecoverableException`
-
- * class :doc:`datatype`
-
- * class :ref:`Datatype::const_iterator<datatype>`
-
- * class :doc:`datatypeconstructor`
-
- * class :ref:`DatatypeConstructor::const_iterator<datatypeconstructor>`
-
- * class :doc:`datatypeconstructordecl`
-
- * class :doc:`datatypedecl`
-
- * class :doc:`datatypeselector`
-
- * class :doc:`grammar`
-
- * class :doc:`op`
-
- * class :doc:`result`
-
- * class :doc:`solver`
-
- * class :doc:`term`
-
- * class :ref:`Term::const_iterator<term>`
-
- * enum :doc:`kind`
-
- * enum :doc:`roundingmode`
-
- * struct :ref:`KindHashFunction<kind>`
-
- * struct :ref:`OpHashFunction<op>`
-
- * struct :ref:`SortHashFunction<sort>`
-
- * class :cpp:class:`cvc5::api::Statistics`
- * class :cpp:class:`cvc5::api::Stat`
-
-
-
-Full API Documentation
-----------------------
-
.. toctree::
:maxdepth: 2
sort
statistics
term
+
+
+Class Hierarchy
+---------------
+
+* namespace ``cvc5::api``
+
+ * class :cpp:class:`CVC5ApiException <cvc5::api::CVC5ApiException>`
+ * class :cpp:class:`CVC5ApiRecoverableException <cvc5::api::CVC5ApiRecoverableException>`
+
+ * class :cpp:class:`Datatype <cvc5::api::Datatype>`
+
+ * class :cpp:class:`const_iterator <cvc5::api::Datatype::const_iterator>`
+
+ * class :cpp:class:`DatatypeConstructor <cvc5::api::DatatypeConstructor>`
+
+ * class :cpp:class:`const_iterator <cvc5::api::DatatypeConstructor::const_iterator>`
+
+ * class :cpp:class:`DatatypeConstructorDecl <cvc5::api::DatatypeConstructorDecl>`
+ * class :cpp:class:`DatatypeDecl <cvc5::api::DatatypeDecl>`
+ * class :cpp:class:`DatatypeSelector <cvc5::api::DatatypeSelector>`
+
+ * class :cpp:class:`Grammar <cvc5::api::Grammar>`
+
+ * enum :cpp:enum:`Kind <cvc5::api::Kind>`
+
+ * class :cpp:class:`Op <cvc5::api::Op>`
+
+ * class :cpp:class:`Result <cvc5::api::Result>`
+
+ * enum :cpp:enum:`UnknownExplanation <cvc5::api::Result::UnknownExplanation>`
+
+ * enum :cpp:enum:`RoundingMode <cvc5::api::RoundingMode>`
+
+ * class :cpp:class:`Solver <cvc5::api::Solver>`
+
+ * class :cpp:class:`Sort <cvc5::api::Sort>`
+
+ * class :cpp:class:`Stat <cvc5::api::Stat>`
+
+ * class :cpp:class:`Statistics <cvc5::api::Statistics>`
+
+ * class :cpp:class:`Term <cvc5::api::Term>`
+
+ * class :cpp:class:`const_iterator <cvc5::api::Term::const_iterator>`
.. doxygenenum:: cvc5::api::Kind
:project: cvc5
-.. doxygenstruct:: cvc5::api::KindHashFunction
- :project: cvc5
+.. doxygenstruct:: std::hash< cvc5::api::Kind >
+ :project: std
:members:
:undoc-members:
Op
==
-.. doxygenstruct:: cvc5::api::OpHashFunction
+.. doxygenclass:: cvc5::api::Op
:project: cvc5
:members:
- :undoc-members:
-.. doxygenclass:: cvc5::api::Op
- :project: cvc5
+.. doxygenstruct:: std::hash< cvc5::api::Op >
+ :project: std
:members:
+ :undoc-members:
.. doxygenenum:: cvc5::api::RoundingMode
:project: cvc5
-.. doxygenstruct:: cvc5::api::RoundingModeHashFunction
- :project: cvc5
+.. doxygenstruct:: std::hash< cvc5::api::RoundingMode >
+ :project: std
:members:
:undoc-members:
Sort
====
-.. doxygenstruct:: cvc5::api::SortHashFunction
+.. doxygenclass:: cvc5::api::Sort
:project: cvc5
:members:
:undoc-members:
-.. doxygenclass:: cvc5::api::Sort
- :project: cvc5
+.. doxygenstruct:: std::hash< cvc5::api::Sort >
+ :project: std
:members:
:undoc-members:
Term
====
-.. doxygenstruct:: cvc5::api::TermHashFunction
+.. doxygenclass:: cvc5::api::Term
:project: cvc5
:members:
:undoc-members:
-.. doxygenclass:: cvc5::api::Term
- :project: cvc5
+.. doxygenstruct:: std::hash< cvc5::api::Term >
+ :project: std
:members:
:undoc-members:
/* -------------------------------------------------------------------------- */
/* Mapping from external (API) kind to internal kind. */
-const static std::unordered_map<Kind, cvc5::Kind, KindHashFunction> s_kinds{
+const static std::unordered_map<Kind, cvc5::Kind> s_kinds{
{INTERNAL_KIND, cvc5::Kind::UNDEFINED_KIND},
{UNDEFINED_KIND, cvc5::Kind::UNDEFINED_KIND},
{NULL_EXPR, cvc5::Kind::NULL_EXPR},
};
/* Set of kinds for indexed operators */
-const static std::unordered_set<Kind, KindHashFunction> s_indexed_kinds(
+const static std::unordered_set<Kind> s_indexed_kinds(
{RECORD_UPDATE,
DIVISIBLE,
IAND,
return out;
}
-size_t KindHashFunction::operator()(Kind k) const { return k; }
-
/* -------------------------------------------------------------------------- */
/* API guard helpers */
/* -------------------------------------------------------------------------- */
return out;
}
-size_t SortHashFunction::operator()(const Sort& s) const
-{
- return TypeNodeHashFunction()(*s.d_type);
-}
-
/* Helpers */
/* -------------------------------------------------------------------------- */
return out;
}
-size_t OpHashFunction::operator()(const Op& t) const
-{
- if (t.isIndexedHelper())
- {
- return NodeHashFunction()(*t.d_node);
- }
- else
- {
- return KindHashFunction()(t.d_kind);
- }
-}
-
/* Helpers */
/* -------------------------------------------------------------------------- */
return out;
}
-std::ostream& operator<<(
- std::ostream& out,
- const std::unordered_set<Term, TermHashFunction>& unordered_set)
+std::ostream& operator<<(std::ostream& out,
+ const std::unordered_set<Term>& unordered_set)
{
container_to_stream(out, unordered_set);
return out;
}
template <typename V>
-std::ostream& operator<<(
- std::ostream& out,
- const std::unordered_map<Term, V, TermHashFunction>& unordered_map)
+std::ostream& operator<<(std::ostream& out,
+ const std::unordered_map<Term, V>& unordered_map)
{
container_to_stream(out, unordered_map);
return out;
}
-size_t TermHashFunction::operator()(const Term& t) const
-{
- return NodeHashFunction()(*t.d_node);
-}
-
/* Helpers */
/* -------------------------------------------------------------------------- */
cvc5::kind::BOUND_VAR_LIST, Term::termVectorToNodes(d_sygusVars)));
}
- std::unordered_map<Term, Sort, TermHashFunction> ntsToUnres(d_ntSyms.size());
+ std::unordered_map<Term, Sort> ntsToUnres(d_ntSyms.size());
for (Term ntsymbol : d_ntSyms)
{
void Grammar::addSygusConstructorTerm(
DatatypeDecl& dt,
const Term& term,
- const std::unordered_map<Term, Sort, TermHashFunction>& ntsToUnres) const
+ const std::unordered_map<Term, Sort>& ntsToUnres) const
{
CVC5_API_TRY_CATCH_BEGIN;
CVC5_API_CHECK_DTDECL(dt);
const Term& term,
std::vector<Term>& args,
std::vector<Sort>& cargs,
- const std::unordered_map<Term, Sort, TermHashFunction>& ntsToUnres) const
+ const std::unordered_map<Term, Sort>& ntsToUnres) const
{
CVC5_API_TRY_CATCH_BEGIN;
CVC5_API_CHECK_TERM(term);
CVC5_API_CHECK_TERMS_MAP(ntsToUnres);
//////// all checks before this line
- std::unordered_map<Term, Sort, TermHashFunction>::const_iterator itn =
- ntsToUnres.find(term);
+ std::unordered_map<Term, Sort>::const_iterator itn = ntsToUnres.find(term);
if (itn != ntsToUnres.cend())
{
Term ret =
/* Rounding Mode for Floating Points */
/* -------------------------------------------------------------------------- */
-const static std::
- unordered_map<RoundingMode, cvc5::RoundingMode, RoundingModeHashFunction>
- s_rmodes{
- {ROUND_NEAREST_TIES_TO_EVEN,
- cvc5::RoundingMode::ROUND_NEAREST_TIES_TO_EVEN},
- {ROUND_TOWARD_POSITIVE, cvc5::RoundingMode::ROUND_TOWARD_POSITIVE},
- {ROUND_TOWARD_NEGATIVE, cvc5::RoundingMode::ROUND_TOWARD_NEGATIVE},
- {ROUND_TOWARD_ZERO, cvc5::RoundingMode::ROUND_TOWARD_ZERO},
- {ROUND_NEAREST_TIES_TO_AWAY,
- cvc5::RoundingMode::ROUND_NEAREST_TIES_TO_AWAY},
- };
+const static std::unordered_map<RoundingMode, cvc5::RoundingMode> s_rmodes{
+ {ROUND_NEAREST_TIES_TO_EVEN,
+ cvc5::RoundingMode::ROUND_NEAREST_TIES_TO_EVEN},
+ {ROUND_TOWARD_POSITIVE, cvc5::RoundingMode::ROUND_TOWARD_POSITIVE},
+ {ROUND_TOWARD_NEGATIVE, cvc5::RoundingMode::ROUND_TOWARD_NEGATIVE},
+ {ROUND_TOWARD_ZERO, cvc5::RoundingMode::ROUND_TOWARD_ZERO},
+ {ROUND_NEAREST_TIES_TO_AWAY,
+ cvc5::RoundingMode::ROUND_NEAREST_TIES_TO_AWAY},
+};
const static std::unordered_map<cvc5::RoundingMode,
RoundingMode,
ROUND_NEAREST_TIES_TO_AWAY},
};
-size_t RoundingModeHashFunction::operator()(const RoundingMode& rm) const
-{
- return size_t(rm);
-}
-
/* -------------------------------------------------------------------------- */
/* Statistics */
/* -------------------------------------------------------------------------- */
const std::string& Stat::getString() const
{
CVC5_API_TRY_CATCH_BEGIN;
- CVC5_API_RECOVERABLE_CHECK(isString()) << "Expected Stat of type std::string.";
+ CVC5_API_RECOVERABLE_CHECK(isString())
+ << "Expected Stat of type std::string.";
return std::get<std::string>(d_data->data);
CVC5_API_TRY_CATCH_END;
}
const Stat::HistogramData& Stat::getHistogram() const
{
CVC5_API_TRY_CATCH_BEGIN;
- CVC5_API_RECOVERABLE_CHECK(isHistogram()) << "Expected Stat of type histogram.";
+ CVC5_API_RECOVERABLE_CHECK(isHistogram())
+ << "Expected Stat of type histogram.";
return std::get<HistogramData>(d_data->data);
CVC5_API_TRY_CATCH_END;
}
"api::CONSTANT"),
d_smtEngine->getStatisticsRegistry().registerHistogram<TypeConstant>(
"api::VARIABLE"),
- d_smtEngine->getStatisticsRegistry().registerHistogram<Kind>("api::TERM"),
+ d_smtEngine->getStatisticsRegistry().registerHistogram<Kind>(
+ "api::TERM"),
});
}
}
} // namespace api
} // namespace cvc5
+
+namespace std {
+
+size_t hash<cvc5::api::Kind>::operator()(cvc5::api::Kind k) const
+{
+ return static_cast<size_t>(k);
+}
+
+size_t hash<cvc5::api::Op>::operator()(const cvc5::api::Op& t) const
+{
+ if (t.isIndexedHelper())
+ {
+ return cvc5::NodeHashFunction()(*t.d_node);
+ }
+ else
+ {
+ return std::hash<cvc5::api::Kind>()(t.d_kind);
+ }
+}
+
+size_t std::hash<cvc5::api::RoundingMode>::operator()(
+ cvc5::api::RoundingMode rm) const
+{
+ return static_cast<size_t>(rm);
+}
+
+size_t std::hash<cvc5::api::Sort>::operator()(const cvc5::api::Sort& s) const
+{
+ return cvc5::TypeNodeHashFunction()(*s.d_type);
+}
+
+size_t std::hash<cvc5::api::Term>::operator()(const cvc5::api::Term& t) const
+{
+ return cvc5::NodeHashFunction()(*t.d_node);
+}
+
+} // namespace std
friend class Op;
friend class Solver;
friend class Grammar;
- friend struct SortHashFunction;
+ friend struct std::hash<Sort>;
friend class Term;
public:
*/
std::ostream& operator<<(std::ostream& out, const Sort& s) CVC5_EXPORT;
+} // namespace api
+} // namespace cvc5
+
+namespace std {
+
/**
* Hash function for Sorts.
*/
-struct CVC5_EXPORT SortHashFunction
+template <>
+struct CVC5_EXPORT hash<cvc5::api::Sort>
{
- size_t operator()(const Sort& s) const;
+ size_t operator()(const cvc5::api::Sort& s) const;
};
+} // namespace std
+
+namespace cvc5::api {
+
/* -------------------------------------------------------------------------- */
/* Op */
/* -------------------------------------------------------------------------- */
{
friend class Solver;
friend class Term;
- friend struct OpHashFunction;
+ friend struct std::hash<Op>;
public:
/**
std::shared_ptr<cvc5::Node> d_node;
};
+/**
+ * Serialize an operator to given stream.
+ * @param out the output stream
+ * @param t the operator to be serialized to the given output stream
+ * @return the output stream
+ */
+std::ostream& operator<<(std::ostream& out, const Op& t) CVC5_EXPORT;
+
+} // namespace cvc5::api
+
+namespace std {
+/**
+ * Hash function for Ops.
+ */
+template <>
+struct CVC5_EXPORT hash<cvc5::api::Op>
+{
+ size_t operator()(const cvc5::api::Op& t) const;
+};
+} // namespace std
+
+namespace cvc5::api {
/* -------------------------------------------------------------------------- */
/* Term */
/* -------------------------------------------------------------------------- */
friend class DatatypeSelector;
friend class Solver;
friend class Grammar;
- friend struct TermHashFunction;
+ friend struct std::hash<Term>;
public:
/**
std::shared_ptr<cvc5::Node> d_node;
};
-/**
- * Hash function for Terms.
- */
-struct CVC5_EXPORT TermHashFunction
-{
- size_t operator()(const Term& t) const;
-};
-
/**
* Serialize a term to given stream.
* @param out the output stream
* @return the output stream
*/
std::ostream& operator<<(std::ostream& out,
- const std::unordered_set<Term, TermHashFunction>&
- unordered_set) CVC5_EXPORT;
+ const std::unordered_set<Term>& unordered_set)
+ CVC5_EXPORT;
/**
* Serialize a map of terms to the given stream.
*/
template <typename V>
std::ostream& operator<<(std::ostream& out,
- const std::unordered_map<Term, V, TermHashFunction>&
- unordered_map) CVC5_EXPORT;
+ const std::unordered_map<Term, V>& unordered_map)
+ CVC5_EXPORT;
-/**
- * Serialize an operator to given stream.
- * @param out the output stream
- * @param t the operator to be serialized to the given output stream
- * @return the output stream
- */
-std::ostream& operator<<(std::ostream& out, const Op& t) CVC5_EXPORT;
+} // namespace cvc5::api
+namespace std {
/**
- * Hash function for Ops.
+ * Hash function for Terms.
*/
-struct CVC5_EXPORT OpHashFunction
+template <>
+struct CVC5_EXPORT hash<cvc5::api::Term>
{
- size_t operator()(const Op& t) const;
+ size_t operator()(const cvc5::api::Term& t) const;
};
+} // namespace std
+
+namespace cvc5::api {
/* -------------------------------------------------------------------------- */
/* Datatypes */
void addSygusConstructorTerm(
DatatypeDecl& dt,
const Term& term,
- const std::unordered_map<Term, Sort, TermHashFunction>& ntsToUnres) const;
+ const std::unordered_map<Term, Sort>& ntsToUnres) const;
/**
* Purify SyGuS grammar term.
* @param ntsToUnres mapping from non-terminals to their unresolved sorts
* @return the purfied term
*/
- Term purifySygusGTerm(
- const Term& term,
- std::vector<Term>& args,
- std::vector<Sort>& cargs,
- const std::unordered_map<Term, Sort, TermHashFunction>& ntsToUnres) const;
+ Term purifySygusGTerm(const Term& term,
+ std::vector<Term>& args,
+ std::vector<Sort>& cargs,
+ const std::unordered_map<Term, Sort>& ntsToUnres) const;
/**
* This adds constructors to \p dt for sygus variables in \p d_sygusVars
/** The non-terminal symbols of this grammar. */
std::vector<Term> d_ntSyms;
/** The mapping from non-terminal symbols to their production terms. */
- std::unordered_map<Term, std::vector<Term>, TermHashFunction> d_ntsToTerms;
+ std::unordered_map<Term, std::vector<Term>> d_ntsToTerms;
/** The set of non-terminals that can be arbitrary constants. */
- std::unordered_set<Term, TermHashFunction> d_allowConst;
+ std::unordered_set<Term> d_allowConst;
/** The set of non-terminals that can be sygus variables. */
- std::unordered_set<Term, TermHashFunction> d_allowVars;
+ std::unordered_set<Term> d_allowVars;
/** Did we call resolve() before? */
bool d_isResolved;
};
ROUND_NEAREST_TIES_TO_AWAY,
};
+} // namespace cvc5::api
+
+namespace std {
+
/**
* Hash function for RoundingModes.
*/
-struct CVC5_EXPORT RoundingModeHashFunction
+template <>
+struct CVC5_EXPORT hash<cvc5::api::RoundingMode>
{
- inline size_t operator()(const RoundingMode& rm) const;
+ size_t operator()(cvc5::api::RoundingMode rm) const;
};
+} // namespace std
+namespace cvc5::api {
/* -------------------------------------------------------------------------- */
/* Statistics */
std::unique_ptr<Random> d_rng;
};
-} // namespace api
-} // namespace cvc5
+} // namespace cvc5::api
+
#endif
*/
std::ostream& operator<<(std::ostream& out, Kind k) CVC5_EXPORT;
+} // namespace api
+} // namespace cvc5
+
+namespace std {
+
/**
* Hash function for Kinds.
*/
-struct CVC5_EXPORT KindHashFunction
+template<>
+struct CVC5_EXPORT hash<cvc5::api::Kind>
{
/**
* Hashes a Kind to a size_t.
*/
- size_t operator()(Kind k) const;
+ size_t operator()(cvc5::api::Kind k) const;
};
-} // namespace api
-} // namespace cvc5
+}
#endif
ostream cout
+cdef extern from "<functional>" namespace "std" nogil:
+ cdef cppclass hash[T]:
+ hash()
+ size_t operator()(T t)
+
+
cdef extern from "api/cpp/cvc5.h" namespace "cvc5":
cdef cppclass Options:
pass
from cvc5 cimport Result as c_Result
from cvc5 cimport RoundingMode as c_RoundingMode
from cvc5 cimport Op as c_Op
-from cvc5 cimport OpHashFunction as c_OpHashFunction
from cvc5 cimport Solver as c_Solver
from cvc5 cimport Grammar as c_Grammar
from cvc5 cimport Sort as c_Sort
-from cvc5 cimport SortHashFunction as c_SortHashFunction
from cvc5 cimport ROUND_NEAREST_TIES_TO_EVEN, ROUND_TOWARD_POSITIVE
from cvc5 cimport ROUND_TOWARD_NEGATIVE, ROUND_TOWARD_ZERO
from cvc5 cimport ROUND_NEAREST_TIES_TO_AWAY
from cvc5 cimport Term as c_Term
-from cvc5 cimport TermHashFunction as c_TermHashFunction
+from cvc5 cimport hash as c_hash
from cvc5kinds cimport Kind as c_Kind
## Objects for hashing
-cdef c_OpHashFunction cophash = c_OpHashFunction()
-cdef c_SortHashFunction csorthash = c_SortHashFunction()
-cdef c_TermHashFunction ctermhash = c_TermHashFunction()
+cdef c_hash[c_Op] cophash = c_hash[c_Op]()
+cdef c_hash[c_Sort] csorthash = c_hash[c_Sort]()
+cdef c_hash[c_Term] ctermhash = c_hash[c_Term]()
cdef class Datatype:
class SymbolManager::Implementation
{
- using TermStringMap = CDHashMap<api::Term, std::string, api::TermHashFunction>;
- using TermSet = CDHashSet<api::Term, api::TermHashFunction>;
+ using TermStringMap = CDHashMap<api::Term, std::string, std::hash<api::Term>>;
+ using TermSet = CDHashSet<api::Term, std::hash<api::Term>>;
using SortList = CDList<api::Sort>;
using TermList = CDList<api::Term>;
public:
OverloadedTypeTrie(Context* c, bool allowFunVariants = false)
: d_overloaded_symbols(
- new (true) CDHashSet<api::Term, api::TermHashFunction>(c)),
+ new (true) CDHashSet<api::Term, std::hash<api::Term>>(c)),
d_allowFunctionVariants(allowFunVariants)
{
}
* above. */
std::unordered_map<std::string, TypeArgTrie> d_overload_type_arg_trie;
/** The set of overloaded symbols. */
- CDHashSet<api::Term, api::TermHashFunction>* d_overloaded_symbols;
+ CDHashSet<api::Term, std::hash<api::Term>>* d_overloaded_symbols;
/** allow function variants
* This is true if we allow overloading (non-constant) functions that expect
* the same argument types.
api::Term d_utr_op;
api::Term d_uts_op;
// The set of expression that already have a bridge
- std::unordered_set<api::Term, api::TermHashFunction> d_r_converted;
+ std::unordered_set<api::Term> d_r_converted;
std::unordered_map<std::string, api::Term> d_distinct_objects;
std::vector< pANTLR3_INPUT_STREAM > d_in_created;