1.0.0 • Published 8 months ago

@ryniaubenpm2/quae-consectetur-aut v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

data-structure-typed

npm GitHub contributors npm package minimized gzipped size (select exports) GitHub top language GITHUB Star eslint NPM npm

Installation and Usage

npm

npm i data-structure-typed --save

yarn

yarn add data-structure-typed
import {
  Heap, Graph, Queue, Deque, PriorityQueue, BST, Trie, DoublyLinkedList,
  AVLTree, SinglyLinkedList, DirectedGraph, RedBlackTree, TreeMultiMap,
  DirectedVertex, Stack, AVLTreeNode
} from 'data-structure-typed';

If you only want to use a specific data structure independently, you can install it separately, for example, by running

npm i heap-typed --save

Why

Do you envy C++ with STL (std::), Python with collections, and Java with java.util ? Well, no need to envy anymore! JavaScript and TypeScript now have data-structure-typed.Benchmark compared with C++ STL. API standards aligned with ES6 and Java. Usability is comparable to Python

Performance

Performance surpasses that of native JS/TS

Conciseness and uniformity

In java.utils, you need to memorize a table for all sequential data structures(Queue, Deque, LinkedList),

whereas in our data-structure-typed, you only need to remember four methods: push, pop, shift, and unshift for all sequential data structures(Queue, Deque, DoublyLinkedList, SinglyLinkedList and Array).

Data structures available

We provide data structures that are not available in JS/TS

Vivid Examples

AVL Tree

Try it out, or you can run your own code using our visual tool

npm.io

Tree Multi Map

Try it out

npm.io

Directed Graph

Try it out

npm.io

Map Graph

Try it out

npm.io

Code Snippets

Red Black Tree snippet

TS

import { RedBlackTree } from 'data-structure-typed';

const rbTree = new RedBlackTree<number>();
rbTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
rbTree.isAVLBalanced();    // true
rbTree.delete(10);
rbTree.isAVLBalanced();    // true
rbTree.print()
//         ___6________
//        /            \
//      ___4_       ___11________
//     /     \     /             \
//    _2_    5    _8_       ____14__
//   /   \       /   \     /        \
//   1   3       7   9    12__     15__
//                            \        \
//                           13       16

JS

import { RedBlackTree } from 'data-structure-typed';

const rbTree = new RedBlackTree();
rbTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
rbTree.isAVLBalanced();    // true
rbTree.delete(10);
rbTree.isAVLBalanced();    // true
rbTree.print()
//         ___6________
//        /            \
//      ___4_       ___11________
//     /     \     /             \
//    _2_    5    _8_       ____14__
//   /   \       /   \     /        \
//   1   3       7   9    12__     15__
//                            \        \
//                           13       16

Free conversion between data structures.

const orgArr = [6, 1, 2, 7, 5, 3, 4, 9, 8];
const orgStrArr = ["trie", "trial", "trick", "trip", "tree", "trend", "triangle", "track", "trace", "transmit"];
const entries = [[6, "6"], [1, "1"], [2, "2"], [7, "7"], [5, "5"], [3, "3"], [4, "4"], [9, "9"], [8, "8"]];

const queue = new Queue(orgArr);
queue.print();
// [6, 1, 2, 7, 5, 3, 4, 9, 8]

const deque = new Deque(orgArr);
deque.print();
// [6, 1, 2, 7, 5, 3, 4, 9, 8]

const sList = new SinglyLinkedList(orgArr);
sList.print();
// [6, 1, 2, 7, 5, 3, 4, 9, 8]

const dList = new DoublyLinkedList(orgArr);
dList.print();
// [6, 1, 2, 7, 5, 3, 4, 9, 8]

const stack = new Stack(orgArr);
stack.print();
// [6, 1, 2, 7, 5, 3, 4, 9, 8]

const minHeap = new MinHeap(orgArr);
minHeap.print();
// [1, 5, 2, 7, 6, 3, 4, 9, 8]

const maxPQ = new MaxPriorityQueue(orgArr);
maxPQ.print();
// [9, 8, 4, 7, 5, 2, 3, 1, 6]

const biTree = new BinaryTree(entries);
biTree.print();
//         ___6___
//        /       \
//     ___1_     _2_
//    /     \   /   \
//   _7_    5   3   4
//  /   \
//  9   8

const bst = new BST(entries);
bst.print();
//     _____5___
//    /         \
//   _2_       _7_
//  /   \     /   \
//  1   3_    6   8_
//        \         \
//        4         9


