File: decoders.py

package info (click to toggle)
mmtf-python 1.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 300 kB
  • sloc: python: 1,150; makefile: 8
file content (28 lines) | stat: -rw-r--r-- 803 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def run_length_decode(in_array):
    """A function to run length decode an int array.
    :param in_array: the input array of integers
    :return the decoded array"""
    switch=False
    out_array=[]
    for item in in_array:
        if switch==False:
            this_item = item
            switch=True
        else:
            switch=False
            out_array.extend([this_item]*int(item))
    return out_array

def delta_decode(in_array):
    """A function to delta decode an int array.

    :param in_array: the input array of integers
    :return the decoded array"""
    if len(in_array) == 0:
        return []
    this_ans = in_array[0]
    out_array = [this_ans]
    for i in range(1, len(in_array)):
        this_ans += in_array[i]
        out_array.append(this_ans)
    return out_array