The Page
class represents a single page on disk, which can store multiple tuples.
class Page {
public:
size_t used_size = 0; // Tracks how much space is used in the page.
std::vector<std::unique_ptr<Tuple>> tuples; // Stores tuples (records) in the page.
};
used_size
: Keeps track of how much space is already occupied.tuples
: A vector of smart pointers to tuples stored in the page.The addTuple
function inserts a tuple into the page if there is enough space.
bool addTuple(std::unique_ptr<Tuple> tuple) {
size_t tuple_size = /* calculate size of tuple */;
// Check if there's enough space in the page.
if (used_size + tuple_size > PAGE_SIZE)
return false;
// Add the tuple to the page and update the used size.
tuples.push_back(std::move(tuple));
used_size += tuple_size;
return true;
}
std::move
to transfer ownership of the tuple to the page.Serialization converts the in-memory Page
object into a format that can be stored on disk.