diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-02-15 02:46:14 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-02-15 06:02:08 +0300 |
commit | fa2f7c69acc55fd1fe3db0610ad319d08d77d79e (patch) | |
tree | 004780e19ea70ec8ee5eb6b26cde8ace90558a70 /source/blender/python/mathutils/mathutils_Color.c | |
parent | a9d979c8ef2b6de25c1953da341dd5e207416540 (diff) |
mathutils: Implement __hash__() functions
- all mathutils types
- only works on frozen data (so vectors can be used in sets/dict keys)
- uses same method as CPython, (matches hashing a tuple)
D1104 by @juicyfruit with own modifications
Diffstat (limited to 'source/blender/python/mathutils/mathutils_Color.c')
-rw-r--r-- | source/blender/python/mathutils/mathutils_Color.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/source/blender/python/mathutils/mathutils_Color.c b/source/blender/python/mathutils/mathutils_Color.c index 7fea0e59b82..add8c2451ff 100644 --- a/source/blender/python/mathutils/mathutils_Color.c +++ b/source/blender/python/mathutils/mathutils_Color.c @@ -192,6 +192,17 @@ static PyObject *Color_richcmpr(PyObject *a, PyObject *b, int op) return Py_INCREF_RET(res); } +static Py_hash_t Color_hash(ColorObject *self) +{ + if (BaseMath_ReadCallback(self) == -1) + return -1; + + if (BaseMathObject_Prepare_ForHash(self) == -1) + return -1; + + return mathutils_array_hash(self->col, COLOR_SIZE); +} + /* ---------------------SEQUENCE PROTOCOLS------------------------ */ /* ----------------------------len(object)------------------------ */ /* sequence length */ @@ -843,7 +854,7 @@ PyTypeObject color_Type = { &Color_NumMethods, /* tp_as_number */ &Color_SeqMethods, /* tp_as_sequence */ &Color_AsMapping, /* tp_as_mapping */ - NULL, /* tp_hash */ + (hashfunc)Color_hash, /* tp_hash */ NULL, /* tp_call */ #ifndef MATH_STANDALONE (reprfunc) Color_str, /* tp_str */ |