Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TreeNodeDynamicSize impl part 10 - Zero pad empty space
Previously, space that was left empty after removing key pointers and children was not padded with zeroes. If this empty space was later partly used by data space (the actual keys) and then reclaimed we would have broken unused child pointers left as a result. This is not problem until you want to reuse this space for child pointers again. But when you do, you read the (broken) child pointer that is their before writing what you want to write. Because this garbage data is interpreted as a broken child pointer we can not overwrite it. See visual below. We fix this problem by always padding space left empty with zeroes so that it can be reused for children later. [HEADER] [KEYS_AND_CHILDREN] [EMPTY_SPACE] [DATA_SPACE] [HEADER] [C0,K0*,C1,K1*,C2,K2*,C3] [EMPTY ] [SOME_DATA] - Removing K2*C3 without padding [HEADER] [C0,K0*,C1,K1*,C2] [K2*,C3 EMPTY ] [SOME_DATA] - Data grows, breaking the unused child pointer [HEADER] [C0,K0*,C1,K1*,C2] [K2*,C] [SOME_DATA ] - Defragment shrinks data space [HEADER] [C0,K0*,C1,K1*,C2] [K2*,C EMPTY ] [SOME_DATA ] - Insert a new K* and C, need to read space where C3 used to be. This is now garbage data and can not be read. FAIL v [HEADER] [C0,K0*,C1,K1*,C2] [K2*,C EMPTY ] [SOME_DATA ]
- Loading branch information
Showing
4 changed files
with
54 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters