UNPKG

agentscape

Version:

Agentscape is a library for creating agent-based simulations. It provides a simple API for defining agents and their behavior, and for defining the environment in which the agents interact. Agentscape is designed to be flexible and extensible, allowing

37 lines (29 loc) 755 B
export default class FixedQueue<T> { private queue: T[] private maxSize: number constructor(maxSize: number) { this.queue = [] this.maxSize = maxSize } public get size(): number { return this.queue.length } public asArray(): T[] { return this.queue } public enqueue(value: T): void { if (this.queue.length >= this.maxSize) { this.queue.shift() } this.queue.push(value) } public dequeue(): T | undefined { return this.queue.shift() } public get(index: number): T { return this.queue[index] } public forEach(callback: (value: T, index: number) => void): void { this.queue.forEach(callback) } }