コード例 #1
0
 def DebugFormat(self):
     print FormatAsBits((self.output, self.out_boff))
     for i in xrange(self.idx_byte * 8 + self.idx_boff - 1):
         if not i % 8:
             sys.stdout.write("|")
         sys.stdout.write("-")
     print "^"
コード例 #2
0
 def DebugFormat(self):
     """
 Prints out (to stdout) a representation intended to help with debugging
 """
     print FormatAsBits((self.output, self.out_boff))
     for i in xrange(self.idx_byte * 8 + self.idx_boff - 1):
         if not i % 8:
             sys.stdout.write("|")
         sys.stdout.write("-")
     print "^"
コード例 #3
0
def main():
  h = Huffman(request_freq_table)
  for s in test_data:
    print " encoding: ", s
    sp = [ord(c) for c in s]
    e_result = h.Encode(sp, False)
    print "      e_result: ", FormatAsBits(e_result)
    d_result = ''.join(ListToStr(h.Decode(e_result[0], False, e_result[1])))
    if d_result != s:
      print "difference found: ", d_result, " ", s
    else:
      print "It worked: ", s
    print
コード例 #4
0
ファイル: huffman_test.py プロジェクト: mnot/compression-test
def main():
  h = Huffman(request_freq_table)
  for s in test_data:
    print " encoding: ", s
    sp = [ord(c) for c in s]
    e_result = BitBucket()
    h.EncodeToBB(e_result, sp, True)
    print "      e_result: ", FormatAsBits(e_result.GetAllBits())

    d_result = ListToStr(h.DecodeFromBB(e_result, True, -1))
    if d_result != s:
      print "difference found: d_result(%s) vs orig(%s)" % (repr(d_result),
                                                            repr(s))
    else:
      print "It worked: ", s
    print
コード例 #5
0
 def FormatCodeTable(self):
     """
 Makes a formatted version of the code table, useful for debugging
 """
     printable = string.digits + string.letters + string.punctuation + ' '
     x = sorted([(i, FormatAsBits(self.code_table[i]))
                 for i in xrange(len(self.code_table))])
     retval = []
     for entry in x:
         code, description = entry
         readable_code = ""
         if code < 128 and chr(code) in printable:
             readable_code = "'%c'" % chr(code)
         while len(readable_code) < 5:
             readable_code = " " + readable_code
         retval.append('%s (%3d): %s' % (readable_code, code, description))
     return '\n'.join(retval)
コード例 #6
0
 def FormatCodeTable(self):
     """
 Makes a formatted version of the code table, useful for debugging
 """
     printable = string.digits + string.letters + string.punctuation + ' '
     x = sorted([(i, FormatAsBits(self.code_table[i]))
                 for i in xrange(len(self.code_table))])
     retval = []
     for entry in x:
         sym, description = entry
         code = self.canonical_code_table[sym][1]
         code_len = self.canonical_code_table[sym][0][1]
         readable_sym = ""
         if sym < 128 and chr(sym) in printable:
             readable_sym = "'%c'" % chr(sym)
         while len(readable_sym) < 5:
             readable_sym = " " + readable_sym
         s = '{0:5s} ({1:>3d}) {2:<40} {3:8x} [{4:}]'.format(
             readable_sym, sym, description, code, code_len)
         retval.append(s)
     return '\n'.join(retval)
コード例 #7
0
 def __repr__(self):
     return FormatAsBits((self.output, self.out_boff))