2.0.14 • Published 2 years ago

@algorithm.ts/circular-queue v2.0.14

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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' }

Related

2.0.14

2 years ago

2.0.13

2 years ago

2.0.12

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.11

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.10

2 years ago

2.0.8

2 years ago

2.0.8-alpha.0

2 years ago

2.0.7-alpha.1

2 years ago

2.0.7-alpha.0

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.0-alpha.0

2 years ago

2.0.1

2 years ago

1.0.24

2 years ago

2.0.0

2 years ago

1.0.23

2 years ago

1.0.19

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago