Classes

The following classes are available globally.

  • A write buffer that accumulates document insertions for a single batch flush.

    Obtain one via NyaruCollection.insertBatch(_:). All insertions are synchronous — no await needed. Documents are not written to disk until the insertBatch body completes without throwing.

    Note

    Deliberately not Sendable — the buffer is unsynchronised and must only be used from the insertBatch body that received it.
    See more

    Declaration

    Swift

    public final class NyaruInsertBatch<T> where T : Decodable, T : Encodable, T : Sendable
  • An in-memory sorted array-based index that maps FieldValue keys to posting lists of RecordPointer values.

    Architecture choice. This index uses a sorted array with binary search, giving O(log n) point lookups and trivially correct range scans — the same asymptotic performance as a B-tree. An array is significantly simpler to implement, test, and debug. Since the entire index is kept in memory, the O(n) insertion cost of shifting array elements is acceptable for the typical mobile workloads NyaruDB targets (hundreds to low thousands of unique keys).

    Persistence is O(n): the entire array is serialised at once using MsgPack and compressed with gzip. For the expected key counts this is negligible.

    Class semantics. OrderedIndex is a final class rather than a value type to avoid Swift’s Copy-on-Write (COW) penalties during bulk inserts. With COW, mutating an array-backed value type duplicates the entire internal storage on every mutation, which would make building indexes from a large shard scan quadratic.

    Thread safety. The @unchecked Sendable conformance is safe because OrderedIndex is always accessed from within a single CollectionCore actor, which serialises all mutations.

    See more

    Declaration

    Swift

    public final class OrderedIndex : Codable, @unchecked Sendable