Package gmisclib :: Module nice_hash :: Class hash
[frames] | no frames]

Class hash

source code


Instance Methods
 
__init__(self, trimmer=None)
This adds the rmap method to the simple class.
source code
 
rmap(self)
Returns the map from integers to inputs.
source code
 
test(self) source code
 
add(self, x)
Returns an integer which is shared among all x in the equivalence class, but different from all other x.
source code
 
add_newonly(self, x)
Similar to add, except it returns None if the equivalence class has already appeared.
source code
 
classes(self)
Return a list over all the classes that have been seen. (Inherited from gmisclib.nice_hash.simple)
source code
 
classmap(self)
Return the map from integers to classes. (Inherited from gmisclib.nice_hash.simple)
source code
 
get_image(self, x)
Returns an integer which is shared among all x in the equivalence class, but different from all other x. (Inherited from gmisclib.nice_hash.simple)
source code
 
map(self)
Return the map from classes (as returned by the trimmer function) to integers. (Inherited from gmisclib.nice_hash.simple)
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables
  __doc__ = """This class generates a map from inputs to intege... (Inherited from gmisclib.nice_hash.simple)
Properties

Inherited from object: __class__

Method Details

__init__(self, trimmer=None)
(Constructor)

source code 

This adds the rmap method to the simple class.

Parameters:
  • trimmer - Defines equivalence classes on list; it can be some sort of projection operation. The default (None) makes the identity class equal to the inputs. It can also specify which inputs to ignore by raising the DontHashThis exception.
Overrides: object.__init__

add(self, x)

source code 

Returns an integer which is shared among all x in the equivalence class, but different from all other x. If the trimmer function raises the DontHashThis exception, it will ignore the input and return None. Note that if you add an item twice, it will appear twice in rmap().

Returns:
int
Overrides: simple.add

add_newonly(self, x)

source code 

Similar to add, except it returns None if the equivalence class has already appeared.

The list of classes seen (self.seen) then contains only the first item that was added in each class, so rmap() will produce a dictionary containing single-item lists: {int1:[item1],int2:[item2],int3:[item3], ...}. Calls to add() and add_newonly() can be intermixed safely, though the result of rmap() will then not contain all added items.

Returns:
int or None
Overrides: simple.add_newonly