zandaqo / structurae

Data structures for high-performance JavaScript applications.
MIT License
701 stars 21 forks source link

Persistent data structures? #20

Open joakim opened 3 years ago

joakim commented 3 years ago

Could the binary structures serve as the basis for persistent data structures, implemented as HAMT?

zandaqo commented 3 years ago

That's an interesting question. The binary or *view structures can encode any structured data one can describe, say, with JSONSchema. I use them as a simpler, js specific alternative to FlatBuffers for storage and transfer where JSON is too much of an overhead and the structures are too complex to just get away with a DataView or TypedArrays.

In case of HAMT, we can, for example, encode the resulting array of nodes as a VectorView (or several) of MapViews representing structures for nodes. This will essentially make the result immutable, since we cannot change the length of the created VectorView(s), and have some overhead depending on the way we describe the structures for nodes, though I'm sure it will be much less than most other ways of encoding will give us.