def block(source): source.check() codeMap = CodeMap('Blockcode') count = 0 blockLength = ceil(bb(len(source))) for symbol in source.sorted(): codeMap.mapSymbol(symbol, _paddedBinary(count, blockLength)) count += 1 return codeMap
def weaver(source): source.check() code = '' codeMap = CodeMap('Shannon-Weaver') cached = source.sorted() for symbol in cached[:-1]: codeMap.mapSymbol(symbol, code + '0') code += '1' codeMap.mapSymbol(cached[-1], code) return codeMap
def weaver(source): source.check() code = '' codeMap = CodeMap('Shannon-Weaver') cached = source.sorted() for symbol in cached[:-1]: codeMap.mapSymbol(symbol, code+'0') code += '1' codeMap.mapSymbol(cached[-1], code) return codeMap