ludic.base: an IntIndex slot's list made with room for 16 rows, so filing in play does not grow it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8a4f3f5ad6
commit
d6b3242b25
1 changed files with 10 additions and 3 deletions
|
|
@ -2,6 +2,13 @@
|
||||||
# slot; a large one (a chunk's packed cell) is given the next slot through a map, so a sparse
|
# slot; a large one (a chunk's packed cell) is given the next slot through a map, so a sparse
|
||||||
# value costs one list and not every list up to it
|
# value costs one list and not every list up to it
|
||||||
const IX_DENSE: int = 1024 # a value below this is its own slot; above, one is given it
|
const IX_DENSE: int = 1024 # a value below this is its own slot; above, one is given it
|
||||||
|
const IX_CAP: int = 16 # rows a value's list holds before it grows: a list grown in play is a new block
|
||||||
|
|
||||||
|
function ix_list_new() -> words {
|
||||||
|
let l = words(IX_CAP)
|
||||||
|
List.clear(l)
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
|
||||||
# the slot value v's list is in, -1 when it has none (and `make` did not ask for one)
|
# the slot value v's list is in, -1 when it has none (and `make` did not ask for one)
|
||||||
function ix_slot(ix: IntIndex, v: int, make: bool) -> int {
|
function ix_slot(ix: IntIndex, v: int, make: bool) -> int {
|
||||||
|
|
@ -9,15 +16,15 @@ function ix_slot(ix: IntIndex, v: int, make: bool) -> int {
|
||||||
if v < IX_DENSE {
|
if v < IX_DENSE {
|
||||||
if v >= len(ix.lists) {
|
if v >= len(ix.lists) {
|
||||||
if not make { return -1 }
|
if not make { return -1 }
|
||||||
while len(ix.lists) <= v { push(ix.lists, words(0)) }
|
while len(ix.lists) <= v { push(ix.lists, ix_list_new()) }
|
||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
var s = imap_get(ix.sparse, v, -1)
|
var s = imap_get(ix.sparse, v, -1)
|
||||||
if s < 0 and make {
|
if s < 0 and make {
|
||||||
while len(ix.lists) < IX_DENSE { push(ix.lists, words(0)) }
|
while len(ix.lists) < IX_DENSE { push(ix.lists, ix_list_new()) }
|
||||||
s = len(ix.lists)
|
s = len(ix.lists)
|
||||||
push(ix.lists, words(0))
|
push(ix.lists, ix_list_new())
|
||||||
imap_put(ix.sparse, v, s)
|
imap_put(ix.sparse, v, s)
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue