Skip to main content

DictStore

Struct DictStore 

Source
pub struct DictStore {
    pub entities: EntityTable,
    /* private fields */
}
Expand description

Storage for all PostScript dictionaries.

The entity table maps EntityId → index into dicts. For Phase 2 this is a 1:1 mapping (entity N → dicts[N]), but the indirection enables save_level tracking and future COW.

Fields§

§entities: EntityTable

Implementations§

Source§

impl DictStore

Source

pub fn new() -> Self

Source

pub fn dict_slots(&self) -> usize

Allocate a new dictionary with the given maximum length and name. Number of dict slots handed out so far; the store’s high-water mark.

Source

pub fn truncate_to(&mut self, dicts_len: usize, entity_len: usize)

Release every dict slot and entity from the given marks onward.

Used by restore to reclaim the objects a save level created. See crate::entity_table::EntityTable::truncate for the safety argument and the EntityId-reuse caveat.

Source

pub fn allocate(&mut self, max_length: usize, name: &[u8]) -> EntityId

Source

pub fn allocate_with( &mut self, max_length: usize, name: &[u8], save_level: u16, global: bool, created_after_save: u32, ) -> EntityId

Allocate with a specific save level and global flag.

Source

pub fn iter_entities(&self) -> impl Iterator<Item = (EntityId, &DictEntry)>

Iterate every allocated dictionary in this store as (EntityId, &DictEntry).

Used by the VM audit (see crate::vm_audit) to sweep global VM for PLRM 3.7.2 violations. Iterating entities rather than following references from a root set is deliberate: it catches dictionaries that nothing reachable points at, and it does not depend on writes having gone through DictStore::put.

Source

pub fn get(&self, entity: EntityId, key: &DictKey) -> Option<PsObject>

Look up a key in a dictionary.

Source

pub fn put(&mut self, entity: EntityId, key: DictKey, value: PsObject)

Insert or update a key-value pair.

Source

pub fn known(&self, entity: EntityId, key: &DictKey) -> bool

Check if a key exists.

Source

pub fn get_name(&self, entity: EntityId) -> &[u8]

Get the dict’s name.

Source

pub fn set_name(&mut self, entity: EntityId, name: &[u8])

Set the dict’s name.

Source

pub fn length(&self, entity: EntityId) -> usize

Current number of entries.

Source

pub fn max_length(&self, entity: EntityId) -> usize

Maximum capacity.

Source

pub fn remove(&mut self, entity: EntityId, key: &DictKey)

Remove a key.

Source

pub fn entry(&self, entity: EntityId) -> &DictEntry

Borrow the dict entry.

Source

pub fn entry_mut(&mut self, entity: EntityId) -> &mut DictEntry

Mutably borrow the dict entry.

Source

pub fn keys(&self, entity: EntityId) -> impl Iterator<Item = &DictKey>

Iterate over keys of a dictionary.

Source

pub fn access(&self, entity: EntityId) -> u8

Get the access level of a dictionary.

Source

pub fn require_read(&self, entity: EntityId) -> Result<(), PsError>

Require read access on a dict. Returns InvalidAccess if access < READ_ONLY.

Source

pub fn require_write(&self, entity: EntityId) -> Result<(), PsError>

Require write access on a dict. Returns InvalidAccess if access < UNLIMITED.

Source

pub fn set_access(&mut self, entity: EntityId, access: u8)

Set the access level of a dictionary.

Source

pub fn cow_copy(&mut self, entity: EntityId) -> EntityId

Copy a dictionary’s contents to a new dict (for COW). Returns the new EntityId. The original entity is updated to point at the copy; the returned entity points at the original data (the backup).

Source

pub fn swap_offsets(&mut self, a: EntityId, b: EntityId)

Swap indices between two entities (used by restore).

Trait Implementations§

Source§

impl Default for DictStore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.