diff --git a/ring.go b/ring.go index 2214c4b..3564555 100644 --- a/ring.go +++ b/ring.go @@ -35,6 +35,21 @@ func (r Ring) Capacity() int { return len(r.buff) } +/* +ContentSize returns the current number of elements inside the ring buffer. +*/ +func (r *Ring) ContentSize() int { + if r.head == -1 { + return 0 + } else { + difference := (r.head - r.tail) + if difference < 0 { + difference = -difference + } + return difference + 1 + } +} + /* Enqueue a value into the Ring buffer. */