Proofs: Fully indexable dictionary
These are the human proofs of Fully indexable dictionary, at full length.
The queries of the fully indexable dictionary are correct full
This proof shows: correctness.
Let with , and let be its characteristic vector. Write for the elements of . We assume that the primitives are correct: ACCESS, RANK1, SELECT1 and SELECT0 is the -th smallest element of . These are the queries of the rank and select problem on .
MEMBER, RANK, SELECT (lines L1 to L3). if and only if , so line L1 is correct. counts the with , which are the elements of less than , so line L2 is correct. Line L3 returns by assumption.
PRED (lines L4 to L6). Let and . The elements of that are are exactly : they are the smallest elements of , because if then for each . If , no element is , and line L5 returns none, which is right. If , the largest of them is , and line L6 returns SELECT1.
SUCC (lines L7 to L9). Let . By the same argument, the elements less than are , so the elements are . If , there is none, and line L8 returns none. Otherwise the smallest is , which line L9 returns; SELECT1 is defined because .
RANK-OUT (line L10). Each with is in exactly one of and , so .
SELECT-OUT (line L11). The -th smallest element of is the position of the -th 0 of , which SELECT0 returns by assumption.
The primitives of the implementation. The Python code keeps in packed words with the count of 1s before superblock of words. Its rank adds , the counts of the full words of the superblock before word , and the count of the low bits of that word, which together cover exactly. Its select first finds by binary search the last superblock with fewer than wanted bits before it. Such a exists since superblock 0 has none before it, and the wanted bit is in superblock or later; it is not later, because the next superblock already has at least wanted bits before it, or does not exist. It then scans words from the start of superblock as in the SELECT1 of the bit vector, with the padding of the last word masked off for 0s.