in cpc/cpc_compressed_state.go [366:412]
func (c *CpcCompressedState) uncompressPinnedFlavor(src *CpcSketch) error {
// The pinned flavor must have a non-nil cwStream.
if c.CwStream == nil {
return fmt.Errorf("uncompressPinnedFlavor: expected cwStream to be non-nil")
}
// Uncompress the window portion into the target sketch.
if err := uncompressTheWindow(src, c); err != nil {
return err
}
srcLgK := c.LgK
numPairs := int(c.NumCsv)
if numPairs == 0 {
// If there are no pairs, create an empty pair table.
pt, err := NewPairTable(2, 6+srcLgK)
if err != nil {
return err
}
src.pairTable = pt
} else {
// For pinned flavor, csvStream must be non-nil.
if c.CsvStream == nil {
return fmt.Errorf("uncompressPinnedFlavor: expected csvStream to be non-nil")
}
// Uncompress the surprising values.
pairs, err := uncompressTheSurprisingValues(c)
if err != nil {
return err
}
// Undo the compressor's 8-column shift:
// For each pair, the lower 6 bits (the column) must be less than 56.
// Then add 8 back.
for i := 0; i < numPairs; i++ {
if (pairs[i] & 63) >= 56 {
return fmt.Errorf("uncompressPinnedFlavor: invalid pair value %d at index %d", pairs[i], i)
}
pairs[i] += 8
}
// Create a new pair table from the corrected pairs array.
table, err := newInstanceFromPairsArray(pairs, numPairs, srcLgK)
if err != nil {
return err
}
src.pairTable = table
}
return nil
}