]> Savannah Git Hosting - gnulib.git/commitdiff
module: efficient hash implementation
authorDmitry Selyutin <ghostmansd@gmail.com>
Thu, 28 Sep 2017 15:53:30 +0000 (18:53 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Thu, 28 Sep 2017 17:54:31 +0000 (20:54 +0300)
pygnulib/module.py

index 828071e2fe60dc7f005c092e18a1abc78bfa5095..967148bbb4e539464a2295b4afcda060849f86bc 100644 (file)
@@ -34,6 +34,15 @@ class Base:
         "licenses"               : (0x0C, set, "License"),
         "maintainers"            : (0x0D, set, "Maintainer"),
     }
+    _TABLE_STR_ = []
+    _TABLE_SET_ = []
+    for (_key_, (_, _typeid_, _)) in _TABLE_.items():
+        if _typeid_ is str:
+            _TABLE_STR_.append(_key_)
+        elif _typeid_ is set:
+            _TABLE_SET_.append(_key_)
+    _TABLE_STR_ = sorted(_TABLE_STR_)
+    _TABLE_SET_ = sorted(_TABLE_SET_)
     _PATTERN_DEPENDENCIES_ = _re_.compile("^(\\S+)(?:\\s+(.+))*$")
 
 
@@ -298,7 +307,12 @@ class Base:
 
 
     def __hash__(self):
-        return hash(str(self))
+        result = ""
+        for key in Base._TABLE_SET_:
+            result += "".join(self.__table[key])
+        for key in Base._TABLE_STR_:
+            result += self.__table[key]
+        return hash((self.__name, result))
 
 
     def __repr__(self):