6.13.149 • Published 9 months ago

@firanorg/a-neque-sunt v6.13.149

Weekly downloads
-
License
MIT
Repository
github
Last release
9 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;
toArrayroutesameValueZerovaluescore-jsdescriptorstatelessutilitieswalkequalityterminalclassnamesefficientextensionbcryptajvArrayBuffer.prototype.sliceio-tsUint32ArrayeslintpluginhardlinkschannelimmertrimStartreduxlogcss nestingregularmakebreakprunejasmineimportes5es2016positiveassertionJSON-SchemaYAMLperformanceduplexprotocol-buffersdefinePropertyrapidphoneloadingmodulemkdirless cssmergenodeES2017omitgroupByproxylibphonenumber[[Prototype]]MapES2018columnprotobufECMAScript 3onceObjectgdprtypeuninstallgradients cssstarteroptimizerjsonrequireECMAScript 2016tapeflagfindstreamECMAScript 2020flatawsclass-validatorarraybuffertimeweakmapsigtermresolveInt16Arraycorearrayutil.inspectfstslibArray.prototype.flattenfseventsuuidRxJSES8optimistcryptguidchromesettingsiterateformsqueueES2015outputextraworkerpolyfillInt32Array256trimLefthasES2021metadatadescriptorsemojiclassesmkdirpcssfpsfull-widthreal-timeRegExp#flagscommandES5__proto__flatMapmoveaccessibilityrouterdropsetImmediateapiinvariantelbquotedataObject.assignprefixECMAScript 2018apptostringtagawaitroute53formattingjestgetOwnPropertyDescriptorES2020amazonponyfillargsmatchAllboundtextes8valuedeterministicbusyES2022bluebirdoperating-systemmatchesl10nmochacodesassertsgradients css3promiseRFC-6455fullstylingfastcopywatchbootstrap lessES3rm -rfes-abstractrgbcensorexit@@toStringTagfetchlengthcjkjoidependency managerwaitnopecollectiones7rangeerrorwatchFilemake direnderpromisesasciihashvpcenumerableArray.prototype.findLastIndexreact-hook-formjsdompropbrowserslistwarninga11ysortedpathidtypedarraysformfast-clonethrottlewindowscontainsopenarrayscreatehasOwni18nawesomesaucecomputed-typescachexhrBigInt64ArrayES2023isConcatSpreadablewhatwgaccessorminimalvestjsxmatchdeepes6arktypeperformantES2019reducersearchpropertydom-testing-libraryObject.istypedarrayutiltrimtoobjectavacallbindfindLastIndexsideprivate dataprogressnamestelephonefunctionsunicodedefineESnextdataviewchaiReactiveXArray.prototype.flatMaprestfulreactrfc4122typed arraySymbol.toStringTagsuperagentworkflowreact-hooksbinderror-handlingdomObject.entries.envcall-bindflattenArray.prototype.flatWebSocketswritablesyntaxerrorshellES6objjssetsimpledbrestreact-testing-libraryhttpinstallerpredictableviewflagsformatdynamodbCSSStyleDeclarationpicomatchPushttyBigUint64Arrayless compilerUint8ArrayoffsetjapanesewhichspecfastcloneasynccloudtrailcolumnsTypedArrayiteratoragentquerystringTypeScriptzodcode pointsreusesomepackagerandomECMAScript 2022jsdiffAsyncIteratoreventDispatchertapbuffersimportexportIteratorWeakMapsafeFloat32ArrayUnderscorehigher-orderinputcallbackquerypostcssmiddlewaretouchfast-copyauthenticationeslint-pluginloggingparentsdeepclonecallecmascriptpyyamlstoragegatewayStreamvalidationdebugec2webwraplooksetPrototypeOfcall-boundstylesrecursivevisualremovermdirlimitsharedsnskarmaeventEmitterfilterArray.prototype.containsutilitycloudsearchprototypeinferenceescapewordwrapparserendpointhotsymlinkreadablepreserve-symlinksequalconsoletypedtddES7es2015HyBicharacterauthkeyenvscheme-validationworkspace:*slotStreamsexecestreespinnerpasswordshebangfind-uplazyfixed-widthcryptomodulesvariables in csserrorchineseincludesintrinsicArrayBuffer#slicefromECMAScript 6httpsArray.prototype.includesArrayBufferReflect.getPrototypeOfsymboltypesconcatMapObject.keysregular expressionsdebuggerWebSocketargvnumberInt8ArraycorsownmixinsxtermURLSearchParamsTypeBoxgetintrinsicfast-deep-cloneirqstringifysymbolsupbootstrap cssshamstdlibdataViewansiassertframeworkconfigurableshimmacoscommanderyamlArray.prototype.findLastbatchswftypeerrorclassnamepushdirectorystringlook-upinternalcoerciblebundlingencryptionjwtwalkingexit-codeconsumeemrjavascriptreducemomentdescriptionString.prototype.trimkinesisgetterstringifiercss-in-jscss lesscloudwatchcompilersettersqsform-validationasttc39rmStyleSheetstylesheetelasticachenegative zeroUint8ClampedArrayECMAScript 5browserpostcss-pluginpersistentrdsconcurrencytypanioninterruptsMicrosoftes-shimsArraytrimRightkeyslessajaxtypeofstructuredCloneString.prototype.matchAllserializernested csswidthObject.definePropertyruntimetypescriptpackage.jsonObject.fromEntriesnativefilerobustES2016koreanvariablesobjectUint16Arraycompile lessenvironmentebsbannercss variablecloudformationentrieses2017east-asian-widthpnpm9plugindatastructureECMAScript 7bdddeletegetdiffeventsfastifyFunction.prototype.namecurlcheckrequesteslintconfigparentECMAScript 2021sharedarraybufferObject.getPrototypeOffile systeminternal slotless.jsCSSinmapdeep-cloneRxESdayjsbyteLengthmkdirspackagesWeakSetwriteelmfoldertakeloadbalancingstableisECMAScript 2019linewraptoStringTagpackage managerieautoscalingfullwidtheveryfluxredactesairbnbchromiumnamewafrm -frconnectstyleguideartpipebytecolorReactiveExtensionslimitedpreprocessorspeedemitglacierzeromobilehooksbundlerexpressfindLastsignalslesscssconcatFloat64Arraywgetclonestateregexmimetypes_.extendsequencevalidatetermgroupspinnersjsonpathdirmonorepoargparsesesmimelanguagequeueMicrotasktestinghelpersassignserializedotenvsigintshrinkwrapargumentstreamstsstreams2dependenciesfastECMAScript 2023byteOffsetimmutabledeepcopycommand-lineprettyes2018optionconfigmulti-packagefigletregexpcolorslinklockfilelistenerssyntaxmime-db-0testergetPrototypeOfhookformurllastsymlinksfunctionaltoolkitstatuseslintbufferSymbolschemahas-ownnegativesliceindicatorless mixinslintidletoolsprivateiterationtestObject.valuesextendjQuerypatchinspectdateratelimitstyleECMAScript 2015taskArray.prototype.filterlrumrubeanstalkweaksetvalidmapreduceSet0installECMAScript 2017copyreadablestreamsuperstructcollection.es6serializationthroatcircularsignal
6.13.149

