Equals returns a bool indicating if the provided bit array equals this bitarray.
(other BitArray)
| 206 | // Equals returns a bool indicating if the provided bit array |
| 207 | // equals this bitarray. |
| 208 | func (sba *sparseBitArray) Equals(other BitArray) bool { |
| 209 | if other.Capacity() == 0 && sba.Capacity() > 0 { |
| 210 | return false |
| 211 | } |
| 212 | |
| 213 | var selfIndex uint64 |
| 214 | for iter := other.Blocks(); iter.Next(); { |
| 215 | otherIndex, otherBlock := iter.Value() |
| 216 | if len(sba.indices) == 0 { |
| 217 | if otherBlock > 0 { |
| 218 | return false |
| 219 | } |
| 220 | |
| 221 | continue |
| 222 | } |
| 223 | |
| 224 | if selfIndex >= uint64(len(sba.indices)) { |
| 225 | return false |
| 226 | } |
| 227 | |
| 228 | if otherIndex < sba.indices[selfIndex] { |
| 229 | if otherBlock > 0 { |
| 230 | return false |
| 231 | } |
| 232 | continue |
| 233 | } |
| 234 | |
| 235 | if otherIndex > sba.indices[selfIndex] { |
| 236 | return false |
| 237 | } |
| 238 | |
| 239 | if !sba.blocks[selfIndex].equals(otherBlock) { |
| 240 | return false |
| 241 | } |
| 242 | |
| 243 | selfIndex++ |
| 244 | } |
| 245 | |
| 246 | return true |
| 247 | } |
| 248 | |
| 249 | // Count returns the number of set bits in this array. |
| 250 | func (sba *sparseBitArray) Count() int { |