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

Class simple

source code


This class generates a map from inputs to integers, where an equivalence class is defined by the trimmer function. It is just a stripped-down version of the hash class defined above. Faster and less memory consumption, if you don't need the rmap method.

Instance Methods
 
__init__(self, trimmer=None)
x.__init__(...) initializes x; see help(type(x)) for signature
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
 
get_image(self, x)
Returns an integer which is shared among all x in the equivalence class, but different from all other x.
source code
 
map(self)
Return the map from classes (as returned by the trimmer function) to integers.
source code
 
classes(self)
Return a list over all the classes that have been seen.
source code
 
classmap(self)
Return the map from integers to classes.
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...
Properties

Inherited from object: __class__

Method Details

__init__(self, trimmer=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

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.

Returns:
int

add_newonly(self, x)

source code 

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

Returns:
int or None

get_image(self, x)

source code 

Returns an integer which is shared among all x in the equivalence class, but different from all other x.

Raises:
  • NotInHash - when x is not in the hash table.

Note: the return value is the same as add, except that this doesn't add anything: rather than increasing the size of the mapping, it raises NotInHash.

classmap(self)

source code 

Return the map from integers to classes.

Returns:
[classname, classsname, ...]

Class Variable Details

__doc__

Value:
"""This class generates a map from inputs to integers,
		where an equivalence class is defined by the trimmer function.
		It is just a stripped-down version of the L{hash} class
		defined above.   Faster and less memory consumption, if
		you don't need the rmap method.
		"""