9 months ago

6.13.148

9 months ago

6.13.147

9 months ago

6.13.129

10 months ago

6.13.130

10 months ago

6.13.131

10 months ago

6.13.132

10 months ago

6.13.133

10 months ago

6.13.134

10 months ago

6.13.135

10 months ago

6.13.136

10 months ago

6.13.137

10 months ago

6.13.138

10 months ago

6.13.139

9 months ago

6.13.140

9 months ago

6.13.141

9 months ago

6.13.142

9 months ago

6.13.143

9 months ago

6.13.144

9 months ago

6.13.145

9 months ago

6.13.146

9 months ago

6.13.127

10 months ago

6.13.128

10 months ago

6.12.126

10 months ago

6.12.127

10 months ago

6.12.125

10 months ago

6.12.124

10 months ago

6.12.122

10 months ago

6.12.123

10 months ago

6.12.121

10 months ago

6.10.120

10 months ago

6.11.120

10 months ago

6.11.121

10 months ago

6.10.119

10 months ago

6.10.118

10 months ago

6.10.117

10 months ago

6.10.116

10 months ago

6.10.115

10 months ago

6.10.114

10 months ago

5.10.114

10 months ago

5.10.113

10 months ago

5.10.112

11 months ago

5.9.112

11 months ago

5.8.112

