Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
makeunicodedata.Hash Class Reference

List of all members.

Public Member Functions

def __init__
def dump

Public Attributes

 collisions
 data
 magic
 name
 size
 poly

Detailed Description

Definition at line 995 of file makeunicodedata.py.


Constructor & Destructor Documentation

def makeunicodedata.Hash.__init__ (   self,
  name,
  data,
  magic 
)

Definition at line 996 of file makeunicodedata.py.

00996 
00997     def __init__(self, name, data, magic):
00998         # turn a (key, value) list into a static hash table structure
00999 
01000         # determine table size
01001         for size, poly in SIZES:
01002             if size > len(data):
01003                 poly = size + poly
01004                 break
01005         else:
01006             raise AssertionError("ran out of polynomials")
01007 
01008         print(size, "slots in hash table")
01009 
01010         table = [None] * size
01011 
01012         mask = size-1
01013 
01014         n = 0
01015 
01016         hash = myhash
01017 
01018         # initialize hash table
01019         for key, value in data:
01020             h = hash(key, magic)
01021             i = (~h) & mask
01022             v = table[i]
01023             if v is None:
01024                 table[i] = value
01025                 continue
01026             incr = (h ^ (h >> 3)) & mask;
01027             if not incr:
01028                 incr = mask
01029             while 1:
01030                 n = n + 1
01031                 i = (i + incr) & mask
01032                 v = table[i]
01033                 if v is None:
01034                     table[i] = value
01035                     break
01036                 incr = incr << 1
01037                 if incr > mask:
01038                     incr = incr ^ poly
01039 
01040         print(n, "collisions")
01041         self.collisions = n
01042 
01043         for i in range(len(table)):
01044             if table[i] is None:
01045                 table[i] = 0
01046 
01047         self.data = Array(name + "_hash", table)
01048         self.magic = magic
01049         self.name = name
01050         self.size = size
01051         self.poly = poly


Member Function Documentation

def makeunicodedata.Hash.dump (   self,
  file,
  trace 
)

Definition at line 1052 of file makeunicodedata.py.

01052 
01053     def dump(self, file, trace):
01054         # write data to file, as a C array
01055         self.data.dump(file, trace)
01056         file.write("#define %s_magic %d\n" % (self.name, self.magic))
01057         file.write("#define %s_size %d\n" % (self.name, self.size))
01058         file.write("#define %s_poly %d\n" % (self.name, self.poly))
01059 
01060 # stuff to deal with arrays of unsigned integers


Member Data Documentation

Definition at line 1040 of file makeunicodedata.py.

Definition at line 1046 of file makeunicodedata.py.

Definition at line 1047 of file makeunicodedata.py.

Definition at line 1048 of file makeunicodedata.py.

Definition at line 1050 of file makeunicodedata.py.

Definition at line 1049 of file makeunicodedata.py.


The documentation for this class was generated from the following file: