Hacker News new | ask | show | jobs
by marknadal 2350 days ago
Same algorithm for everything.

This cartoon explains it:

https://gun.eco/distributed/matters.html

It is a vector + timestamp + lexical sort.

A delete is changing a value to `null`, it would lose (I assume you are asking if/when these 2 changes happen at the exact same microsecond time, conflicting?) as is it has a lower lexical rank.

1 comments

Can you refer me to a document where you explain the "lexical rank" that you are referring to?

The cartoon explanation do not tackle those terms.

JSON.stringify('a') < JSON.stringify('z')

https://en.wikipedia.org/wiki/Lexicographical_order

Cool! Make sense.

Let's say our state have an array like ['a','b'].

What about if Peer-A splice the first element (0) which results in ['b'] and Peer-B wants to mutate 'a' to 'A' which results in ['A','b'] and they both make the mutation at the same millisecond?

You have to choose which type of Array:

1. An atomic Array

2. Fixed index Array

3. Linked list

Now rather than not knowing what magic is going to happen, app developers know what to expect in advance.

So atomic would choose one or the other, not a combined result.

Fixed array 2nd item to 1st which nulls 2nd and makes 1st b, simultaneously also makes 1st A. Cause lower case b is lexically larger than A, you'd get [b, null].

Linked list theoretically could handle it as you suggest.

Does gun have a built-in "Linked list" in the API? If so, where are the docs? Could not find them.

If not, any paper or doc that explain how to implement it with gun?

Started, but never finished. :(

@nmaro has some pretty good stuff.

The cartoon explainers gives an overview.

But you'd probably want to do RGA algorithm or one of the newer ones.

Martin Kleppmann has a pretty good talk with bunch of paper references:

https://youtu.be/yCcWpzY8dIA