String creates a string representation of the Bitmap
()
| 241 | |
| 242 | // String creates a string representation of the Bitmap |
| 243 | func (rb *Bitmap) String() string { |
| 244 | // inspired by https://github.com/fzandona/goroar/ |
| 245 | var buffer bytes.Buffer |
| 246 | start := []byte("{") |
| 247 | buffer.Write(start) |
| 248 | i := rb.Iterator() |
| 249 | counter := 0 |
| 250 | if i.HasNext() { |
| 251 | counter = counter + 1 |
| 252 | buffer.WriteString(strconv.FormatUint(i.Next(), 10)) |
| 253 | } |
| 254 | for i.HasNext() { |
| 255 | buffer.WriteString(",") |
| 256 | counter = counter + 1 |
| 257 | // to avoid exhausting the memory |
| 258 | if counter > 0x40000 { |
| 259 | buffer.WriteString("...") |
| 260 | break |
| 261 | } |
| 262 | buffer.WriteString(strconv.FormatUint(i.Next(), 10)) |
| 263 | } |
| 264 | buffer.WriteString("}") |
| 265 | return buffer.String() |
| 266 | } |
| 267 | |
| 268 | // Iterator creates a new IntPeekable to iterate over the integers contained in the bitmap, in sorted order; |
| 269 | // the iterator becomes invalid if the bitmap is modified (e.g., with Add or Remove). |