multiple-tree
v1.0.1
Published
Nodejs Multiple tree lib
Downloads
3
Readme
MultipleTree
介绍
Nodejs实现的多叉树库
APIS
- select(object)
传入一个对象 判断在多叉树中是否存储了这个对象 return : true/false
- insert(object)
插入这个对象,true为成功,false则说明已经存在
- grow(object)
不存在则插入 返回true,存在返回false
- delete(object)
删除对象
- clear()
清空字典树
- walk()
返回整个字典树对象
例子
const Tree = require('multiple-tree');
let tree = new Tree();
let a = {
a:1,
b:2,
c:3
}
tree.insert(a);
console.log("tree select ",tree.select(a));
console.log(tree.insert({
a:1,b:2,c:3,d:4
}));
tree.insert({
a:1,b:2,c:3,d:5
});
tree.insert({
a:1,b:2,c:3,d:7
});
tree.grow({
a:1,b:2,c:3,d:6
});
tree.grow({
a:1,b:2,c:3,d:8
});
tree.grow({
a:1,b:2,c:3,d:9
});
tree.grow({
a:1,b:2,c:3,d:9,e:10
});
console.log(tree.grow({
a:1,b:2,c:3,d:9,e:10
}));
console.log("tree walk ",JSON.stringify(tree.walk()));
tree.delete({
a:1,b:2,c:3,d:9,e:10
})
console.log("tree walk ",JSON.stringify(tree.walk()));
输出:
tree select true
true
false
tree walk {"1":{"2":{"3":{"4":{},"5":{},"6":{},"7":{},"8":{},"9":{"10":{}}}}}}
tree walk {"1":{"2":{"3":{"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}}}}}