From 71cc140239f4f0104598c87b91f8327121cc09a9 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sat, 27 Jun 2015 21:19:58 -0500 Subject: [PATCH] Implement __hash__ and __len__ --- gen_wrap.py | 10 +++++++--- islpy/__init__.py | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/gen_wrap.py b/gen_wrap.py index 67d68e6..bfeaf24 100644 --- a/gen_wrap.py +++ b/gen_wrap.py @@ -1371,13 +1371,17 @@ def write_method_wrapper(gen, cls_name, meth): gen("") method_val = meth.name + py_name = meth.name + if meth.is_static: method_val = "staticmethod(%s)" % method_val + if py_name == "size" and len(meth.args) == 1: + py_name = "__len__" - gen("{py_cls}.{name} = {method_val}" + gen("{py_cls}.{py_name} = {method_val}" .format( py_cls=isl_class_to_py_class(meth.cls), - name=meth.name, + py_name=py_name, method_val=method_val)) gen("") @@ -1385,7 +1389,7 @@ def write_method_wrapper(gen, cls_name, meth): gen("{py_cls}._{name}_is_static = True" .format( py_cls=isl_class_to_py_class(meth.cls), - name=meth.name)) + name=py_name)) gen("") # }}} diff --git a/islpy/__init__.py b/islpy/__init__.py index a234399..fd006bc 100644 --- a/islpy/__init__.py +++ b/islpy/__init__.py @@ -212,10 +212,20 @@ def _add_functionality(): return "%s(\"%s\")" % ( type(self).__name__, prn.get_str()) + def generic_hash(self): + return hash((type(self), str(self))) + + def generic_isl_hash(self): + return self.get_hash() + for cls in ALL_CLASSES: if hasattr(cls, "_base_name") and hasattr(Printer, "print_"+cls._base_name): cls.__str__ = generic_str cls.__repr__ = generic_repr + if hasattr(cls, "get_hash"): + cls.__hash__ = generic_isl_hash + else: + cls.__hash__ = generic_hash # }}} -- GitLab