mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-24 13:19:02 +00:00
Readme for btree
This commit is contained in:
parent
2423735a20
commit
449c62b666
@ -13,25 +13,25 @@ BTreeContext ctx = new BTreeContext(
|
|||||||
1, // entry size
|
1, // entry size
|
||||||
512); // block size bits
|
512); // block size bits
|
||||||
|
|
||||||
// Allocate a memory area to work in, see the array library for how to do this with files
|
// Allocate a memory area to work in, see the array library for how to do this with files
|
||||||
LongArray array = LongArray.allocate(8192);
|
LongArray array = LongArray.allocate(8192);
|
||||||
|
|
||||||
// Write a btree at offset 123 in the area
|
// Write a btree at offset 123 in the area
|
||||||
long[] items = new long[400];
|
long[] items = new long[400];
|
||||||
BTreeWriter writer = new BTreeWriter(array, ctx);
|
BTreeWriter writer = new BTreeWriter(array, ctx);
|
||||||
final int offsetInFile = 123;
|
final int offsetInFile = 123;
|
||||||
|
|
||||||
long btreeSize = writer.write(offsetInFile, items.length, slice -> {
|
long btreeSize = writer.write(offsetInFile, items.length, slice -> {
|
||||||
// we're *must* write items.length * entry.size words in slice
|
// we're *must* write items.length * entry.size words in slice
|
||||||
// these items must be sorted!!
|
// these items must be sorted!!
|
||||||
|
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (int i = 0; i < items.length; i++) {
|
||||||
slice.set(i, items[i]);
|
slice.set(i, items[i]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Read the BTree
|
// Read the BTree
|
||||||
|
|
||||||
BTreeReader reader = new BTreeReader(array, ctx, offsetInFile);
|
BTreeReader reader = new BTreeReader(array, ctx, offsetInFile);
|
||||||
reader.findEntry(items[0]);
|
reader.findEntry(items[0]);
|
||||||
```
|
```
|
Loading…
Reference in New Issue
Block a user