Small library implementing a radix (or prefix) tree.
npm i --save rad-tree
'use strict'
const Tree = require('rad-tree')
const tree = new Tree()
...
tree.set('icecream', 'cone')
tree.set('foo', 'bar')
tree.set('iced', 'coffee')
tree.set('foobar', 'baz')
tree.set('ice') // value defaults to `ice`
tree.set('fo', 'mo')
...
tree.get('foobar')
// 'baz'
tree.get('icedcoffee')
// undefined
...
tree.delete('foobar')
// true
tree.delete('icedcoffee')
// false
...
tree.toObject()
// {
// edges: [
// {
// key: 'fo',
// node: {
// value: 'mo',
// edges: [
// {
// key: 'o',
// node: {
// value: 'bar',
// edges: [
// {
// key: 'bar',
// node: { value: 'baz' }
// }
// ]
// }
// }
// ]
// }
// },
// {
// key: 'ice',
// node: {
// edges: [
// {
// key: 'cream',
// node: { value: 'cone' }
// },
// {
// key: 'd',
// node: { value: 'coffee' }
// }
// ],
// value: 'ice'
// }
// }
// ]
// }
...
tree.toString()
// `fo: mo
// o: bar
// bar: baz
// ice: ice
// cream: cone
// d: coffee`
npm test
npm run lint
npm run doc
Please do!
If you find a bug, want a feature added, or just have a question, feel free to open an issue. In addition, you're welcome to create a pull request addressing an issue. You should push your changes to a feature branch and request merge to develop
.
Make sure linting and tests pass and coverage is 💯 before creating a pull request!