From 62bafd9af773097de9b3dd9a001231ceec094f65 Mon Sep 17 00:00:00 2001 From: Joren Date: Tue, 18 Jun 2024 17:38:01 +0200 Subject: [PATCH] Add contains --- ringbuffer/ringbuffer.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ringbuffer/ringbuffer.go b/ringbuffer/ringbuffer.go index d8125ca..b363395 100644 --- a/ringbuffer/ringbuffer.go +++ b/ringbuffer/ringbuffer.go @@ -73,3 +73,16 @@ func (rb *RingBuffer) GetLastPosition() int { return rb.tail } +func (rb *RingBuffer) ContainsItem(item string) bool { + rb.mu.Lock() + defer rb.mu.Unlock() + + for i := 0; i < rb.size; i++ { + index := (rb.head + i) % rb.size + if rb.buffer[index] == item { + return true + } + } + + return false +}