in cpc/cpc_compressed_state.go [463:526]
func (c *CpcCompressedState) uncompressSlidingFlavor(src *CpcSketch) error {
// Ensure that cwStream is not nil.
if c.CwStream == nil {
return fmt.Errorf("uncompressSlidingFlavor: expected cwStream to be non-nil")
}
// Uncompress the window portion.
if err := uncompressTheWindow(src, c); err != nil {
return err
}
srcLgK := c.LgK
numPairs := int(c.NumCsv)
if numPairs == 0 {
// Create an empty pair table.
pt, err := NewPairTable(2, 6+srcLgK)
if err != nil {
return err
}
src.pairTable = pt
} else {
// Ensure csvStream is present.
if c.CsvStream == nil {
return fmt.Errorf("uncompressSlidingFlavor: expected csvStream to be non-nil")
}
// Uncompress the surprising values.
pairs, err := uncompressTheSurprisingValues(c)
if err != nil {
return err
}
// Determine pseudoPhase.
pseudoPhase := determinePseudoPhase(srcLgK, int64(c.NumCoupons))
if pseudoPhase >= 16 {
return fmt.Errorf("uncompressSlidingFlavor: pseudoPhase %d out of range", pseudoPhase)
}
permutation := columnPermutationsForDecoding[pseudoPhase]
// Get the window offset; it must be in (0, 56].
offset := c.getWindowOffset()
if offset <= 0 || offset > 56 {
return fmt.Errorf("uncompressSlidingFlavor: invalid window offset %d", offset)
}
// For each pair, undo the permutation and rotation.
for i := 0; i < numPairs; i++ {
rowCol := pairs[i]
row := rowCol >> 6
col := rowCol & 63
// First, undo the permutation.
col = int(permutation[col])
// Then, undo the rotation: old = (new + (offset+8)) mod 64.
col = (col + (offset + 8)) & 63
pairs[i] = (row << 6) | col
}
// Create a new pair table from the adjusted pairs.
table, err := newInstanceFromPairsArray(pairs, numPairs, srcLgK)
if err != nil {
return err
}
src.pairTable = table
}
return nil
}