{"id":"allocate-page-prefers-free-list","text":"`allocate_page` always recycles from the free list before extending the file with a new page, keeping the data file compact after deletions","truth_value":"IN","source":"entries/2026/05/28/b-tree-storage-engine-btree-allocate_page.md","source_url":"","source_hash":"","justifications":[],"dependents":[],"metadata":{"example":"if free_head != NO_SIBLING:\n    page_num = free_head  # reuse freed page\n    new_head = struct.unpack(\">I\", page_data[HEADER_SIZE:HEADER_SIZE+4])[0]\nelse:\n    page_num = next_free  # allocate at end"},"explanation":{"steps":[{"node":"allocate-page-prefers-free-list","truth_value":"IN","reason":"premise"}]}}