Basic idea: A Nim DSL that describes the game model declaratively
There is a raw
list/sequence of the data for fast iteration over all elements. The implementation
should be either based on an ordinary contiguous sequence or something like: http://plflib.org/colony.htm which is essentially a linked list of growing arrays so that no reallocations are required.
In addition to the contiguous storage there can be multiple indexes into the data. The indexes can be hash based or based on a BTree depending on whether ranges queries need to be supported. There is always a primary key of type integer that can be used to index the contiguous array.
An example:
table t:
type Entry = object
key: string
val: int
hashIndex key
btreeIndex val
with: del
shared: true
count C: val > 10
lazyCount B: val > 1000
From this declaration all the procedural code is generated, accessors ensure the different views on the data are kept up-to-date etc. t
supports lookups by key
because there is a hashIndex
on key
. It supports range queries on val
because there is a BTree index on val
.
- Deletion in a hash table implementation usually requires "tombstones", an implementation can be faster if deletion is not supported at all, hence deletion has to be enabled via
with: del
. shared: true
means it should use Nim's shared memory heap. All operations on the data then needs to take a lock. The implementation can use "lock stripes" or even atomic compare and swap loops to improve performance.count C: p
counts the number of entries that fullfill the predicatep
.C
is the name of the counter.lazyCount
does the same but the counter is only available after a full run iteration overt
and invalidated on every update operation.