Return a hash value for this feature structure. :require: ``self`` must be frozen. :param visited: A set containing the ids of all feature structures we've already visited while hashing.
(self, visited)
| 347 | return True |
| 348 | |
| 349 | def _calculate_hashvalue(self, visited): |
| 350 | """ |
| 351 | Return a hash value for this feature structure. |
| 352 | |
| 353 | :require: ``self`` must be frozen. |
| 354 | :param visited: A set containing the ids of all feature |
| 355 | structures we've already visited while hashing. |
| 356 | """ |
| 357 | if id(self) in visited: |
| 358 | return 1 |
| 359 | visited.add(id(self)) |
| 360 | |
| 361 | hashval = 5831 |
| 362 | for fname, fval in sorted(self._items()): |
| 363 | hashval *= 37 |
| 364 | hashval += hash(fname) |
| 365 | hashval *= 37 |
| 366 | if isinstance(fval, FeatStruct): |
| 367 | hashval += fval._calculate_hashvalue(visited) |
| 368 | else: |
| 369 | hashval += hash(fval) |
| 370 | # Convert to a 32 bit int. |
| 371 | hashval = int(hashval & 0x7FFFFFFF) |
| 372 | return hashval |
| 373 | |
| 374 | ##//////////////////////////////////////////////////////////// |
| 375 | # { Freezing |