Or returns a bit array resulting from a bitwise OR of the two bit arrays. If the two bit-arrys have different lengths, Or right-pads the smaller of the two bit-arrays with zeroes. Thus the size of the return value is the maximum of the two provided bit arrays.
(o *BitArray)
| 112 | // If the two bit-arrys have different lengths, Or right-pads the smaller of the two bit-arrays with zeroes. |
| 113 | // Thus the size of the return value is the maximum of the two provided bit arrays. |
| 114 | func (bA *BitArray) Or(o *BitArray) *BitArray { |
| 115 | if bA == nil && o == nil { |
| 116 | return nil |
| 117 | } |
| 118 | if bA == nil && o != nil { |
| 119 | return o.Copy() |
| 120 | } |
| 121 | if o == nil { |
| 122 | return bA.Copy() |
| 123 | } |
| 124 | bA.mtx.Lock() |
| 125 | o.mtx.Lock() |
| 126 | c := bA.copyBits(tmmath.MaxInt(bA.Bits, o.Bits)) |
| 127 | smaller := tmmath.MinInt(len(bA.Elems), len(o.Elems)) |
| 128 | for i := 0; i < smaller; i++ { |
| 129 | c.Elems[i] |= o.Elems[i] |
| 130 | } |
| 131 | bA.mtx.Unlock() |
| 132 | o.mtx.Unlock() |
| 133 | return c |
| 134 | } |
| 135 | |
| 136 | // And returns a bit array resulting from a bitwise AND of the two bit arrays. |
| 137 | // If the two bit-arrys have different lengths, this truncates the larger of the two bit-arrays from the right. |