github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/engine/wazevo/wazevoapi/queue.go (about)

     1  package wazevoapi
     2  
     3  // Queue is the resettable queue where the underlying slice is reused.
     4  type Queue[T any] struct {
     5  	index int
     6  	Data  []T
     7  }
     8  
     9  func (q *Queue[T]) Enqueue(v T) {
    10  	q.Data = append(q.Data, v)
    11  }
    12  
    13  func (q *Queue[T]) Dequeue() (ret T) {
    14  	ret = q.Data[q.index]
    15  	q.index++
    16  	return
    17  }
    18  
    19  func (q *Queue[T]) Empty() bool {
    20  	return q.index >= len(q.Data)
    21  }
    22  
    23  func (q *Queue[T]) Reset() {
    24  	q.index = 0
    25  	q.Data = q.Data[:0]
    26  }