Demo
Ture -Ture is a collection of algorithms and data structures written in TypeScript for fun and profit.
WTF does Ture mean? Essentially, it's a famous sicilian personal name, but it's contained in the word strucTUREs and remembers Alan Turing as well, so why not.
Beware that some algorithms and data structure aren't really optimized for production use, so please take this into account before depending on this package. At the moment I'm using it on personal small projects, especially small video game demos.
For instance the KdTree (a 2d tree implementation actually) and its operation are ready for production use and guaranteed to run on logarithmic time in the typical case, while some other algorithms on graphs are in the works and may need some testing.
Features
- KdTree (2d tree implementation) with logarithmic running time (typical case)
- KdTree with
range
andnearest
operations - Test cases and examples (found in the
/examples
folder) to get started
Install
Simply npm install ture --save
.
Then use it like in the following example:
; // contains ;tree.insertnew Point2D07, 02;tree.insertnew Point2D05, 04;tree.insertnew Point2D02, 03;tree.insertnew Point2D04, 07;tree.insertnew Point2D09, 06; tree.containsnew Point2D04, 07; // truetree.containsnew Point2D03, 07; // false // range ;tree.insertnew Point2D01, 04;tree.insertnew Point2D06, 05;;console.logpoints.length; // 1console.logpoints; // (0.6, 0.5) // nearest ;tree.insertnew Point2D0206107, 0095492; // Atree.insertnew Point2D0975528, 0654508; // Btree.insertnew Point2D0024472, 0345492; // Ctree.insertnew Point2D0793893, 0095492; // Dtree.insertnew Point2D0793893, 0904508; // Etree.insertnew Point2D0975528, 0345492; // Ftree.insertnew Point2D0206107, 0904508; // Gtree.insertnew Point2D0500000, 0000000; // Htree.insertnew Point2D0024472, 0654508; // Itree.insertnew Point2D0500000, 1000000; // L;console.lognearestPoint; // (0.975528, 0.345492)
or
;;graph.addEdge'1337', '1338';
Credits
Some of the data structures are ported from Java from the wonderful book "Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne".
License
This project is licensed under the terms of the MIT license.