Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deleteBitfieldPageRange #14

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ class WriteBatch {
this.write.tryDelete(encodeDataIndex(this.storage.dataPointer, DATA.BITFIELD, index))
}

deleteBitfieldPageRange (start, end) {
return this._deleteRange(DATA.BITFIELD, start, end)
}

_deleteRange (type, start, end) {
const s = encodeDataIndex(this.storage.dataPointer, type, start)
const e = encodeDataIndex(this.storage.dataPointer, type, end === -1 ? Infinity : end)
Expand Down
92 changes: 90 additions & 2 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ test('delete block range: no end', async function (t) {
{
const b = c.createWriteBatch()

b.deleteBlockRange(10244242, -1)
b.deleteBlockRange(10244243, -1)

await b.flush()
}
Expand All @@ -381,7 +381,7 @@ test('delete block range: no end', async function (t) {
const node4 = b.getBlock(10244245)
b.tryFlush()

t.alike(await node1, null)
t.alike(await node1, data1)
t.alike(await node2, null)
t.alike(await node3, null)
t.alike(await node4, null)
Expand Down Expand Up @@ -488,6 +488,94 @@ test('bitfield pages', async function (t) {
}
})

test('bitfield page: delete range', async function (t) {
const c = await getCore(t)

const empty = Buffer.alloc(4096)
const full = Buffer.alloc(4096, 0xff)

{
const b = c.createWriteBatch()

b.putBitfieldPage(0, empty)
b.putBitfieldPage(1, full)
b.putBitfieldPage(10244243, empty)
b.putBitfieldPage(10244244, full)

await b.flush()
}

{
const b = c.createReadBatch()

const page1 = b.getBitfieldPage(0)
const page2 = b.getBitfieldPage(1)
const page3 = b.getBitfieldPage(10244243)
const page4 = b.getBitfieldPage(10244244)
const pageNull = b.getBitfieldPage(2)
b.tryFlush()

t.alike(await page1, empty)
t.alike(await page2, full)
t.alike(await page3, empty)
t.alike(await page4, full)
t.alike(await pageNull, null)
}

{
const b = c.createWriteBatch()

b.deleteBitfieldPageRange(1, 10244244)

await b.flush()
}

{
const b = c.createReadBatch()

const page1 = b.getBitfieldPage(0)
const page2 = b.getBitfieldPage(1)
const page3 = b.getBitfieldPage(10244243)
const page4 = b.getBitfieldPage(10244244)
b.tryFlush()

t.alike(await page1, empty)
t.alike(await page2, null)
t.alike(await page3, null)
t.alike(await page4, full)
}

{
const b = c.createWriteBatch()

b.deleteBitfieldPageRange(0, -1)

await b.flush()
}

{
const b = c.createReadBatch()

const page1 = b.getBitfieldPage(0)
const page4 = b.getBitfieldPage(10244244)
b.tryFlush()

t.alike(await page1, null)
t.alike(await page4, null)
}

t.alike(await c.peakLastBitfieldPage(), null)

{
const pages = []
for await (const page of c.createBitfieldPageStream()) {
pages.push(page)
}

t.alike(pages, [])
}
})

test('make lots of cores in parallel', async function (t) {
const s = await getStorage(t)
const promises = []
Expand Down
Loading