Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@algorithm.ts/circular-queue

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algorithm.ts/circular-queue

Circular queue in Typescript

  • 2.0.14
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
696
decreased by-27.88%
Maintainers
1
Weekly downloads
 
Created
Source

@algorithm.ts/circular-queue


A typescript implementation of the Circular Queue data structure.

Circular queue is a queue structure, the main purpose of its design is to reuse space as much as possible on the basis of ordinary queues. Circular queues usually need to specify the maximum volume C of the collector. If the number of elements in the queue exceeds C, only the most recent C elements are kept in the queue. Other operations are the same as ordinary queues.

Install

  • npm

    npm install --save @algorithm.ts/circular-queue
    
  • yarn

    yarn add @algorithm.ts/circular-queue
    
  • deno

    import { createCircularQueue } from 'https://raw.githubusercontent.com/guanghechen/algorithm.ts/main/packages/circular-queue/src/index.ts'
    

Usage

  • Basic:

    import { createCircularQueue } from '@algorithm.ts/circular-queue'
    
    const queue = createCircularQueue<{ name: string }>()
    
    // Initialize the circular-queue with the maximum number of elements it can
    // be managed.
    queue.init(100)
    
    // Append a element to the end of the queue.
    queue.enqueue({ name: 'alice' })  // => 0
    queue.enqueue({ name: 'bob' }) // => 1
    queue.size()   // => 2
    
    // Get the front element of the queue.
    queue.front()       // => { name: 'alice' }
    
    // Get the last element of the queue.
    queue.end()         // => { name: 'bob' }
    
    // Take off the first element of the queue.
    queue.dequeue()     // => { name: 'alice' }
    queue.size()        // => 1
    
    // Test if the queue is empty.
    queue.isEmpty()     // => false
    
    queue.get(0)        // undefined
    queue.get(0, true)  // undefined
    queue.get(0, false) // { name: 'alice' }
    
    queue.get(1)        // => { name: 'bob' }
    queue.get(1, true)  // => { name: 'bob' }
    queue.get(1, false) // => { name: 'bob' }
    

Keywords

FAQs

Package last updated on 27 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc