<commit_before># can-binarytree

**can-binarytree** extends the very well written Javascript binary tree
implementations provided by [@vadimg](https://github.com/vadimg/js_bintrees)
and and mixes in features of CanJS that make the data structures observable.

Note: Currently, the only data structure in the package that is observable is
the `can.RBTreeList`, which was adapted from the `can.RBTree` data structure
for use in CanJS' [can-derive plugin](https://github.com/canjs/can-derive).

> - [Install](#install)
> - [Use](#use)
> - [Data Structures](#data-structures)
> - [API](#api)
>   - [`can.RBTreeList`](#canrbtreelist)
>     - [`.attr()`](#attr)
>     - [`.batchSet()`](#batchset)
>     - [`.deleteAttr()`](#deleteattr)
>     - [`.each()`](#each)
>     - [`.eachNode()`](#eachnode)
>     - [`.filter()`](#filter)
>     - [`.indexOf()`](#indexof)
>     - [`.indexOfNode()`](#indexofnode)
>     - [`.map()`](#map)
>     - [`.push()`](#push)
>     - [`.removeAttr()`](#removeattr)
>     - [`.replace()`](#replace)
>     - [`.splice()`](#splice)
>     - [`.unshift()`](#unshift)
>   - [`can.RBTreeList.Node`](#canrbtreelistnode)
>   - [`can.RBTree`](#canrbtree)
>   - [`can.BinTree`](#canbintree)
> - [Contributing](#contributing)




## Install

Use npm to install `can-binarytree`:

```
npm install can-binarytree --save
```


## Use

Use `require` in Node/Browserify workflows to import `can-binarytree` like:

```js
var binaryTree = require('can-binarytree');
```

Use `define`, `require` or `import` in [StealJS](http://stealjs.com)
workflows to import `can-binarytree` like:

```js
import binaryTree from 'can-binarytree'
```

Once you've imported `can-binarytree` into your project, use it to
create observable binary tree data structures. The following example
formats and `console.log`'s the current list of values as they are
added to a Red-Black Tree List:

```js
var tree = new can.RBTreeList();

tree.bind('add', function () {
    tree.print(function (node) {
        return '<' + node.data + '>';
    });
})

tree.push('Hop');
// <Hop>

tree.push('Skip');
// <Hop>------
// -----<Skip>

tree.push('Jump');
// -----<Skip>------
// <Hop>------<Jump>

```


## Data Structures

- RBTreeList - A red-black tree implementation that meets the specifications of
  a can.List
- RBTree - A self-balancing binary tree that serves as a key-value store
- BinTree - A binary tree that is not balanced


## API


### can.RBTreeList

<commit_msg>Doc revisions<commit_after># can-binarytree

**can-binarytree** extends the very well written Javascript binary tree
implementations provided by [@vadimg](https://github.com/vadimg/js_bintrees)
and and mixes in features of CanJS that make the data structures observable.

> - [Install](#install)
> - [Use](#use)
> - [Data Structures](#data-structures)
> - [API](#api)
>   - [`can.RBTreeList`](#canrbtreelist)
>     - [`.attr()`](#attr)
>     - [`.batchSet()`](#batchset)
>     - [`.deleteAttr()`](#deleteattr)
>     - [`.each()`](#each)
>     - [`.eachNode()`](#eachnode)
>     - [`.filter()`](#filter)
>     - [`.indexOf()`](#indexof)
>     - [`.indexOfNode()`](#indexofnode)
>     - [`.map()`](#map)
>     - [`.push()`](#push)
>     - [`.removeAttr()`](#removeattr)
>     - [`.replace()`](#replace)
>     - [`.splice()`](#splice)
>     - [`.unshift()`](#unshift)
>   - [`can.RBTreeList.Node`](#canrbtreelistnode)
>   - [`can.RBTree`](#canrbtree)
>   - [`can.BinTree`](#canbintree)
> - [Contributing](#contributing)




## Install

Use npm to install `can-binarytree`:

```
npm install can-binarytree --save
```


## Use

Use `require` in Node/Browserify workflows to import `can-binarytree` like:

```js
var can = require('can');
require('can-binarytree');
```

Use `define`, `require` or `import` in [StealJS](http://stealjs.com)
workflows to import `can-binarytree` like:

```js
import can from 'can';
import 'can-binarytree';
```

Once you've imported `can-binarytree` into your project, use it to
create observable binary tree data structures. The following example
`console.log`'s some metadata about each node that's added to a
`can.RBTreeList`:

```js
var tree = new can.RBTreeList();

tree.bind('add', function (ev, nodes) {
    console.log(node[0]);
})

tree.push('Hop'); // Node {id: 0, parent: null, data: "Hop", left: null, right: null...}
tree.push('Skip'); // Node {id: 2, parent: Node, data: "Skip", left: null, right: null...}
tree.push('Jump'); // Node {id: 4, parent: Node, data: "Jump", left: null, right: null...}
```


## Data Structures

- RBTreeList - A red-black tree implementation that meets the specifications of
  a can.List
- RBTree - A self-balancing binary tree that serves as a key-value store
- BinTree - A binary tree that is not balanced

Note: Currently, the only data structure in the package that is observable is
the `can.RBTreeList`.


## API


### can.RBTreeList

A red-black tree that uses a numeric "index" as the "key" in the same way
a `can.List` or native Javascript array might, yet still performs insert and
remove operations in `O(log n)` time.

{'fraction_non_alphanumeric': 0.19536358232613435, 'fraction_numerical': 0.0007925500297206261, 'mean_word_length': 3.7532956685499057, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 56, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6140780', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1689, 'n_words': 468}