Equals returns a bool indicating if these two bit arrays are equal.
(other BitArray)
| 255 | |
| 256 | // Equals returns a bool indicating if these two bit arrays are equal. |
| 257 | func (ba *bitArray) Equals(other BitArray) bool { |
| 258 | if other.Capacity() == 0 && ba.highest > 0 { |
| 259 | return false |
| 260 | } |
| 261 | |
| 262 | if other.Capacity() == 0 && !ba.anyset { |
| 263 | return true |
| 264 | } |
| 265 | |
| 266 | var selfIndex uint64 |
| 267 | for iter := other.Blocks(); iter.Next(); { |
| 268 | toIndex, otherBlock := iter.Value() |
| 269 | if toIndex > selfIndex { |
| 270 | for i := selfIndex; i < toIndex; i++ { |
| 271 | if ba.blocks[i] > 0 { |
| 272 | return false |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | selfIndex = toIndex |
| 278 | if !ba.blocks[selfIndex].equals(otherBlock) { |
| 279 | return false |
| 280 | } |
| 281 | selfIndex++ |
| 282 | } |
| 283 | |
| 284 | lastIndex, _ := getIndexAndRemainder(ba.highest) |
| 285 | if lastIndex >= selfIndex { |
| 286 | return false |
| 287 | } |
| 288 | |
| 289 | return true |
| 290 | } |
| 291 | |
| 292 | // Intersects returns a bool indicating if the supplied bitarray intersects |
| 293 | // this bitarray. This will check for intersection up to the length of the supplied |