String creates a string representation of the Bitmap
()
| 944 | |
| 945 | // String creates a string representation of the Bitmap |
| 946 | func (rb *Bitmap) String() string { |
| 947 | // inspired by https://github.com/fzandona/goroar/ |
| 948 | var buffer bytes.Buffer |
| 949 | start := []byte("{") |
| 950 | buffer.Write(start) |
| 951 | i := rb.Iterator() |
| 952 | counter := 0 |
| 953 | if i.HasNext() { |
| 954 | counter = counter + 1 |
| 955 | buffer.WriteString(strconv.FormatInt(int64(i.Next()), 10)) |
| 956 | } |
| 957 | for i.HasNext() { |
| 958 | buffer.WriteString(",") |
| 959 | counter = counter + 1 |
| 960 | // to avoid exhausting the memory |
| 961 | if counter > 0x40000 { |
| 962 | buffer.WriteString("...") |
| 963 | break |
| 964 | } |
| 965 | buffer.WriteString(strconv.FormatInt(int64(i.Next()), 10)) |
| 966 | } |
| 967 | buffer.WriteString("}") |
| 968 | return buffer.String() |
| 969 | } |
| 970 | |
| 971 | // Iterate iterates over the bitmap, calling the given callback with each value in the bitmap. If the callback returns |
| 972 | // false, the iteration is halted. |