// SPDX-FileCopyrightText: 2023 The Pion community // SPDX-License-Identifier: MIT package sctp import ( "fmt" "math/bits" ) type receivePayloadQueue struct { tailTSN uint32 chunkSize int tsnBitmask []uint64 dupTSN []uint32 maxTSNOffset uint32 cumulativeTSN uint32 } func newReceivePayloadQueue(maxTSNOffset uint32) *receivePayloadQueue { maxTSNOffset = ((maxTSNOffset + 63) / 64) * 64 return &receivePayloadQueue{ tsnBitmask: make([]uint64, maxTSNOffset/64), maxTSNOffset: maxTSNOffset, } } func (q *receivePayloadQueue) init(cumulativeTSN uint32) { q.cumulativeTSN = cumulativeTSN q.tailTSN = cumulativeTSN q.chunkSize = 0 for i := range q.tsnBitmask { q.tsnBitmask[i] = 0 } q.dupTSN = q.dupTSN[:0] } func (q *receivePayloadQueue) hasChunk(tsn uint32) bool { if q.chunkSize == 0 || sna32LTE(tsn, q.cumulativeTSN) || sna32GT(tsn, q.tailTSN) { return false } index, offset := int(tsn/64)%len(q.tsnBitmask), tsn%64 return q.tsnBitmask[index]&(1<> uint64(start)) return i + start, i+start < end } func getFirstZeroBit(val uint64, start, end int) (int, bool) { return getFirstNonZeroBit(^val, start, end) }