Example #1
0
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
Example #2
0
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
Example #3
0
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
Example #4
0
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
Example #5
0
def huffman(source):
    source.check()
    codeMap = CodeMap('Huffman')
    return _huffman(source.sorted(), codeMap)
Example #6
0
def fanno(source):
    source.check()
    codeMap = CodeMap('Shannon-Fanno')
    _fanno(source.sorted(), '', codeMap)
    return codeMap