Noticeably Playful Monkeys
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

succinct-binary-tree-encoding

1.0.0 • Public • Published

succinct-binary-tree-encoding

succinctly represent the structure of a binary tree

example

encode a binary tree to a bit field:

var succinct = require('succinct-binary-tree-encoding')
 
var tree = JSON.parse(process.argv.slice(2).join(' '))
var bits = succinct.encode(tree)
console.log(bits.join(''))
$ node encode.js '{"left":null,"right":{"left":{"left":null,"right":{"left":null,"right":null}}}}'
101101

decode a bit field to a binary tree:

var succinct = require('succinct-binary-tree-encoding')
 
var tree = JSON.parse(process.argv.slice(2).join(' '))
var bits = succinct.encode(tree)
console.log(bits.join(''))
$ node decode.js 101101
{"left":null,"right":{"left":{"left":null,"right":{"left":null,"right":null}},"right":null}}

api

var succinct = require('succinct-binary-tree-encoding')

var bits = succinct.encode(tree)

Generate an array of bits from a nested object tree with left and right properties.

var tree = succinct.decode(bits)

Generate a nested tree object with left and right properties from an array of bits.

install

npm install succinct-binary-tree-encoding

license

MIT

install

npm i succinct-binary-tree-encoding

Downloadsweekly downloads

3

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability