<commit_before># _tree

> "Computing's core challenge is how not to make a mess of it."
> --*<NAME>, [EWD1243][]*

This library provides a tree model (data structure) implementation and
a pluggable tree behavior for your data. It maintains *zero* internal
state, provides only immutable objects, and does not alter your data
or trample on the global scope.

`_tree` supports AMD (RequireJs), Node, and global-script loading
scenarios.

## Simple Usage Example

To get a feel for the library, also check out the
[tests](https://github.com/drfloob/_tree/tree/master/test) and read
the
[annotated source](https://rawgithub.com/drfloob/_tree/master/docs/_tree.html)
documentation.


```javascript
'use strict';
var Patronage, FamilyTree;

Patronage = {'name': 'Jake', 'kids': [{'name': 'Jake Jr.'}, {'name': 'T.V.'}, {'name': 'Charlie'}, {'name': 'Viola'}]};
FamilyTree = _tree.inflate(Patronage);

// FamilyTree is immutable. You need to capture the return value to
// see your changes. If nothing holds a reference to the old tree, it
// will be garbage collected.
FamilyTree = FamilyTree.addChild(FamilyTree.root(), {'name': '<NAME>'});

// Log the tree, with everyone's name and their father's name
FamilyTree.walk(function(node) {
    var origin = 'origin unknown';
    if (_.has(node), 'parent'))
        origin = 'is the child of ' + node.parent.data.name;
    console.log(node.data.name, origin);
});

// Delete a child node
FamilyTree = FamilyTree.findNodeByData({name: 'Charlie'}).delete();

FamilyTree.findNodeByData({name: 'Charlie'}) === false; // true

```

## Quality Metrics

**Tests**: All tests pass on

 * google chrome 30
 * firefox 25
 
[PhantomJS](https://github.com/ariya/phantomjs) does not support
`Object.freeze`, so only the tests for immutability fail there.

You can [run tests in the browser](https://rawgithub.com/drfloob/_tree/master/test/test.html) (via rawgithub.com),
or at the command line with 

```bash
grunt test # via phantomJS
```

**Performance**: On an Intel Core 2 CPU T5600 @ 1.83GHz, 3GB ram, running Debian Wheezy:

 * 1024 node trees can be inflated at ~15/sec
 * 30 node trees can be inflated at ~600/sec
 * 11 node trees can be inflated at ~1,500/sec
 * empty trees can be created at ~12,000/sec

Run benchmarks with:

```bash
grunt benchmark:all
```

**Coverage**: Test coverage is at 98% functions, 94% statements, 94% lines, and 87% branches.

Coverage is calculated every time you run `grunt test` from the
command line. You can view the coverage report locally at
`coverage/index.html`. Here is the
[latest report](https://rawgithub.com/drfloob/_tree/master/coverage/index.html).

## API

The `_tree` library exposes the following functions:

 * `create`: creates an empty `Tree`
 * `inflate`: parses your data into a `Tree`
 * `fromNode`: creates a new tree from the given `Node`

All of the `_tree` methods return a `Tree` object, which has the
following methods: 

 * `root`: returns the root `Node`
 * `findNode`: finds the equivalent `Node` in a tree (works across
   clones)
 * `walk`: traverses the `Tree`, executing a callback for each node in
   the order you specify<commit_msg>add test info for safari 5.0.6<commit_after># _tree

> "Computing's core challenge is how not to make a mess of it."
> --*<NAME>, [EWD1243][]*

This library provides a tree model (data structure) implementation and
a pluggable tree behavior for your data. It maintains *zero* internal
state, provides only immutable objects, and does not alter your data
or trample on the global scope.

`_tree` supports AMD (RequireJs), Node, and global-script loading
scenarios.

## Simple Usage Example

To get a feel for the library, also check out the
[tests](https://github.com/drfloob/_tree/tree/master/test) and read
the
[annotated source](https://rawgithub.com/drfloob/_tree/master/docs/_tree.html)
documentation.


```javascript
'use strict';
var Patronage, FamilyTree;

Patronage = {'name': 'Jake', 'kids': [{'name': '<NAME>.'}, {'name': 'T.V.'}, {'name': 'Charlie'}, {'name': 'Viola'}]};
FamilyTree = _tree.inflate(Patronage);

// FamilyTree is immutable. You need to capture the return value to
// see your changes. If nothing holds a reference to the old tree, it
// will be garbage collected.
FamilyTree = FamilyTree.addChild(FamilyTree.root(), {'name': '<NAME>'});

// Log the tree, with everyone's name and their father's name
FamilyTree.walk(function(node) {
    var origin = 'origin unknown';
    if (_.has(node), 'parent'))
        origin = 'is the child of ' + node.parent.data.name;
    console.log(node.data.name, origin);
});

// Delete a child node
FamilyTree = FamilyTree.findNodeByData({name: 'Charlie'}).delete();

FamilyTree.findNodeByData({name: 'Charlie'}) === false; // true

```

## Quality Metrics

**Tests**: All tests pass on

 * google chrome 30
 * firefox 25
 
In the following browsers, which do not support `Object.freeze`,
*only* the tests for immutability fail:

 * [PhantomJS](https://github.com/ariya/phantomjs)
 * Safari 5.0.6

You can
[**run the tests yourself in your browser**](https://rawgithub.com/drfloob/_tree/master/test/test.html),
or at the command line with `grunt test`

**Performance**: On an Intel Core 2 CPU T5600 @ 1.83GHz, 3GB ram, running Debian Wheezy:

 * 1024 node trees can be inflated at ~15/sec
 * 30 node trees can be inflated at ~600/sec
 * 11 node trees can be inflated at ~1,500/sec
 * empty trees can be created at ~12,000/sec

Run benchmarks with `grunt benchmark:all`

**Coverage**: Test coverage is at 98% functions, 94% statements, 94% lines, and 87% branches.

Coverage is calculated every time you run `grunt test` from the
command line. You can view the coverage report locally at
`coverage/index.html`. Here is the
[**latest report**](https://rawgithub.com/drfloob/_tree/master/coverage/index.html).

## API

The `_tree` library exposes the following functions:

 * `create`: creates an empty `Tree`
 * `inflate`: parses your data into a `Tree`
 * `fromNode`: creates a new tree from the given `Node`

All of the `_tree` methods return a `Tree` object, which has the
following methods: 

 * `root`: returns the root `Node`
 * `findNode`: finds the equivalent `Node` in a tree (works across
   clones)
 * `walk`: traverses the `Tree`, executing a callback for each node in
   the order you specify
{'fraction_non_alphanumeric': 0.1273015873015873, 'fraction_numerical': 0.015873015873015872, 'mean_word_length': 4.326289095519865, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, 'https://': 10, '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': '1101077', 'n_tokens_mistral': 2079, 'n_tokens_neox': 1892, 'n_words': 774}