Programming Language

Nocter

A self-contained systems language built around simplicity, encapsulation, and foolproof design.

/development/std/internal/table/index.nct

index.nct

//! Package-private associative storage.
//!
//! Parallel dense key/value stores own initialized user values; buckets contain only entry
//! indices and occupancy state. The table owns hashing, probing, replacement, removal, growth,
//! and failure-atomic rebuilding. Public Map and Set APIs do not observe this representation.

use /hash.{Hash, HashState}
use /mem.TryAllocator
see ./storage.nct
see ./probing.nct
see ./growth.nct
see ./mutation.nct
see ./iteration.nct

pub(/) struct Table<K, V>

/// One readonly dense entry projected without exposing table metadata.
pub(/) copy struct TableEntryRef<K, V> {
    pub(/) key: &K
    pub(/) value: &V
}

/// One entry with a stable readonly key and an exclusive value loan.
pub(/) struct TableEntryMut<K, V> {
    pub(/) key: &K
    pub(/) value: &+V
}

/// One entry transferred out of an owning table cursor.
pub(/) struct TableEntry<K, V> {
    pub(/) key: K
    pub(/) value: V
}

pub(/) struct TableIter<K, V>

instance TableIter<K, V> {
    pub(/) method &self.remaining(): usize
    pub(/) method &+self.advance(): TableEntryRef<K, V>?
}

pub(/) struct TableIterMut<K, V>

instance TableIterMut<K, V> {
    pub(/) method &self.remaining(): usize
    pub(/) method &+self.advance(): TableEntryMut<K, V>?
}

pub(/) struct TableIntoIter<K, V>

instance TableIntoIter<K, V> {
    pub(/) method &self.remaining(): usize
    pub(/) method &+self.advance(): TableEntry<K, V>?
}

construct Table<K, V> {
    pub(/) func empty(): Self where K impl Hash

    pub(/) func with_capacity(minimum: usize): Self where K impl Hash

    pub(/) func try_with_capacity(
        allocator: &+TryAllocator,
        minimum: usize,
    ): Self! where K impl Hash
}

instance Table<K, V> where K impl Hash {
    pub(/) method &self.len(): usize
    pub(/) method &self.is_empty(): bool
    pub(/) method &self.capacity(): usize

    pub(/) method &self.get(key: &K): &V?
    pub(/) method &+self.get_mut(key: &K): &+V?
    pub(/) method &self.contains_key(key: &K): bool

    pub(/) method &+self.insert(key: K, value: V): V?
    pub(/) method &+self.try_insert(key: K, value: V): V?!
    pub(/) method &+self.remove(key: &K): V?
    pub(/) method &+self.clear(): void
    pub(/) method &+self.reserve(additional: usize): void
    pub(/) method &+self.try_reserve(additional: usize): void!

    pub(/) method &self.equals(other: &Self): bool where (&V == &V): bool

    pub(/) method &self.iter(): TableIter<K, V>
    pub(/) method &+self.iter_mut(): TableIterMut<K, V>
    pub(/) method self.into_iter(): TableIntoIter<K, V>
}