func()

in cpc/cpc_sketch.go [503:542]


func (c *CpcSketch) bitMatrixOfSketch() ([]uint64, error) {
	k := uint64(1) << c.lgK
	offset := c.windowOffset
	if offset < 0 || offset > 56 {
		return nil, fmt.Errorf("offset < 0 || offset > 56")
	}
	matrix := make([]uint64, k)
	if c.numCoupons == 0 {
		return matrix, nil // Returning a matrix of zeros rather than NULL.
	}
	//Fill the matrix with default rows in which the "early zone" is filled with ones.
	//This is essential for the routine's O(k) time cost (as opposed to O(C)).
	defaultRow := (1 << offset) - 1
	for i := range matrix {
		matrix[i] = uint64(defaultRow)
	}
	if c.slidingWindow != nil { // In other words, we are in window mode, not sparse mode.
		for i, v := range c.slidingWindow { // set the window bits, trusting the sketch's current offset.
			matrix[i] |= uint64(v) << offset
		}
	}
	table := c.pairTable
	if table == nil {
		return nil, fmt.Errorf("table == nil")
	}
	slots := table.slotsArr
	numSlots := 1 << table.lgSizeInts
	for i := 0; i < numSlots; i++ {
		rowCol := slots[i]
		if rowCol != -1 {
			col := rowCol & 63
			row := rowCol >> 6
			// Flip the specified matrix bit from its default value.
			// In the "early" zone the bit changes from 1 to 0.
			// In the "late" zone the bit changes from 0 to 1.
			matrix[row] ^= 1 << col
		}
	}
	return matrix, nil
}