const rbTree = new RedBlackTree(entries);
rbTree.print();
//     ___4___
//    /       \
//   _2_     _6___
//  /   \   /     \
//  1   3   5    _8_
//              /   \
//              7   9


const avl = new AVLTree(entries);
avl.print();
//     ___4___
//    /       \
//   _2_     _6___
//  /   \   /     \
//  1   3   5    _8_
//              /   \
//              7   9

const treeMulti = new TreeMultiMap(entries);
treeMulti.print();
//     ___4___
//    /       \
//   _2_     _6___
//  /   \   /     \
//  1   3   5    _8_
//              /   \
//              7   9

const hm = new HashMap(entries);
hm.print()
// [[6, "6"], [1, "1"], [2, "2"], [7, "7"], [5, "5"], [3, "3"], [4, "4"], [9, "9"], [8, "8"]]

const rbTreeH = new RedBlackTree(hm);
rbTreeH.print();
//     ___4___
//    /       \
//   _2_     _6___
//  /   \   /     \
//  1   3   5    _8_
//              /   \
//              7   9

const pq = new MinPriorityQueue(orgArr);
pq.print();
// [1, 5, 2, 7, 6, 3, 4, 9, 8]

const bst1 = new BST(pq);
bst1.print();
//     _____5___
//    /         \
//   _2_       _7_
//  /   \     /   \
//  1   3_    6   8_
//        \         \
//        4         9

const dq1 = new Deque(orgArr);
dq1.print();
// [6, 1, 2, 7, 5, 3, 4, 9, 8]
const rbTree1 = new RedBlackTree(dq1);
rbTree1.print();
//    _____5___
//   /         \
//  _2___     _7___
// /     \   /     \
// 1    _4   6    _9
//      /         /
//      3         8


const trie2 = new Trie(orgStrArr);
trie2.print();
// ['trie', 'trial', 'triangle', 'trick', 'trip', 'tree', 'trend', 'track', 'trace', 'transmit']
const heap2 = new Heap(trie2, { comparator: (a, b) => Number(a) - Number(b) });
heap2.print();
// ['transmit', 'trace', 'tree', 'trend', 'track', 'trial', 'trip', 'trie', 'trick', 'triangle']
const dq2 = new Deque(heap2);
dq2.print();
// ['transmit', 'trace', 'tree', 'trend', 'track', 'trial', 'trip', 'trie', 'trick', 'triangle']
const entries2 = dq2.map((el, i) => [i, el]);
const avl2 = new AVLTree(entries2);
avl2.print();
//     ___3_______
//    /           \
//   _1_       ___7_
//  /   \     /     \
//  0   2    _5_    8_
//          /   \     \
//          4   6     9

Binary Search Tree (BST) snippet

import { BST, BSTNode } from 'data-structure-typed';

const bst = new BST<number>();
bst.add(11);
bst.add(3);
bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
bst.size === 16;                // true
bst.has(6);                     // true
const node6 = bst.getNode(6);   // BSTNode
bst.getHeight(6) === 2;         // true
bst.getHeight() === 5;          // true
bst.getDepth(6) === 3;          // true

bst.getLeftMost()?.key === 1;   // true

bst.delete(6);
bst.get(6);                     // undefined
bst.isAVLBalanced();            // true
bst.bfs()[0] === 11;            // true
bst.print()
//       ______________11_____           
//      /                     \          
//   ___3_______            _13_____
//  /           \          /        \    
//  1_     _____8____     12      _15__
//    \   /          \           /     \ 
//    2   4_       _10          14    16
//          \     /                      
//          5_    9
//            \                          
//            7

const objBST = new BST<number, { height: number, age: number }>();

objBST.add(11, { "name": "Pablo", "age": 15 });
objBST.add(3, { "name": "Kirk", "age": 1 });

objBST.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5], [
    { "name": "Alice", "age": 15 },
    { "name": "Bob", "age": 1 },
    { "name": "Charlie", "age": 8 },
    { "name": "David", "age": 13 },
    { "name": "Emma", "age": 16 },
    { "name": "Frank", "age": 2 },
    { "name": "Grace", "age": 6 },
    { "name": "Hannah", "age": 9 },
    { "name": "Isaac", "age": 12 },
    { "name": "Jack", "age": 14 },
    { "name": "Katie", "age": 4 },
    { "name": "Liam", "age": 7 },
    { "name": "Mia", "age": 10 },
    { "name": "Noah", "age": 5 }
  ]
);

objBST.delete(11);

AVLTree snippet

import { AVLTree } from 'data-structure-typed';

