Skip to content

Commit

Permalink
[py] added __hash__ for Interval, IntervalVar, IntervalVectorVar
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRohou committed Apr 20, 2022
1 parent 329f6bf commit 5fcaebf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/pybind11
Submodule pybind11 updated 135 files
11 changes: 10 additions & 1 deletion python/src/core/cn/codac_py_Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ void export_IntervalVar(py::module& m)

.def(py::init<>(),
"todo") // todo: doc

//.attr("__hash__") = py::none()
.def("__eq__", [](const IntervalVar& s1, const IntervalVar& s2) { return reinterpret_cast<std::uintptr_t>(&s1) == reinterpret_cast<std::uintptr_t>(&s2); })

.def("__hash__", [](const IntervalVar& s1) { return reinterpret_cast<std::uintptr_t>(&s1); })
;
}

Expand All @@ -57,5 +62,9 @@ void export_IntervalVectorVar(py::module& m)
},
"todo",
py::return_value_policy::reference_internal)
;

.def("__eq__", [](const IntervalVectorVar& s1, const IntervalVectorVar& s2) { return reinterpret_cast<std::uintptr_t>(&s1) == reinterpret_cast<std::uintptr_t>(&s2); })

.def("__hash__", [](const IntervalVectorVar& s1) { return reinterpret_cast<std::uintptr_t>(&s1); })
;
}
1 change: 1 addition & 0 deletions python/src/core/domains/interval/codac_py_Interval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ void export_Interval(py::module& m)
.def("bisect", &Interval::bisect, DOCS_INTERVAL_BISECT, py::arg("ratio")=0.5)
.def("__get_item__", get_item, "x[0] returns the lb and x[1] returns ub")
.def("copy", &interval_copy, "return a new object which is the copy of x")
.def("__hash__", [](const Interval& s1) { return reinterpret_cast<std::uintptr_t>(&s1); })
//.def( "__pow__", pow__)

// Constants
Expand Down

0 comments on commit 5fcaebf

Please sign in to comment.