Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization of sorted btree #34

Open
mcndt opened this issue Mar 5, 2022 · 2 comments
Open

Serialization of sorted btree #34

mcndt opened this issue Mar 5, 2022 · 2 comments
Labels
question Further information is requested

Comments

@mcndt
Copy link

mcndt commented Mar 5, 2022

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?

@kamarmack
Copy link

^ Also have same question

@qwertie
Copy link
Owner

qwertie commented Mar 9, 2022

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.

@qwertie qwertie added the question Further information is requested label Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants