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

package replaydetector

import (
	
)

// fixedBigInt is the fix-sized multi-word integer.
type fixedBigInt struct {
	bits    []uint64
	n       uint
	msbMask uint64
}

// newFixedBigInt creates a new fix-sized multi-word int.
func newFixedBigInt( uint) *fixedBigInt {
	 := ( + 63) / 64
	if  == 0 {
		 = 1
	}
	return &fixedBigInt{
		bits:    make([]uint64, ),
		n:       ,
		msbMask: (1 << (64 - %64)) - 1,
	}
}

// Lsh is the left shift operation.
func ( *fixedBigInt) ( uint) {
	if  == 0 {
		return
	}
	 := int( / 64)
	 :=  % 64

	for  := len(.bits) - 1;  >= 0; -- {
		var  uint64
		if - >= 0 {
			 = .bits[-] << 
			if --1 >= 0 {
				 |= .bits[--1] >> (64 - )
			}
		}
		.bits[] = (.bits[] << ) | 
	}
	.bits[len(.bits)-1] &= .msbMask
}

// Bit returns i-th bit of the fixedBigInt.
func ( *fixedBigInt) ( uint) uint {
	if  >= .n {
		return 0
	}
	 :=  / 64
	 :=  % 64
	if .bits[]&(1<<) != 0 {
		return 1
	}
	return 0
}

// SetBit sets i-th bit to 1.
func ( *fixedBigInt) ( uint) {
	if  >= .n {
		return
	}
	 :=  / 64
	 :=  % 64
	.bits[] |= 1 << 
}

// String returns string representation of fixedBigInt.
func ( *fixedBigInt) () string {
	var  string
	for  := len(.bits) - 1;  >= 0; -- {
		 += fmt.Sprintf("%016X", .bits[])
	}
	return 
}