add Peek method to RecordQueue

This commit is contained in:
2025-11-12 12:47:31 +00:00
parent 7d6ba54f8a
commit 67b8540cb1
2 changed files with 56 additions and 9 deletions

View File

@@ -36,14 +36,10 @@ func (rq *RecordQueue) Push(r Record) {
rq.l.PushBack(r)
}
// Pop removes and returns the first Record of the list as the first return value. If the list is
// Pop removes and returns the first Record of the queue in the 1st return value. If the list is
// empty returns falso on the 2nd return value, true otherwise.
func (rq *RecordQueue) Pop() (Record, bool) {
if rq == nil || rq.l == nil {
return nil, false
}
el := rq.l.Front()
el := rq.frontElement()
if el == nil {
return nil, false
}
@@ -53,6 +49,25 @@ func (rq *RecordQueue) Pop() (Record, bool) {
return val.(Record), true
}
// Peek returns the front Record of the queue in the 1st return value. If the list is empty returns
// falso on the 2nd return value, true otherwise.
func (rq *RecordQueue) Peek() (Record, bool) {
el := rq.frontElement()
if el == nil {
return nil, false
}
return el.Value.(Record), true
}
func (rq *RecordQueue) frontElement() *list.Element {
if rq == nil || rq.l == nil {
return nil
}
return rq.l.Front()
}
func (rq *RecordQueue) Len() int {
if rq == nil || rq.l == nil {
return 0