shrinkUniqueManual function
Compresses a list of unique integers using a specified method.
Important: The automatic shrinkUnique function is recommended over this manual option in most cases, as it intelligently selects the optimal compression algorithm, which can yield significantly better compression ratios for different data patterns.
This function allows you to manually select the compression algorithm instead of using the automatic selection in shrinkUnique.
ids
: The list of integers to compressmethod
: The compression method to use
Returns a compressed Uint8List representation of the integer list. The first byte indicates the method used, following the same format as shrinkUnique.
Implementation
Uint8List shrinkUniqueManual(List<int> ids, UniqueCompressionMethod method) {
// Make a copy and ensure the list is sorted
final sortedIds = [...ids]..sort();
// Apply the specified compression method
Uint8List compressed;
switch (method) {
case UniqueCompressionMethod.deltaVarint:
compressed = _encodeDeltaVarint(sortedIds);
break;
case UniqueCompressionMethod.runLength:
compressed = _encodeRuns(sortedIds);
break;
case UniqueCompressionMethod.chunked:
compressed = _encodeChunked(sortedIds);
break;
case UniqueCompressionMethod.bitmask:
compressed = _encodeBitmask(sortedIds);
break;
}
// Create result with method byte + compressed data
final result = Uint8List(compressed.length + 1);
result[0] = method.index; // First byte stores the method enum ordinal
result.setRange(1, result.length, compressed);
return result;
}