Elias-Fano access and next-geq are correct, and the space bound full
This proof shows: correctness, space.
Let 0≤x0≤⋯≤xn−1<u, let ℓ be as in line L1, and write xi=hi2ℓ+li with 0≤li<2ℓ. Then hi=⌊xi/2ℓ⌋≤⌊(u−1)/2ℓ⌋, and h0≤h1≤⋯≤hn−1 because ⌊⋅/2ℓ⌋ is monotone.
Lemma 1. The 1s of H are exactly at the positions qi=hi+i, these are strictly increasing in i, and they lie inside H.
Proof. Line L4 sets the bits qi and no others. qi+1−qi=hi+1−hi+1≥1. The largest is qn−1≤⌊(u−1)/2ℓ⌋+n−1, less than the length of H. □
Access. By Lemma 1 the (i+1)-th 1 of H, in increasing order, is at qi, so SELECT1H(i+1)−i=hi. Line L5 returns hi2ℓ+Lo[i]=hi2ℓ+li=xi.
Lemma 2. For h≥0 with h≤⌊(u−1)/2ℓ⌋, let ph=0 if h=0 and ph=SELECT0H(h)+1 otherwise. Then ph−h=∣{i:hi<h}∣.
Proof. For h=0 both sides are 0. Let h≥1. H has ⌊(u−1)/2ℓ⌋+1≥h+1 zeros, since it has n ones and length n+⌊(u−1)/2ℓ⌋+1, so the h-th 0 exists. Before position qi there are exactly qi−i=hi zeros, because the other i positions before qi hold the 1s q0,…,qi−1. So qi comes before the h-th 0 if and only if hi<h: if hi<h, at most h−1 zeros precede qi; if hi≥h, the h-th 0 precedes qi. The positions 0,…,ph−1 contain exactly h zeros, and the ones among them are the qi with hi<h. Hence ph=h+∣{i:hi<h}∣. □
Next-geq. Let 0≤x<u, h=⌊x/2ℓ⌋, and let i∗=min{i:xi≥x}, or n if no such i exists. Line L8 sets i=ph−h, which by Lemma 2 is the number of elements with hi<h; by monotonicity these are x0,…,xi−1. Each of them satisfies xj<h2ℓ≤x, so i≤i∗. The loop of line L9 increases i while xi<x; since the sequence is nondecreasing, the elements xi,xi+1,…,xi∗−1 are all less than x, and xi∗≥x or i∗=n. So the loop stops exactly at i=i∗, which line L10 returns.
Space. The low bits take nℓ bits, and H has n ones and Z=⌊(u−1)/2ℓ⌋+1 zeros. If u≥n≥1 and ℓ=⌊lg(u/n)⌋, then ℓ+1>lg(u/n), so 2ℓ>u/(2n) and Z≤u/2ℓ+1<2n+1. The total is less than nℓ+3n+1 bits. If instead ℓ=⌈lg(u/n)⌉, then 2ℓ≥u/n, Z≤n+1, and the total is at most n⌈lg(u/n)⌉+2n+1. ■