Class BinarySearchOnSortedFile
java.lang.Object
org.aksw.commons.io.binseach.BinarySearchOnSortedFile
- All Implemented Interfaces:
AutoCloseable, BinarySearcher
Binary search over sorted files with memory mapped IO
TODO Move to a separate project as this is of general use
TODO Allow cache to be shared between concurrent readers
- Author:
- raven
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Seekableprotected longprotected AutoCloseableprotected byte -
Constructor Summary
ConstructorsConstructorDescriptionBinarySearchOnSortedFile(AutoCloseable closeAction, Seekable baseSeekable, long baseSeekableSize, byte delimiter) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static BinarySearchOnSortedFilestatic longgetPosOfFirstMatch(Seekable seekable, byte delimiter, byte[] prefix) The initial position is assumed point to the delimiter The result will point to the initial position or a preceding delimiter If there is no preceding delimiter, the seekable will be positioned before startstatic InputStreamnewInputStream(Seekable channel, BinSearchScanState state) search(byte[] prefixBytes) The high-level search method.searchCore(String prefix) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BinarySearcher
parallelSearch
-
Field Details
-
baseSeekable
-
closeAction
-
channelSize
protected long channelSize -
delimiter
protected byte delimiter
-
-
Constructor Details
-
BinarySearchOnSortedFile
public BinarySearchOnSortedFile(AutoCloseable closeAction, Seekable baseSeekable, long baseSeekableSize, byte delimiter)
-
-
Method Details
-
create
- Throws:
IOException
-
newInputStream
-
search
The high-level search method. The search result is an input stream over the matching region. The binary search will only seek the offset of the region; the end detection occurs on-the-fly when serving requested data.- Specified by:
searchin interfaceBinarySearcher- Parameters:
prefix-- Returns:
-
searchCore
- Throws:
IOException
-
search
- Specified by:
searchin interfaceBinarySearcher- Throws:
IOException
-
getPosOfFirstMatch
public static long getPosOfFirstMatch(Seekable seekable, byte delimiter, byte[] prefix) throws IOException The initial position is assumed point to the delimiter The result will point to the initial position or a preceding delimiter If there is no preceding delimiter, the seekable will be positioned before start- Parameters:
seekable-delimiter-prefix-- Returns:
- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceBinarySearcher- Throws:
Exception
-