Use proper hash function

This commit is contained in:
angie 2023-08-26 23:16:22 -04:00
parent eb407ec9d3
commit ed678cfeb6

View File

@ -91,15 +91,21 @@ static PyGetSetDef rabbitizer_type_Enum_getsetters[] = {
}; };
// Crappy hash
Py_hash_t rabbitizer_type_Enum_hash(PyRabbitizerEnum *self) { Py_hash_t rabbitizer_type_Enum_hash(PyRabbitizerEnum *self) {
Py_hash_t hash = PyObject_Hash(self->enumType); PyObject *tuple = PyTuple_Pack(2, self->enumType, PyLong_FromLong(self->value));
Py_hash_t hash;
if (tuple == NULL) {
return -1;
}
hash = PyObject_Hash(tuple);
if (hash == -1) { if (hash == -1) {
return -1; return -1;
} }
return hash + self->value; return hash;
} }
// Checks for the 6 basic comparisons (==, !=, <, <=, >, >=) // Checks for the 6 basic comparisons (==, !=, <, <=, >, >=)