├── .gitignore
├── LICENSE
├── README.md
├── examples
├── .DS_Store
├── simple.html
└── vendor
│ └── graphing.js
├── index.js
├── package.json
├── prufer.js
└── test
└── index.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 |
5 | # Runtime data
6 | pids
7 | *.pid
8 | *.seed
9 |
10 | # Directory for instrumented libs generated by jscoverage/JSCover
11 | lib-cov
12 |
13 | # Coverage directory used by tools like istanbul
14 | coverage
15 |
16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17 | .grunt
18 |
19 | # Compiled binary addons (http://nodejs.org/api/addons.html)
20 | build/Release
21 |
22 | # Dependency directory
23 | # Commenting this out is preferred by some people, see
24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
25 | node_modules
26 |
27 | # Users Environment Variables
28 | .lock-wscript
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Johnathan
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | prüfer
2 | ======
3 |
4 | 
5 |
6 | Implements the Prüfer sequence algorithm in pure javascript, for space-efficient representation of trees using a unique sequence. Useful for generating random trees of data.
7 |
8 | Here are some examples:
9 | [3. 3. 3. 4](http://jleppert.github.io/prufer/examples/simple.html)
10 | [4, 4, 4, 5](http://jleppert.github.io/prufer/examples/simple.html?a=4,4,4,5)
11 |
12 | ```js
13 | var prufer = require('prufer');
14 |
15 | // to make a tree, supply a series of integers
16 | var tree = prufer([3, 3, 3, 4]);
17 |
18 | // you'll get back an array of edges
19 | console.log(tree);
20 | // --> [[3, 0], [3, 1], [3, 2], [4, 3], [4, 5]]
21 | ```
22 |
23 | Installing
24 | -------------
25 | Using with node:
26 |
27 | npm install prufer
28 |
29 | For the browser, use `prufer.js`:
30 |
31 | ```html
32 |
33 |
37 | ```
38 |
39 | Running Tests
40 | -------------
41 |
42 | Make sure you have Mocha installed:
43 |
44 | npm install -g mocha
45 | npm test
46 |
47 | Reporting Bugs & Feature Requests
48 | -------------
49 | Please use github to report all bugs and feature requests at .
50 |
51 |
52 | Further Reading
53 | -------------
54 | [Prüfer sequence Wikipedia](http://en.wikipedia.org/wiki/Pr%C3%BCfer_sequence)
55 |
56 | [Python Version & Good Overview](http://hamberg.no/erlend/posts/2010-11-06-prufer-sequence-compact-tree-representation.html)
57 |
58 | License
59 | -------------
60 | Copyright (c) 2014 Johnathan Leppert
61 |
62 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
63 |
64 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
65 |
66 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
67 |
--------------------------------------------------------------------------------
/examples/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jleppert/prufer/46379242400c5245cd805723178ff13b74043ceb/examples/.DS_Store
--------------------------------------------------------------------------------
/examples/simple.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Prüfer Sequence Tree Example
6 |
7 |
8 |
9 |
13 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/examples/vendor/graphing.js:
--------------------------------------------------------------------------------
1 | Raphael=function(){var a=/[, ]+/,aO=/^(circle|rect|path|ellipse|text|image)$/,L=document,au=window,l={was:"Raphael"in au,is:au.Raphael},an=function(){if(an.is(arguments[0],"array")){var d=arguments[0],e=w[aW](an,d.splice(0,3+an.is(d[0],al))),S=e.set();for(var R=0,a0=d[m];R