Class SixBitBinarySearch
Performs binary search on data compressed by SixBitAsciiCompressor. The data must have been sorted prior
to compression.
If prefixSearch is true, the method returns the first element whose prefix matches the specified
key. Otherwise, it looks for an exact match. When multiple elements share the same prefix, the first matching element
is returned (just as in the exact‐match search).
Null elements are considered to come after any character, in the same way that Z comes after A. This is because
the compressedData array typically has extra space to accommodate new entries, so unused slots (nulls) are
placed at the end.
Note that character ordering depends on the sequence defined in your custom charset (via
supportedCharset), which is passed to the compressor constructor (see
SixBitAsciiCompressor(byte[])). If no custom charset is provided, compressors use a
default charset ordered by ASCII.
- See Also:
-
Field Summary
Fields inherited from class com.dannemann.stringcompressor.search.BaseBinarySearch
charset, compressedData, prefixSearch -
Constructor Summary
ConstructorsConstructorDescriptionSixBitBinarySearch(byte[][] compressedData, boolean prefixSearch) Creates a binary search object for data compressed with the default character setSixBitAsciiCompressor.DEFAULT_6BIT_CHARSET.SixBitBinarySearch(byte[][] compressedData, boolean prefixSearch, byte[] charset) Creates a binary search object. -
Method Summary
Modifier and TypeMethodDescriptionintsearch(byte[] key) Performs a binary search on the provided compressed data array to locate the specified key.Methods inherited from class com.dannemann.stringcompressor.search.BaseBinarySearch
getCharset, getCompressedData, isPrefixSearch
-
Constructor Details
-
SixBitBinarySearch
public SixBitBinarySearch(byte[][] compressedData, boolean prefixSearch) Creates a binary search object for data compressed with the default character setSixBitAsciiCompressor.DEFAULT_6BIT_CHARSET.- Parameters:
compressedData- The mass of compressed strings to search through.prefixSearch- Iftrue, searches for elements starting with the provided key prefix (must be unique).- See Also:
-
SixBitBinarySearch
public SixBitBinarySearch(byte[][] compressedData, boolean prefixSearch, byte[] charset) Creates a binary search object.- Parameters:
compressedData- The mass of compressed strings to search through.prefixSearch- Iftrue, searches for elements starting with the provided key prefix (must be unique).charset- Character set used to compresscompressedData.
-
-
Method Details
-
search
public int search(byte[] key) Performs a binary search on the provided compressed data array to locate the specified key.
The compressed data is expected to be produced by
SixBitAsciiCompressorand must be sorted before compression for this search to work correctly. The search is performed directly on the compressed form without decompressing the entire dataset, enabling fast lookups in large in-memory compressed collections.The method returns the index of the matching element if found; otherwise, it returns
-(insertion point) - 1, following the contract ofArrays.binarySearch(long[], long).- Specified by:
searchin classBaseBinarySearch- Parameters:
key- The uncompressed key to search for, as a byte array.- Returns:
- The index of the search key if it is found; otherwise,
-(insertion point) - 1.
-