const avlTree = new AVLTree<number>();
avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
avlTree.isAVLBalanced();    // true
avlTree.delete(10);
avlTree.isAVLBalanced();    // true

Directed Graph simple snippet

import { DirectedGraph } from 'data-structure-typed';

const graph = new DirectedGraph<string>();

graph.addVertex('A');
graph.addVertex('B');

graph.hasVertex('A');       // true
graph.hasVertex('B');       // true
graph.hasVertex('C');       // false

graph.addEdge('A', 'B');
graph.hasEdge('A', 'B');    // true
graph.hasEdge('B', 'A');    // false

graph.deleteEdgeSrcToDest('A', 'B');
graph.hasEdge('A', 'B');    // false

graph.addVertex('C');

graph.addEdge('A', 'B');
graph.addEdge('B', 'C');

const topologicalOrderKeys = graph.topologicalSort(); // ['A', 'B', 'C']

Undirected Graph snippet

import { UndirectedGraph } from 'data-structure-typed';

const graph = new UndirectedGraph<string>();
graph.addVertex('A');
graph.addVertex('B');
graph.addVertex('C');
graph.addVertex('D');
graph.deleteVertex('C');
graph.addEdge('A', 'B');
graph.addEdge('B', 'D');

const dijkstraResult = graph.dijkstra('A');
Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', 'D']

API docs & Examples

API Docs

Live Examples

Examples Repository

Benchmark

MacBook Pro (15-inch, 2018)

Processor 2.2 GHz 6-Core Intel Core i7

Memory 16 GB 2400 MHz DDR4

Graphics Radeon Pro 555X 4 GB

Intel UHD Graphics 630 1536 MB

macOS Big Sur

Version 11.7.9

The corresponding relationships between data structures in different language standard libraries.

Built-in classic algorithms

Software Engineering Design Standards

We strictly adhere to computer science theory and software development standards. Our LinkedList is designed in the traditional sense of the LinkedList data structure, and we refrain from substituting it with a Deque solely for the purpose of showcasing performance test data. However, we have also implemented a Deque based on a dynamic array concurrently.

supported module system

Now you can use it in Node.js and browser environments

CommonJS:require export.modules =

ESModule:   import export

Typescript:   import export

UMD:           var Deque = dataStructureTyped.Deque

CDN

Copy the line below into the head tag in an HTML document.

development

<script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.js'></script>

production

<script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.min.js'></script>

Copy the code below into the script tag of your HTML, and you're good to go with your development.

