48
правок
Изменения
м
→Принцип действия
'''double''' right
'''Segment'''[m] defineSegments(letters: '''char'''[m], probability: '''double'''[m]):
'''Segment'''[m] segment
'''double''' l = 0
'''return''' segment
'''double''' arithmeticCoding(letters: '''char'''[m], probability: '''double'''[m], s: '''char'''[n]):
'''Segment'''[m] segment = defineSegments(letters, probability)
'''double''' left = 0
'''for''' i = 0 '''to''' n - 1
'''char''' symb = s[i]
'''double''' newRight = left + (right - left) * segment[symb].right ''<font color=green>// segment {{---}} массив, заполненный в результате выполнения метода defineSegments</font>''
'''double''' newLeft = left + (right - left) * segment[symb].left
left = newLeft
'''char''' character
'''Segment'''[m] defineSegments(letters: '''char'''[n], probability: '''double'''[n]):
'''Segment'''[m] segment
'''double''' l = 0
'''return''' segment
'''string''' arithmeticDecoding(letters: '''char'''[m], probability: '''double'''[m], code: '''double''', n: '''int'''):
'''Segment'''[m] segment = defineSegments(letters, probability)
'''string''' s = ""