mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-24 05:18:58 +00:00
Readme for array
This commit is contained in:
parent
83c32dc1a6
commit
1264c64a15
@ -31,10 +31,40 @@ array.forEach(0, 100, (pos, val) -> {
|
|||||||
## Query Buffers
|
## Query Buffers
|
||||||
|
|
||||||
The library offers many operations for sorting and dealing with sorted data.
|
The library offers many operations for sorting and dealing with sorted data.
|
||||||
Especially noteworthy are the operations `retain()` and `reject()` in
|
The classes [IntQueryBuffer](src/main/java/nu/marginalia/array/buffer/IntQueryBuffer.java)
|
||||||
([IntArraySearch](src/main/java/nu/marginalia/array/algo/IntArraySearch.java) and [LongArraySearch](src/main/java/nu/marginalia/array/algo/LongArraySearch.java)) which act upon the
|
and [LongQueryBuffer](src/main/java/nu/marginalia/array/buffer/LongQueryBuffer.java) are used
|
||||||
classes [IntQueryBuffer](src/main/java/nu/marginalia/array/buffer/IntQueryBuffer.java)
|
heavily in the search engine's query processing.
|
||||||
and [LongQueryBuffer](src/main/java/nu/marginalia/array/buffer/LongQueryBuffer.java);
|
|
||||||
they keep or remove all items in the buffer that exist in the range. These are used
|
|
||||||
to offer an intersection operation for the B-Tree that has in practice sub-linear run time.
|
|
||||||
|
|
||||||
|
They are dual-pointer buffers that offer tools for filtering data.
|
||||||
|
|
||||||
|
```java
|
||||||
|
LongQueryBuffer buffer = new LongQueryBuffer(1000);
|
||||||
|
|
||||||
|
fillBuffer(buffer);
|
||||||
|
|
||||||
|
// A typical filtering operation may look like this:
|
||||||
|
|
||||||
|
while (buffer.hasMore()) { // read < end
|
||||||
|
if (someCondition(buffer.currentValue())) {
|
||||||
|
// copy the value pointed to by the read
|
||||||
|
// pointer to the read pointer, and
|
||||||
|
// advance both
|
||||||
|
buffer.retainAndAdvance();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// advance the read pointer
|
||||||
|
buffer.rejectAndAdvance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the read pointer to the read pointer
|
||||||
|
// after this we can filter again
|
||||||
|
|
||||||
|
buffer.finalizeFiltering();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Especially noteworthy are the operations `retain()` and `reject()` in
|
||||||
|
[IntArraySearch](src/main/java/nu/marginalia/array/algo/IntArraySearch.java) and [LongArraySearch](src/main/java/nu/marginalia/array/algo/LongArraySearch.java).
|
||||||
|
They keep or remove all items in the buffer that exist in the range. These are used
|
||||||
|
to offer an intersection operation for the B-Tree that has in practice sub-linear run time.
|
||||||
|
Loading…
Reference in New Issue
Block a user