21/34
Part 5 of 7 · Alignment and growthLearn and do
Shrinking always works, and the cut-off units merge like any free
Shrinking is the easy half of resize. Say n is the new, smaller size:
0123456789
A holds 6
AAAAAA
[(6, 10)]
shrink A to 2
AA
[(2, 10)]: the cut-off units merged with (6, 10).
The units cut off the end are free now, and they may touch the run after them, so they go back through the same merge as any free. Here they joined (6, 10).
The block keeps its start, so the dict key doesn't change, and it keeps its owner. Growing or shrinking a block never touches owned.
shrink(blocks, free, addr, n) is the shrink half of resize, and give_back from the merging part sits above it in the editor. Write shrink, and the figure's block of 6 units becomes 2.