1. Disks and Pages

Basic Unit of Disk Storage:

Page Class:

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.
};

2. Adding Tuples to a 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;
}
  1. Space Check: Ensures the page has enough free space before adding a new tuple.
  2. Smart Pointer Transfer: Uses std::move to transfer ownership of the tuple to the page.

3. Serialization of Pages

Serialization converts the in-memory Page object into a format that can be stored on disk.

Serialization Process: