(sba *sparseBitArray, other *sparseBitArray)
| 17 | package bitarray |
| 18 | |
| 19 | func 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 | |
| 76 | func orSparseWithDenseBitArray(sba *sparseBitArray, other *bitArray) BitArray { |
searching dependent graphs…