// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package sctp

type queue[ any] struct {
	buf   []
	head  int
	tail  int
	count int
}

const minCap = 16

func newQueue[ any]( int) *queue[] {
	 := minCap
	for  <  {
		 <<= 1
	}

	return &queue[]{
		buf: make([], ),
	}
}

func ( *queue[]) () int {
	return .count
}

func ( *queue[]) ( ) {
	.growIfFull()
	.buf[.tail] = 
	.tail = (.tail + 1) % len(.buf)
	.count++
}

func ( *queue[]) ()  {
	 := .buf[.head]
	var  
	.buf[.head] = 
	.head = (.head + 1) % len(.buf)
	.count--

	return 
}

func ( *queue[]) ()  {
	return .buf[.head]
}

func ( *queue[]) ()  {
	return .buf[(.tail-1+len(.buf))%len(.buf)]
}

func ( *queue[]) ( int)  {
	return .buf[(.head+)%(len(.buf))]
}

func ( *queue[]) () {
	if .count < len(.buf) {
		return
	}

	 := make([], .count<<1)
	if .tail > .head {
		copy(, .buf[.head:.tail])
	} else {
		 := copy(, .buf[.head:])
		copy([:], .buf[:.tail])
	}

	.head = 0
	.tail = .count
	.buf = 
}