ipfs / notes

IPFS Collaborative Notebook for Research
MIT License
400 stars 33 forks source link

Immutable data structures #112

Open odipar opened 8 years ago

odipar commented 8 years ago

Everything immutable! That's been my motto for almost a decade!

It seems that I'm not the only one: more and more frameworks share this 'immutability' property, including IPFS.

When I look at all the reddit and hackernews comments related to IPFS, most commenters are worried that IPFS cannot deal with 'dynamic' content. Nonsense!

But then you need to know that new (versions of) immutable data structures can be efficiently created, merged and altered, just like their mutable counterparts.

You just have to look at Clojure's Vector implementation to get an idea of how efficient immutable data structures can be in practice. In fact, there is a whole body of research out there that deal with various immutable data structures, such as:

Now the point is: all these data structures can be trivially Merkle-ized. Indeed, Merkle-zation is the premise of IPFS!

Of course, IPFS is much more. It needs strong P2P and DHT technology to make it a reality. But IPFS is also less, because it doesn’t provide a standard API to build (immutable) data.

For now, I’ll end with some related technology:

So, do you think IPFS needs an API to build data structures? Or should that be left to the client, using IPFS?

Kubuxu commented 8 years ago

Please take a look at recently written specs for InterPlanetary Linked Data. It is standardised way with which applications can use to create data that can be directly stored in IPFS. https://github.com/ipfs/specs/blob/master/merkledag/ipld.md

I plan to work on Conflict-free Replicated Data Types on top of IPLD.

odipar commented 8 years ago

Yeah, I've read the specification, but it doesn't specify an API to manage/create/merge immutable data. So for example, an API like this (in scala):

def create(s: Array[Byte]): IPFS_DATA  // O(array.size)
def create(s: Array[IPFS_DATA]): IPFS_DATA  // O(array.size)
def concatenate(d1: IPFS_DATA, d2: IPFS_DATA): IPFS_DATA // O(log(n)) - n = total size
def splitAt(d: IPFS_DATA,  l: Location): (IPFS_DATA,IPFS_DATA) // O(log(n))
def destructure(d: IPFS_DATA): Array[IPFS_DATA] // O(array.size)

I believe that most Conflict-free Replicated Data Types also needs to be build on top of such immutable data structure API.