restoreUnique function

List<int> restoreUnique(
  1. Uint8List compressed
)

Decompresses a Uint8List created by shrinkUnique back to a list of integers.

This function reads the compression method from the first byte and then applies the appropriate decompression algorithm to restore the original list.

Returns the original list of unique integers. Throws an error if the compressed data is corrupted or uses an unknown method.

Implementation

List<int> restoreUnique(Uint8List compressed) {
  if (compressed.isEmpty) {
    return [];
  }

  // Extract method byte
  final methodIndex = compressed[0];
  final method = UniqueCompressionMethod.values[methodIndex];

  // Extract compressed data (skip method byte)
  final data = Uint8List.sublistView(compressed, 1);

  // Decompress based on method
  switch (method) {
    case UniqueCompressionMethod.deltaVarint:
      return _decodeDeltaVarint(data);
    case UniqueCompressionMethod.runLength:
      return _decodeRuns(data);
    case UniqueCompressionMethod.chunked:
      return _decodeChunked(data);
    case UniqueCompressionMethod.bitmask:
      return _decodeBitmask(data);
  }
}