const { Heap } = dataStructureTyped;
const {
  BinaryTree, Graph, Queue, Stack, PriorityQueue, BST, Trie, DoublyLinkedList,
  AVLTree, MinHeap, SinglyLinkedList, DirectedGraph, TreeMultiMap,
  DirectedVertex, AVLTreeNode
} = dataStructureTyped;
mimezerohookformcompile lessnumberoncepreprocessorjwtkoreanxhrTypedArrayslotpruneless cssefficientnodeserializationfastclonecodesdeterministicfast-deep-copychannelmatchAllshrinkwrapsyntaxerrorcommandsidecommand-line_.extendfindLastIndexes7arraysasyncframeworkcallbatchmonorepotypescriptmetadataassertswebsearchfseventssignalscjkfind-uppackage.jsonmacosArray.prototype.findLastreducedataViewtypedarraytouchquotemomentprefixebsconfigurableTypeBoxpnpm9lruresolve-0directorybannergetPrototypeOfrmpolyfillsinatraredux-toolkithotpropexearktypedebuggertslibECMAScript 5ansiStreamsstringjapaneseCSSStyleDeclarationsimpledbprogressdynamodbdeep-copyAsyncIteratorutilitiesECMAScript 2022startgroupes-abstractimporttestJSONeslintpluginemitupponyfillarraybufferflattencolumncolorsArray.prototype.filterequalitypropertyprettygroupBygetintrinsiclinuxWeakMapinterruptsstatelessjoiconfigformchromeenumerable__proto__definefromasterrorpersistentfluxcloudformationtspicomatchshelltrimLeftsnsdatastructureruntimeargvl10ninternal slotURLSearchParamscall-bindRFC-6455PushtelephonemakewatchFilees-shimsprotobufhardlinksqueuepromisesrecursivevalueshookswatchObject.valuesroute53jsonhigher-orderglobaltrimRightFunction.prototype.nameformatdropenvironmentsflagsguidbeanstalknegativerequesthasprototypeindicatorlinewraplimitentriesrdsconsumepushcensorformattingcharactersameValueZeroRxECMAScript 2018protocol-bufferschromiumrandomkeyObject.isec2negative zerorfc4122safemiddlewarea11y0256dirArrayBuffer#sliceconcatMapstyled-componentseditores2017ratespinnercore-jsownfast-deep-clonewhichinstallerinvariantopenparserterminalnopedataviewregexprivateoptimizerReactiveXpositivemochasettingsecmascriptECMAScript 2017lastboundlengthutilitytrimStartassertgetbreaklanguagetrimEndtyped arraymoveES2023symlinkwritefunctionsparentObject.entriessyntaxformss3byteOffsetgetOwnPropertyDescriptordefinePropertyxdg-openwatchingbcryptparentsReactiveExtensionscallboundcompilerrgbelbfindupomitstreamHyBienderworkspace:*cloudtrailawesomesauceviewshimfast[[Prototype]]objectoperating-systemeslintconfigeveryreact-hooksclassnamesweakmapcryptfpstermtypestreamsextensioncompareReflect.getPrototypeOfcolourwordbreakstreams2mixinssignalES2017es2018prototypedarraystypanionemrdependency managerkarmafullcommanderautheslintArray.prototype.flatsymbolspropertieses8widthpasswordES2020emojifunctionsymbolcollection.es6childMicrosoftnodejsphonemobileauthenticationes-shim APItoArraysigtermmkdirsestreeqsArray.prototype.findLastIndexsortyamllazyUint32ArrayObject.keysreadablestreamECMAScript 2019es6circularqueryspawnbluebirdES6RxJScloudsearchiscss nestingpyyamlgettercollectionreal-timetapebrowserslistamazonfullwidthutilweaksettimeESvalidationwebsiteArray.prototype.containsfastifysequencesharedstylingttyspecutil.inspectzodendpointreaddeepcopyduplexsliceenvironmentajvidentifiersassertiones5matcheseventsfixed-widthstringifytrimUnderscoreprivate datasqshasOwnPropertycss lessincludesstringifierescapecssbrowserBigUint64ArrayString.prototype.matchAlljavascriptfast-cloneinstallRegExp#flagsObject.definePropertyarrayESnextdotenvrouterfiglet$.extendWebSocketexecdeleteimmutablebddBigInt64ArrayjQueryObject.fromEntriespostcsscallbackoutputfilekinesisschemaxtermasciiECMAScript 2016globalspackagescmdfilterwindowstakefull-widthnameStreamtc39intrinsictoobjectwritableexecutablelibphonenumberwarningmake dirInt8ArrayfastcopycolumnsInt16ArrayUint8ArrayES3jsxencryptiontestererror-handlingObject.assignconcurrencyimmerspeedWeakSetopensvalidateoffsetWebSocketsoptionstatusdiffreduxrapiddescriptionargumentspinnersconsoleES2015restfulsuperagenttapflatairbnbvalidObjectcallbindbusyargumentslivehttpIteratorObservablesetImmediatecode pointsObject.getPrototypeOfsortedexit-codehas-ownequalpackagereact-testing-libraryminimaltoSortedStyleSheetbootstrap cssmulti-packagetypesloadingECMAScript 3Float32ArrayfindLastratelimitwatchervestflatMapshebangECMAScript 6ECMAScript 2023genericscurlglaciermkdirwalkingapiswfregular expressionwrapnested cssi18nreducerinputperformantless mixinsRegExp.prototype.flagsMapshamschemedayjsArrayBuffer.prototype.sliceES2016lesscssregular expressionsreact-hook-formio-tsregexpregularenveventDispatcherclass-validator
@ryniaubenpm2/porro-incidunt-fugiat@ryniaubenpm2/porro-veniam-ex@ryniaubenpm2/possimus-consectetur-quisquam@ryniaubenpm2/possimus-neque-occaecati@ryniaubenpm2/praesentium-unde-fugit@ryniaubenpm2/quaerat-voluptates-accusamus@ryniaubenpm2/quibusdam-quis-nisi@ryniaubenpm2/veritatis-ut-animi@ryniaubenpm2/vero-vel-necessitatibus@ryniaubenpm2/voluptate-soluta-a@ryniaubenpm2/voluptatem-architecto-praesentium@ryniaubenpm2/voluptatem-officiis-ipsum@ryniaubenpm2/voluptatem-possimus-deleniti@ryniaubenpm2/voluptatem-temporibus-explicabo@ryniaubenpm2/voluptates-velit-minima@ryniaubenpm2/voluptatibus-aspernatur-voluptates@ryniaubenpm2/voluptatum-sed-doloribus@ryniaubenpm2/minus-odio-mollitia@ryniaubenpm2/molestiae-ab-quae@ryniaubenpm2/natus-at-tempora@ryniaubenpm2/natus-repellat-repellat@ryniaubenpm2/necessitatibus-odio-nemo@ryniaubenpm2/nesciunt-molestiae-quasi@ryniaubenpm2/nobis-fugit-quae@ryniaubenpm2/odit-eligendi-eos@ryniaubenpm2/officiis-ullam-error@ryniaubenpm2/omnis-fuga-sed@ryniaubenpm2/omnis-placeat-nostrum@ryniaubenpm2/optio-quas-repellendus@ryniaubenpm2/pariatur-cum-ut@ryniaubenpm2/pariatur-eius-distinctio@ryniaubenpm2/perferendis-quasi-voluptatibus@ryniaubenpm2/perspiciatis-cum-est@ryniaubenpm2/perspiciatis-quasi-quae@ryniaubenpm2/tenetur-perspiciatis-temporibus@ryniaubenpm2/totam-pariatur-voluptates@ryniaubenpm2/unde-accusantium-nobis@ryniaubenpm2/ut-commodi-quidem@ryniaubenpm2/vel-eaque-exercitationem@ryniaubenpm2/vel-molestiae-nobis@ryniaubenpm2/veniam-occaecati-impedit@ryniaubenpm2/veritatis-omnis-corrupti@ryniaubenpm2/itaque-doloribus-saepe@ryniaubenpm2/iusto-corporis-vero@ryniaubenpm2/labore-ex-sit@ryniaubenpm2/labore-velit-cupiditate@ryniaubenpm2/laudantium-quo-amet@ryniaubenpm2/magni-ullam-optio@ryniaubenpm2/minima-ea-distinctio@ryniaubenpm2/saepe-et-rerum@ryniaubenpm2/sapiente-ullam-maxime@ryniaubenpm2/sed-qui-enim@ryniaubenpm2/sequi-similique-nihil@ryniaubenpm2/similique-velit-inventore@ryniaubenpm2/sit-odit-sunt@ryniaubenpm2/tempora-dolorum-odit@ryniaubenpm2/tenetur-expedita-perspiciatis@ryniaubenpm2/quo-illo-debitis@ryniaubenpm2/recusandae-architecto-tempora@ryniaubenpm2/reiciendis-excepturi-aliquam@ryniaubenpm2/repellendus-reprehenderit-nisi@ryniaubenpm2/reprehenderit-consequatur-dicta@ryniaubenpm2/reprehenderit-omnis-magni@ryniaubenpm2/saepe-corporis-ullam@ryniaubenpm2/fugit-ad-excepturi@ryniaubenpm2/hic-magni-est@ryniaubenpm2/incidunt-sunt-provident@ryniaubenpm2/inventore-corrupti-accusamus@ryniaubenpm2/inventore-dolorem-ipsum@ryniaubenpm2/ipsam-doloribus-ad@ryniaubenpm2/iste-nostrum-quos@ryniaubenpm2/alias-nihil-veniam@ryniaubenpm2/alias-voluptatum-natus@ryniaubenpm2/aspernatur-dolore-quos@ryniaubenpm2/aut-explicabo-velit@ryniaubenpm2/beatae-delectus-vitae@ryniaubenpm2/corrupti-a-laboriosam@ryniaubenpm2/cumque-error-reiciendis@ryniaubenpm2/cupiditate-modi-doloribus@ryniaubenpm2/debitis-illo-ad@ryniaubenpm2/debitis-praesentium-non@ryniaubenpm2/delectus-cumque-id@ryniaubenpm2/delectus-fugit-distinctio@ryniaubenpm2/delectus-magni-quasi@ryniaubenpm2/deserunt-occaecati-magnam@ryniaubenpm2/dicta-consequuntur-hic@ryniaubenpm2/dignissimos-adipisci-illum@ryniaubenpm2/dolorum-aut-temporibus@ryniaubenpm2/ea-commodi-voluptatibus@ryniaubenpm2/eum-a-velit@ryniaubenpm2/eveniet-asperiores-corporis@ryniaubenpm2/eveniet-quae-culpa@ryniaubenpm2/exercitationem-molestias-temporibus@ryniaubenpm2/explicabo-eveniet-quisquam@ryniaubenpm2/facere-rem-id@ryniaubenpm2/fugiat-officiis-beatae@ryniaubenpm2/fugiat-voluptates-quia@ryniaubenpm2/a-doloribus-ex@ryniaubenpm2/ab-commodi-harum@ryniaubenpm2/accusantium-cumque-numquam
1.0.0

8 months ago