pub struct Table {
pub record_type: RecordType,
pub free_list_head: u32,
pub slots: Vec<Slot>,
pub indexes: TableIndexes,
/* private fields */
}Fields§
§record_type: RecordType§free_list_head: u32Head of the table’s free list: a link to the highest free slot, or 0
when every slot holds a record.
A link is (28 + 4 * slot) | 1 — the offset of that slot’s entry in the
slot array, with the low bit set to tell it from a record offset. The
slot it points at holds a link to the next free slot down, and the lowest
one holds 0. That is why a fresh, empty table carries 0x1d: one slot,
free, at 28 + 0.
slots: Vec<Slot>Record slots in file order. A slot’s index is the record number it holds.
indexes: TableIndexesThe table’s index region.
Implementations§
Source§impl Table
impl Table
Sourcepub fn records(&self) -> impl Iterator<Item = &Record>
pub fn records(&self) -> impl Iterator<Item = &Record>
Live records, skipping free and empty slots.
pub fn records_mut(&mut self) -> impl Iterator<Item = &mut Record>
pub fn record_count(&self) -> usize
Sourcepub fn next_record_number(&self) -> u32
pub fn next_record_number(&self) -> u32
Lowest unused record number. macOS numbers records from 0 upward.
Sourcepub fn insert(&mut self, record: Record) -> u32
pub fn insert(&mut self, record: Record) -> u32
Store a record, taking the head of the free list when there is one.
The record’s number is the slot it lands in — that is what a record number is here — so it is assigned rather than taken from the caller, and returned. The record’s bytes go at the end of the records region, the way macOS appends them, however low the reused slot number is.
Sourcepub fn delete(&mut self, number: u32) -> bool
pub fn delete(&mut self, number: u32) -> bool
Delete a record, freeing its slot the way macOS frees one.
The slot keeps its place unless it is the last one, in which case the array loses exactly that entry — trailing free slots below it are left alone, and the array never shrinks below one slot. Surviving records keep their numbers: index entries refer to records by number, and macOS never renumbers.
Returns whether a record was there to delete.
Sourcepub fn unique_index_attribute_ids(&self) -> Option<&[u32]>
pub fn unique_index_attribute_ids(&self) -> Option<&[u32]>
The attributes of the table’s unique index, by id.
None when this build could not parse the index region, or the table
declares no unique index.
Sourcepub fn has_record_with_unique_key(
&self,
relation: &Relation,
attributes: &[Option<Value>],
) -> bool
pub fn has_record_with_unique_key( &self, relation: &Relation, attributes: &[Option<Value>], ) -> bool
True when a record already has the same key as attributes under the
table’s unique index.
The unique index is the one the region marks kind == 1; the attributes
it names are the relation’s notion of identity, which is what macOS
refuses a duplicate of. A table whose index region this build could not
parse answers false: it cannot tell, and refusing a write macOS would
accept is worse than allowing it.
Sourcepub fn rebuild_indexes(&mut self, relation: &Relation) -> Result<()>
pub fn rebuild_indexes(&mut self, relation: &Relation) -> Result<()>
Rebuild every index from the table’s records.
Rebuilding rather than patching keeps the indexes consistent with the
records by construction; tests/keychain_index.rs checks that a rebuild
reproduces the entries and the ordering macOS wrote.