This module contains seq-based containers useful in contexts that make use of data-oriented design
Types
Checkpoint = distinct int
- Represents the state of a Store at some point in time. Source Edit
OrdinalSeq[I; T] = distinct seq[T]
- Similar to a seq, but can only be accessed by values of the specified type. This is useful in situations where the type of the index value is a distinct integer-like type Source Edit
PartialStore[I; T] = object data: seq[T] base: I
-
Used for adding items to an existing Store without directly modifying said object nor requiring access to it.
The usual usage pattern is:
- fork a partial store from a Store object
- add items to the partial store
- once done, join the partial store with the store it was forked from
It's also legal to add items to a partial store that wasn't forked from a store. In this case, it can only be joined into empty stores.
Source Edit
Procs
func `==`(a, b: Checkpoint): bool {.borrow, ...raises: [], tags: [].}
- Source Edit
func `[]`[I; T](s: PartialStore[I, T]; id: I): lent T {.inline.}
- Returns the item associated with id. Source Edit
func add[I; T](s: var PartialStore[I, T]; item: sink T): I
- Adds item to s, returning the ID to later query it with. Source Edit
func add[I; T](x: var OrdinalSeq[I, T]; item: sink T): I {.inline.}
- Source Edit
func add[I; T](x: var Store[I, T]; it: sink T): I {.inline.}
- Appends a new item to the Store and returns the ID assigned to it Source Edit
func checkpoint(s: Store): Checkpoint
- Source Edit
func contains[K, V](m: SeqMap[K, V]; key: K): bool {.inline.}
- Returns whether a value with key key exists in the map Source Edit
func fork[I; T](s: Store[I, T]): PartialStore[I, T]
- Creates a new partial table that can later be joined back (via join) into s. Source Edit
func join[I; T](s: var Store[I, T]; other: sink PartialStore[I, T])
- Adds all items from other to s. s has to have the same number of items it had when other was forked from it. Source Edit
func merge[I; T](dst: var Store[I, T]; src: sink Store[I, T]): Option[I]
- Merges src into dst and returns the ID of the first-merged item. If src has no items, none(I) is returned. Source Edit
func newSeq[I; T](x: var OrdinalSeq[I, T]; len: int) {.inline.}
- Source Edit
func nextId[I; T](x: Store[I, T]): I {.inline.}
- Returns the ID that would be assigned to the next added item. Source Edit
func rewind(s: var Store; p: Checkpoint)
- Removes all items added since p was created. Do note that modifications to items already existing when p was created are not reverted. Source Edit
func setLen[I; T](x: var OrdinalSeq[I, T]; len: int) {.inline.}
- Source Edit
func synchronize[I; A; B](x: var OrdinalSeq[I, A]; s: Store[I, B])
-
Synchronizes the number of elements x has with that of s.
s must be larger than or equal in size to x: if this is not the case, behaviour is undefined.
Source Edit
Iterators
iterator mitems[I; T](x: var Store[I, T]): var T
- Yields a mutable item for each entry in x. Source Edit
iterator mpairs[K, V](m: var SeqMap[K, V]): (K, var V)
- Returns, in an unspecified order, the key and mutable value for each entry in the map m. Source Edit
iterator pairs[I, T](x: Store[I, T]): (I, lent T)
- Iterates over and returns all items in x together with their corresponding IDs Source Edit
iterator pairs[I; T](x: OrdinalSeq[I, T]): (I, lent T)
- Source Edit
iterator pairs[K, V](m: SeqMap[K, V]): (K, lent V)
- Returns, in an unspecified order, the key and value for each entry in the map m. Source Edit
iterator since[I; T](s: Store[I, T]; p: Checkpoint): (I, lent T)
- Returns all items together with their ID added since p was created. Source Edit
Templates
template `[]=`[I; T](x: OrdinalSeq[I, T]; i: I; item: T): untyped
- Source Edit
template `[]=`[I; T](x: var Store[I, T]; i: I; it: T): untyped
- Overwrites the item corresponding to i with it Source Edit
template `[]`[I; T](x: OrdinalSeq[I, T]; i: I): untyped
- Source Edit
template base[I; T](x: OrdinalSeq[I, T]): seq[T]
- Returns underlying seq of x. Source Edit
template len[I; T](x: OrdinalSeq[I, T]): int
- Source Edit