This repository has been archived by the owner on Mar 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,463 additions
and
814 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/main/java/ru/vk/itmo/plyasovklimentii/ByteArraySegment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package ru.vk.itmo.plyasovklimentii; | ||
|
||
import java.io.IOException; | ||
import java.lang.foreign.MemorySegment; | ||
import java.nio.ByteBuffer; | ||
|
||
/** | ||
* Growable buffer with {@link ByteBuffer} and {@link MemorySegment} interface. | ||
* | ||
* @author incubos | ||
*/ | ||
final class ByteArraySegment { | ||
private byte[] array; | ||
private MemorySegment segment; | ||
|
||
ByteArraySegment(final int capacity) { | ||
this.array = new byte[capacity]; | ||
this.segment = MemorySegment.ofArray(array); | ||
} | ||
|
||
void withArray(final ArrayConsumer consumer) throws IOException { | ||
consumer.process(array); | ||
} | ||
|
||
MemorySegment segment() { | ||
return segment; | ||
} | ||
|
||
void ensureCapacity(final long size) { | ||
if (size > Integer.MAX_VALUE) { | ||
throw new IllegalArgumentException("Too big!"); | ||
} | ||
|
||
final int capacity = (int) size; | ||
if (array.length >= capacity) { | ||
return; | ||
} | ||
|
||
// Grow to the nearest bigger power of 2 | ||
final int newSize = Integer.highestOneBit(capacity) << 1; | ||
array = new byte[newSize]; | ||
segment = MemorySegment.ofArray(array); | ||
} | ||
|
||
interface ArrayConsumer { | ||
void process(byte[] array) throws IOException; | ||
} | ||
} |
274 changes: 0 additions & 274 deletions
274
src/main/java/ru/vk/itmo/plyasovklimentii/DiskStorage.java
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
src/main/java/ru/vk/itmo/plyasovklimentii/LiveFilteringIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ru.vk.itmo.plyasovklimentii; | ||
|
||
import ru.vk.itmo.Entry; | ||
|
||
import java.lang.foreign.MemorySegment; | ||
import java.util.Iterator; | ||
import java.util.NoSuchElementException; | ||
|
||
/** | ||
* Filters non tombstone {@link Entry}s. | ||
* | ||
* @author incubos | ||
*/ | ||
final class LiveFilteringIterator implements Iterator<Entry<MemorySegment>> { | ||
private final Iterator<Entry<MemorySegment>> delegate; | ||
private Entry<MemorySegment> next; | ||
|
||
LiveFilteringIterator(final Iterator<Entry<MemorySegment>> delegate) { | ||
this.delegate = delegate; | ||
skipTombstones(); | ||
} | ||
|
||
private void skipTombstones() { | ||
while (delegate.hasNext()) { | ||
final Entry<MemorySegment> entry = delegate.next(); | ||
if (entry.value() != null) { | ||
this.next = entry; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return next != null; | ||
} | ||
|
||
@Override | ||
public Entry<MemorySegment> next() { | ||
if (!hasNext()) { | ||
throw new NoSuchElementException(); | ||
} | ||
|
||
// Consume | ||
final Entry<MemorySegment> result = next; | ||
next = null; | ||
|
||
skipTombstones(); | ||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.