MCPcopy Index your code
hub / github.com/Workiva/go-datastructures / orSparseWithSparseBitArray

Function orSparseWithSparseBitArray

bitarray/or.go:19–74  ·  view source on GitHub ↗
(sba *sparseBitArray,
	other *sparseBitArray)

Source from the content-addressed store, hash-verified

17package bitarray
18
19func orSparseWithSparseBitArray(sba *sparseBitArray,
20 other *sparseBitArray) BitArray {
21
22 if len(other.indices) == 0 {
23 return sba.copy()
24 }
25
26 if len(sba.indices) == 0 {
27 return other.copy()
28 }
29
30 max := maxInt64(int64(len(sba.indices)), int64(len(other.indices)))
31 indices := make(uintSlice, 0, max)
32 blocks := make(blocks, 0, max)
33
34 selfIndex := 0
35 otherIndex := 0
36 for {
37 // last comparison was a real or, we are both exhausted now
38 if selfIndex == len(sba.indices) && otherIndex == len(other.indices) {
39 break
40 } else if selfIndex == len(sba.indices) {
41 indices = append(indices, other.indices[otherIndex:]...)
42 blocks = append(blocks, other.blocks[otherIndex:]...)
43 break
44 } else if otherIndex == len(other.indices) {
45 indices = append(indices, sba.indices[selfIndex:]...)
46 blocks = append(blocks, sba.blocks[selfIndex:]...)
47 break
48 }
49
50 selfValue := sba.indices[selfIndex]
51 otherValue := other.indices[otherIndex]
52
53 switch diff := int(otherValue) - int(selfValue); {
54 case diff > 0:
55 indices = append(indices, selfValue)
56 blocks = append(blocks, sba.blocks[selfIndex])
57 selfIndex++
58 case diff < 0:
59 indices = append(indices, otherValue)
60 blocks = append(blocks, other.blocks[otherIndex])
61 otherIndex++
62 default:
63 indices = append(indices, otherValue)
64 blocks = append(blocks, sba.blocks[selfIndex].or(other.blocks[otherIndex]))
65 selfIndex++
66 otherIndex++
67 }
68 }
69
70 return &sparseBitArray{
71 indices: indices,
72 blocks: blocks,
73 }
74}
75
76func orSparseWithDenseBitArray(sba *sparseBitArray, other *bitArray) BitArray {

Callers 4

OrMethod · 0.85

Calls 3

maxInt64Function · 0.85
orMethod · 0.80
copyMethod · 0.45

Tested by 3

Used in the wild real call sites across dependent graphs

searching dependent graphs…