Exemple #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
Exemple #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
Exemple #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
Exemple #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