Proofs: WebGraph compression
These are the human proofs of WebGraph compression, at full length.
Decoding the WebGraph stream recovers every successor list full
This proof shows: correctness, termination.
We use the pseudocode and the format of the page. The input is sorted lists of distinct integers, a window and .
Claim. DECODE(ENCODE, ) returns .
Step 1 (the codes). The gamma code is prefix-free: is zeros followed by the bits of , which start with 1, so a reader counts the zeros and then knows the length. So reading a field returns the value written, and the reader stops at the end of the field. The map is a bijection from the integers to the naturals, with inverse for even and for odd . So every field written as or is read back as or , provided , which Steps 3 and 4 check.
Step 2 (induction on ). We show that after the decoder has read the part of list , it holds and stands at the start of the part of list . The base is the field . Assume the claim for all lists before . The decoder reads ; if the encoder wrote nothing else (line L1), and the list is empty. Otherwise it reads (line L4). If , then by line L2, and by the hypothesis the decoder holds .
Step 3 (copy blocks). Let be the runs of the mask of , alternating 1s and 0s and starting with 1s. All runs after the first are non-empty, because a run ends only where the next bit differs. The encoder wrote , then and for ; it omitted . The decoder rebuilds , walks through with them, keeping the elements of the runs of 1s, and gives the rest of , which is exactly run , the kind that comes next in the alternation. So it obtains the copied set .
Step 4 (intervals and residuals). Let , sorted. Line L7 cuts into maximal runs of consecutive integers; the runs of length are the intervals , and the other elements are the residuals . Since the runs are maximal and is sorted, : if , the integer would extend run . So the fields and are , and the decoder rebuilds each interval from the previous end. Since the residuals are distinct and sorted, . The decoder knows , reads residuals, the first as and each next one as the previous plus plus the field.
Step 5 (the list). , the intervals and the residuals are disjoint and their union is , by the definitions of and and because the runs partition . So sorting their union gives , and the decoder has read exactly the fields written for and stands at the start of the part of . This completes the induction.
Termination. The encoder runs a loop over with inner loops over finite lists. The decoder reads one field per field written, and each read consumes at least one bit, so it stops after reading the whole string.