Skip to content
Snippets Groups Projects
Commit 1222848b authored by Studer Gabriel's avatar Studer Gabriel
Browse files

define __hash__ for ResNum makes it usable as key in a dict

parent 7e01a0d7
No related branches found
No related tags found
No related merge requests found
...@@ -71,6 +71,19 @@ namespace { ...@@ -71,6 +71,19 @@ namespace {
} }
b->SetChemClass(ChemClass(st[0])); b->SetChemClass(ChemClass(st[0]));
} }
struct H {
std::size_t operator()(const ost::mol::ResNum& n) const {
std::size_t h1 = std::hash<int>{}(n.GetNum());
std::size_t h2 = std::hash<char>{}(n.GetInsCode());
return h1 ^ (h2 << 1);
}
};
int ResNumHash(const ost::mol::ResNum& n) {
return H{}(n);
}
} }
void export_Residue() void export_Residue()
...@@ -118,6 +131,7 @@ void export_Residue() ...@@ -118,6 +131,7 @@ void export_Residue()
.add_property("ins_code", &ResNum::GetInsCode) .add_property("ins_code", &ResNum::GetInsCode)
.def("__str__", &ResNum::AsString) .def("__str__", &ResNum::AsString)
.def("__repr__", &ResNum::AsString) .def("__repr__", &ResNum::AsString)
.def("__hash__", &ResNumHash)
.def(self<self) .def(self<self)
.def(self>self) .def(self>self)
.def(self>=self) .def(self>=self)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment