btree-typescript
btree-typescript copied to clipboard
Serialization of sorted btree
What would be the best method for serialization of a sorted btree (using interface ISortedMap
)?
Is it safe to use JSON.stringify, or would you recommend serializing the iterable and then reconstructing the tree from the resulting array?
^ Also have same question
BTree
should be serialized in array form, like this:
let btree1 = new BTree<number>([[1, 'one'], [2, 2.22]]);
let json = JSON.stringify([... btree1.entries()]);
let btree2 = new BTree<number>(JSON.parse(json));
If you use JSON.stringify
you'll get the internal contents of the BTree as JSON, and (1) I don't know any way to reconstruct the BTree
object from that, (2) but if I did, I would still advise against storing it that way because future versions could theoretically use different names for private properties.