This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Item = null | string | number | boolean | Item[] | {[k: string]: Item}; | |
// Must match the shape of the data | |
type Version = number | [number, Version[]] | [number, {[k: string]: Version}]; | |
type Path = (string | number)[] | |
interface Doc { | |
data: Item, | |
versions: Version, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[cfg(test)] | |
mod tests{ | |
// *** Mad science *** | |
#[test] | |
fn positional_updates_1() { | |
// This variant leans on ins_del_runs to just use a single stream of insert and delete positions. | |
#[derive(Debug, Eq, PartialEq, Clone, Copy)] | |
struct Run3 { | |
diff: i32, // From previous item |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const genOp = require('./genOp') | |
// const genOp = require('./genOp2') | |
const {type} = require('ot-text-unicode') | |
// const {type} = require('ot-text-tp2') | |
const assert = require('assert') | |
const genOps = (start, n = 3) => { | |
let ops = [] | |
let state = start |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run with node --expose-gc bench.js ../automerge-paper.json.gz | |
// automerge-paper.json.gz from https://github.com/josephg/crdt-benchmarks | |
// Read in a patch file and check that the patches all apply correctly. | |
const fs = require('fs') | |
const assert = require('assert') | |
const zlib = require('zlib') | |
const automerge = require('automerge') | |
const v8 = require('v8') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CACHE = { | |
_root: { | |
text: { | |
elems: [ | |
{ | |
elemId: '2@3cb54fecd444446cbe579bd128017c42', | |
pred: [ '2@3cb54fecd444446cbe579bd128017c42' ], | |
value: 'a' | |
}, | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
seq: 4, | |
maxOp: 4, | |
requests: [], | |
clock: { '09828cbcb7e14699b37ad87ffe64b448': 4 }, | |
deps: [], | |
backendState: { | |
state: Map { | |
size: 2, | |
_root: ArrayMapNode { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import assert from 'assert' | |
import seed from 'seed-random' | |
type Id = [agent: string, seq: number] | |
type Version = Record<string, number> // Last seen seq for each agent. | |
type Algorithm = { | |
integrate: <T>(doc: Doc<T>, newItem: Item<T>) => void | |
ignoreTests?: string[] | |
}// & Record<string, any> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This implements the core algorithm of Yjs, but with some tweaks in about 100 lines. | |
// This is a toy and it probably still has some small bugs. | |
import assert from 'assert/strict' | |
type Id = { | |
agent: string, | |
seq: number, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Y from 'yjs' | |
const makeYDoc = (clientId: number) => { | |
const doc = new Y.Doc() | |
doc.clientID = clientId | |
return doc | |
} | |
const yjsMergeInto = (target: Y.Doc, src: Y.Doc) => { | |
const sv = Y.encodeStateVector(target) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This is a simple example program showing a working in-memory database storing | |
* full history and branches. In this demo the "database" is a Map from string | |
* keys to values. | |
* | |
* Everything is versioned - you can wind time forward and backwards, and mark a | |
* branch and teleport the database back to that point in time. | |
* | |
* Conflicts are handled similarly to Basho's riak. When concurrent writes | |
* happen, the database stores every concurrent version of the document. A |