Skip to content

Commit

Permalink
$mol_slicer: pager for range with temp push
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Sep 16, 2023
1 parent 1f73174 commit f76b65f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
23 changes: 16 additions & 7 deletions range3/range3.test.ts → slicer/slicer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,38 @@ namespace $ {
}

function make_range() {
const range = new $mol_range3<string>()
const chunk_size = 10
const chunks = [
stub_ids(chunk_size),
stub_ids(chunk_size),
stub_ids(chunk_size / 2),
]
const count = chunks.reduce((acc, row) => acc + row.length, 0)

const range = new $mol_slicer<string>()
range.count = () => count
range.chunk_size = () => chunk_size
range.chunk = offset => chunks[offset]
range.chunk = offset => chunks[offset / chunk_size]

return { range, chunks }
return { range, chunks, count }
}

$mol_test({

'chunk addressing'() {
const { range, chunks } = make_range()
'chunk addressing'($) {
const { range, chunks, count } = make_range()
const arr = range.range()

$mol_assert_equal(arr[0], chunks[0][0])
$mol_assert_equal(arr[1], chunks[0][1])
$mol_assert_equal(arr.at(-1), chunks.at(-1)?.at(-1))
},

'push temp'($) {
const { range, chunks, count } = make_range()
const arr = range.range()
$mol_assert_equal(arr.length, count)
range.push('123')
$mol_assert_equal(arr.length, count + 1)
$mol_assert_equal(arr.at(-1), '123')
}

})
Expand Down
4 changes: 2 additions & 2 deletions range3/range3.ts → slicer/slicer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace $ {
export class $mol_range3<Item> extends $mol_range2_array<Item> {
export class $mol_slicer<Item> extends $mol_object {
count(): number {
throw new Error('implement')
}
Expand Down Expand Up @@ -73,7 +73,7 @@ namespace $ {

@ $mol_mem
range() {
return $mol_range2(index => this.at(index), () => this.length, this) as readonly Item[]
return $mol_range2(index => this.at(index), () => this.length) as readonly Item[]
}

}
Expand Down

0 comments on commit f76b65f

Please sign in to comment.