ubilabs / kd-tree-javascript

JavaScript k-d Tree Implementation
MIT License
642 stars 109 forks source link

Adding serialization capability #4

Closed rf closed 11 years ago

rf commented 11 years ago

Hi,

I've added the ability to serialize a tree and restore it from the serialization. This way, a tree can be generated on a server and then pulled to a client where it is loaded and used. Example:

var tree = new kdTree(stops, haversine, ['x', 'y']);
fs.writeFileSync('kdtree.json', JSON.stringify(tree, false, 4));

// Later ...
var treeData = JSON.parse(fs.readFileSync('kdtree.json', 'utf8'));
var newTree = new kdTree(treeData, haversine, ['x', 'y']);