ForEach will iterate through the buffer items
(fn func(t T) (end bool))
| 46 | |
| 47 | // ForEach will iterate through the buffer items |
| 48 | func (c *circularBuffer[T]) ForEach(fn func(t T) (end bool)) (ended bool) { |
| 49 | // First index is at starting position |
| 50 | index := c.start |
| 51 | // Iterate for the length of the buffer |
| 52 | for i := 0; i < c.len; i++ { |
| 53 | // Get item at current index |
| 54 | item := c.s[index] |
| 55 | // Pass item to func |
| 56 | if fn(item) { |
| 57 | // Func returned break boolean as true, return true |
| 58 | return true |
| 59 | } |
| 60 | |
| 61 | // Increment index and see if index exceeds length |
| 62 | if index++; index >= c.len { |
| 63 | // Index exceeds length, set to 0 |
| 64 | index = 0 |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | return |
| 69 | } |
| 70 | |
| 71 | // Len will return the length of a circular buffer |
| 72 | func (c *circularBuffer[T]) Len() int { |
no outgoing calls