cbytesparse.c.collapse_blocks

cbytesparse.c.collapse_blocks(blocks)

Collapses a generic sequence of blocks.

Given a generic sequence of blocks, writes them in the same order, generating a new sequence of non-contiguous blocks, sorted by address.

Parameters

blocks (sequence of blocks) – Sequence of blocks to collapse.

Returns

list of blocks – Collapsed block list.

Examples

0

1

2

3

4

5

6

7

8

9

[0

1

2

3

4

5

6

7

8

9]

[A

B

C

D]

[E

F]

[$]

[x

y

z]

[$

B

C

E

F

5

x

y

z

9]

>>> blocks = [
...     [0, b'0123456789'],
...     [0, b'ABCD'],
...     [3, b'EF'],
...     [0, b'$'],
...     [6, b'xyz'],
... ]
>>> collapse_blocks(blocks)
[[0, b'$BCEF5xyz9']]

~~~

0

1

2

3

4

5

6

7

8

9

[0

1

2]

[A

B]

[x

y

z]

[$]

[0

$

2]

[A

B

x

y

z]

>>> blocks = [
...     [0, b'012'],
...     [4, b'AB'],
...     [6, b'xyz'],
...     [1, b'$'],
... ]
>>> collapse_blocks(blocks)
[[0, b'0$2'], [4, b'ABxyz']]