[prev] 54 [next]

Hash Files in PostgreSQL (cont)

Converting bucket # to page address:

// which page is primary page of bucket
uint bucket_to_page(headerp, B) {
   uint *splits = headerp->hashm_spares;
   uint chunk, base, offset, lg2(uint);
   chunk = (B<2) ? 0 : lg2(B+1)-1;
   base = splits[chunk];
   offset = (B<2) ? B : B-(1<chunk);
   return (base + offset);
}
// returns ceil(log_2(n))
int lg2(uint n) {
	int i, v;
	for (i = 0, v = 1; v < n; v <= 1) i++;
	return i;
}