stradap / nest_websocket_gnz

Nest server to have a priority queue of calls coming from a third party service (WebSocket)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Support us

Description

Nest framework TypeScript starter repository.

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.

Algorithm (priority queue):

The essential operations of the priority queue are:

  • enqueue: insert elements on the queue
  • dequeue: remove elements from the queue in the same order they were inserted.

Enqueue The algorithm to insert an element is the following:

  • Insert the element into the next empty position (tail).
  • From that position, “bubble up” the element to keep the min-heap invariant “parent should be smaller than any children” (the opposite if max-heap).
  • If the invariant is broken, fix it by swapping the node with its parent and repeat the process all the way to the root node if necessary.

Complexity:

  • Time: O(log n), in the worst case, you will have to bubble up the inserted element up to the root of the tree. These will involve log n swaps, where n is the total number of nodes.
  • Space: O(n)

Dequeue

The algorithms for dequeuing an element is:

Remove the root element

  • Since the root element is gone, you need to fill the hole by promoting a child to take its place. This process is called “heapify” or bubbleDown.
  • You choose the child that has the min value for min-heap (or max value for max-heap). You do this recursively until you found a leaf (node without children).

Complexity:

  • Time: O(log n), The maximum number of swaps is given by the tree’s height, which is log n.
  • Space: O(n).

About

Nest server to have a priority queue of calls coming from a third party service (WebSocket)


Languages

Language:TypeScript 100.0%