11 months ago

5.8.111

11 months ago

5.8.110

11 months ago

5.8.109

11 months ago

5.8.108

11 months ago

5.8.107

11 months ago

5.8.106

11 months ago

5.8.105

11 months ago

3.6.69

12 months ago

3.6.68

1 year ago

3.6.67

1 year ago

3.6.66

1 year ago

3.6.65

1 year ago

3.6.64

1 year ago

3.6.63

1 year ago

4.7.90

11 months ago

3.6.62

1 year ago

3.6.61

1 year ago

3.6.60

1 year ago

3.6.79

12 months ago

3.6.78

12 months ago

3.6.77

12 months ago

3.6.76

12 months ago

3.6.75

12 months ago

3.6.74

12 months ago

4.7.86

12 months ago

4.7.89

11 months ago

4.7.87

11 months ago

4.7.88

11 months ago

3.6.73

12 months ago

3.6.72

12 months ago

3.6.71

12 months ago

3.6.70

12 months ago

5.8.98

11 months ago

5.8.99

11 months ago

3.4.29

1 year ago

3.6.59

1 year ago

3.4.36

1 year ago

3.6.58

1 year ago

3.4.37

1 year ago

3.6.57

1 year ago

3.4.38

1 year ago

3.6.56

1 year ago

3.6.55

1 year ago

3.2.17

1 year ago

3.6.54

1 year ago

3.2.16

1 year ago

3.2.18

1 year ago

3.4.30

1 year ago

3.4.31

1 year ago

3.4.32

1 year ago

3.4.33

1 year ago

3.4.34

1 year ago

3.4.35

1 year ago

3.5.54

1 year ago

3.5.53

1 year ago

3.5.52

1 year ago

3.5.51

1 year ago

3.5.50

1 year ago

4.8.90

11 months ago

3.7.86

12 months ago

4.8.92

11 months ago

4.8.91

11 months ago

4.8.94

11 months ago

4.8.93

11 months ago

4.8.96

11 months ago

4.8.95

11 months ago

4.8.98

11 months ago

4.8.97

11 months ago

3.7.84

12 months ago

3.7.85

12 months ago

3.3.18

1 year ago

3.3.19

1 year ago

3.5.39

1 year ago

3.5.38

1 year ago

3.6.84

12 months ago

3.6.83

12 months ago

3.6.82

12 months ago

3.6.81

12 months ago

3.6.80

12 months ago

3.5.47

1 year ago

3.3.24

1 year ago

3.5.46

1 year ago

3.3.25

1 year ago

3.5.45

1 year ago

3.3.26

1 year ago

3.5.44

1 year ago

3.3.27

1 year ago

3.5.43

1 year ago

3.3.28

1 year ago

3.5.42

1 year ago

3.3.29

1 year ago

3.5.41

1 year ago

3.5.40

1 year ago

5.8.102

11 months ago

5.8.103

11 months ago

5.8.104

11 months ago

3.3.20

1 year ago

3.3.21

1 year ago

5.8.100

11 months ago

3.5.49

1 year ago

3.3.22

1 year ago

5.8.101

11 months ago

3.5.48

1 year ago

3.3.23

1 year ago

3.2.15

1 year ago

3.2.13

1 year ago

3.2.12

1 year ago

3.2.14

1 year ago

3.2.11

1 year ago

3.1.11

1 year ago

3.1.10

1 year ago

3.1.9

1 year ago

3.1.8

1 year ago

2.1.8

1 year ago

2.1.7

1 year ago

2.1.6

1 year ago

2.1.5

1 year ago

2.1.4

1 year ago

2.1.2

1 year ago

2.1.3

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago