/**
 * Thin abstraction around a Uint32Array which allows to push tokens
 * whithout caring for the offset. It is used as a way to avoid multiple
 * allocations while calling tokenization (mostly beneficitial for
 * `NetworkFilter.getTokens()`).
 */ export class TokensBuffer { private readonly buffer : Uint32Array ; public pos : number = 0 ; constructor ( size ) { this . buffer = new Uint32Array ( size ) ; } public reset ( ) { this . pos = 0 ; } public slice ( ) { return this . buffer . slice ( 0 , this . pos ) ; } public push ( token ) { this . buffer [ this . pos ++ ] = token ; } public empty ( ) { return this . pos === 0 ; } public full ( ) { return this . pos === this . buffer . length ; } public remaining ( ) { return this . buffer . length - this . pos ; } } export const TOKENS_BUFFER = new TokensBuffer ( 1024 ) ;