code: func (f *freelist) allocate(n int) pgid {
  	if len(f.ids) == 0 {
  		return 0
  	}
  
  	var initial, previd pgid
  	for i, id := range f.ids {
  		if id <= 1 {
  			panic(fmt.Sprintf("invalid page allocation: %d", id))
  		}
  
  		// Reset initial page if this is not contiguous.
  		if previd == 0 || id-previd != 1 {
  			initial = id
  		}
  
  		// If we found a contiguous block then remove it and return it.
  		if (id-initial)+1 == pgid(n) {
  			// If we're allocating off the beginning then take the fast path
  			// and just adjust the existing slice. This will use extra memory
  			// temporarily but the append() in free() will realloc the slice
  			// as is necessary.
  			if (i + 1) == n {
  				f.ids = f.ids[i+1:]
  			} else {
  				copy(f.ids[i-n+1:], f.ids[i+1:])
  				f.ids = f.ids[:len(f.ids)-n]
  			}
  
  			// Remove from the free cache.
  			for i := pgid(0); i < pgid(n); i++ {
  				delete(f.cache, initial+i)
  			}
  
  			return initial
  		}
  
  		previd = id
  	}
  	return 0
  }
docs: // allocate returns the starting page id of a contiguous list of pages of a given size.
  // If a contiguous block cannot be found then 0 is returned.