MCPcopy
hub / github.com/nltk/nltk / _calculate_hashvalue

Method _calculate_hashvalue

nltk/featstruct.py:349–372  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

__hash__Method · 0.95

Calls 2

_itemsMethod · 0.95
addMethod · 0.45

Tested by

no test coverage detected