44implementations provided by [ @vadimg ] ( https://github.com/vadimg/js_bintrees )
55and and mixes in features of CanJS that make the data structures observable.
66
7- Note: Currently, the only data structure in the package that is observable is
8- the ` can.RBTreeList ` , which was adapted from the ` can.RBTree ` data structure
9- for use in CanJS' [ can-derive plugin] ( https://github.com/canjs/can-derive ) .
10-
117> - [ Install] ( #install )
128> - [ Use] ( #use )
139> - [ Data Structures] ( #data-structures )
@@ -49,41 +45,33 @@ npm install can-binarytree --save
4945Use ` require ` in Node/Browserify workflows to import ` can-binarytree ` like:
5046
5147``` js
52- var binaryTree = require (' can-binarytree' );
48+ var can = require (' can' );
49+ require (' can-binarytree' );
5350```
5451
5552Use ` define ` , ` require ` or ` import ` in [ StealJS] ( http://stealjs.com )
5653workflows to import ` can-binarytree ` like:
5754
5855``` js
59- import binaryTree from ' can-binarytree'
56+ import can from ' can' ;
57+ import ' can-binarytree' ;
6058```
6159
6260Once you've imported ` can-binarytree ` into your project, use it to
6361create observable binary tree data structures. The following example
64- formats and ` console.log ` 's the current list of values as they are
65- added to a Red-Black Tree List :
62+ ` console.log ` 's some metadata about each node that's added to a
63+ ` can.RBTreeList ` :
6664
6765``` js
6866var tree = new can.RBTreeList ();
6967
70- tree .bind (' add' , function () {
71- tree .print (function (node ) {
72- return ' <' + node .data + ' >' ;
73- });
68+ tree .bind (' add' , function (ev , nodes ) {
69+ console .log (node[0 ]);
7470})
7571
76- tree .push (' Hop' );
77- // <Hop>
78-
79- tree .push (' Skip' );
80- // <Hop>------
81- // -----<Skip>
82-
83- tree .push (' Jump' );
84- // -----<Skip>------
85- // <Hop>------<Jump>
86-
72+ tree .push (' Hop' ); // Node {id: 0, parent: null, data: "Hop", left: null, right: null...}
73+ tree .push (' Skip' ); // Node {id: 2, parent: Node, data: "Skip", left: null, right: null...}
74+ tree .push (' Jump' ); // Node {id: 4, parent: Node, data: "Jump", left: null, right: null...}
8775```
8876
8977
@@ -94,12 +82,18 @@ tree.push('Jump');
9482- RBTree - A self-balancing binary tree that serves as a key-value store
9583- BinTree - A binary tree that is not balanced
9684
85+ Note: Currently, the only data structure in the package that is observable is
86+ the ` can.RBTreeList ` .
87+
9788
9889## API
9990
10091
10192### can.RBTreeList
10293
94+ A red-black tree that uses a numeric "index" as the "key" in the same way
95+ a ` can.List ` or native Javascript array might, yet still performs insert and
96+ remove operations in ` O(log n) ` time.
10397
10498#### .attr()
10599
0 commit comments