pub struct TableRegistry { /* private fields */ }Expand description
The table registry takes care of storing the records for each table,
using the [FreeSegmentsLedger] and [PageLedger] to derive exactly where to read/write.
A registry is generic over a record, which must implement Encode.
The CRUD operations provided by the table registry do NOT perform any logical checks, but just allow to read/write records from/to memory. So CRUD checks must be performed by a higher layer, prior to calling these methods.
Implementations§
Source§impl TableRegistry
impl TableRegistry
Sourcepub fn load(
table_pages: TableRegistryPage,
mm: &impl MemoryAccess,
) -> MemoryResult<Self>
pub fn load( table_pages: TableRegistryPage, mm: &impl MemoryAccess, ) -> MemoryResult<Self>
Loads the table registry from memory.
Sourcepub fn insert<E>(
&mut self,
record: E,
mm: &mut impl MemoryAccess,
) -> MemoryResult<()>where
E: Encode,
pub fn insert<E>(
&mut self,
record: E,
mm: &mut impl MemoryAccess,
) -> MemoryResult<()>where
E: Encode,
Inserts a new record into the table registry.
NOTE: this function does NOT make any logical checks on the record being inserted.
Sourcepub fn read<'a, E, MA>(&'a self, mm: &'a MA) -> TableReader<'a, E, MA>where
E: Encode,
MA: MemoryAccess,
pub fn read<'a, E, MA>(&'a self, mm: &'a MA) -> TableReader<'a, E, MA>where
E: Encode,
MA: MemoryAccess,
Creates a TableReader to read records from the table registry.
Use TableReader::try_next to read records one by one.
Sourcepub fn delete(
&mut self,
record: impl Encode,
page: Page,
offset: PageOffset,
mm: &mut impl MemoryAccess,
) -> MemoryResult<()>
pub fn delete( &mut self, record: impl Encode, page: Page, offset: PageOffset, mm: &mut impl MemoryAccess, ) -> MemoryResult<()>
Deletes a record at the given page and offset.
The space occupied by the record is marked as free and zeroed.
Sourcepub fn update(
&mut self,
new_record: impl Encode,
old_record: impl Encode,
old_page: Page,
old_offset: PageOffset,
mm: &mut impl MemoryAccess,
) -> MemoryResult<()>
pub fn update( &mut self, new_record: impl Encode, old_record: impl Encode, old_page: Page, old_offset: PageOffset, mm: &mut impl MemoryAccess, ) -> MemoryResult<()>
Updates a record at the given page and offset.
The logic is the following:
- If the new record has exactly the same size of the old record, overwrite it in place.
- If the new record does not fit, delete the old record and insert the new record.