MCPcopy Create free account
hub / github.com/Workiva/go-datastructures / nandSparseWithDenseBitArray

Function nandSparseWithDenseBitArray

bitarray/nand.go:86–116  ·  view source on GitHub ↗
(sba *sparseBitArray, other *bitArray)

Source from the content-addressed store, hash-verified

84}
85
86func nandSparseWithDenseBitArray(sba *sparseBitArray, other *bitArray) BitArray {
87 // Since nand is non-commutative, the resulting array should be sparse,
88 // and the same length or less than the sparse array
89 indices := make(uintSlice, 0, len(sba.indices))
90 blocks := make(blocks, 0, len(sba.indices))
91
92 var resultBlock block
93
94 // Loop through the sparse array and match it with the dense array.
95 for selfIndex, selfValue := range sba.indices {
96 if selfValue >= uint64(len(other.blocks)) {
97 // Since the dense array is exhausted, just copy over the data
98 // from the sparse array
99 resultBlock = sba.blocks[selfIndex]
100 indices = append(indices, selfValue)
101 blocks = append(blocks, resultBlock)
102 continue
103 }
104
105 resultBlock = sba.blocks[selfIndex].nand(other.blocks[selfValue])
106 if resultBlock > 0 {
107 indices = append(indices, selfValue)
108 blocks = append(blocks, resultBlock)
109 }
110 }
111
112 return &sparseBitArray{
113 indices: indices,
114 blocks: blocks,
115 }
116}
117
118func nandDenseWithSparseBitArray(sba *bitArray, other *sparseBitArray) BitArray {
119 // Since nand is non-commutative, the resulting array should be dense,

Callers 5

NandMethod · 0.85

Calls 1

nandMethod · 0.80

Used in the wild real call sites across dependent graphs

searching dependent graphs…