首页
随机
最近更改
特殊页面
社群首页
参数设置
关于WHY42
免责声明
WHY42
搜索
用户菜单
登录
欢迎来到Riguz的小站!这是一个私人wiki,用来记录一些我的笔记。
查看“︁Yjs state vector”︁的源代码
←
Yjs state vector
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
Yjs has the ability to exchange only the differences when syncing two clients. We use lamport timestamps to identify structs and to track in which order a client created them. Each struct has an <syntaxhighlight lang="java" inline>struct.id = { client: number, clock: number}</syntaxhighlight> that uniquely identifies a struct. We define the next expected clock by each client as the state vector. This data structure is similar to the version vectors data structure. But we use state vectors only to describe the state of the local document, so we can compute the missing struct of the remote client. We do not use it to track causality. <ref>https://github.com/yjs/yjs?tab=readme-ov-file#state-vector</ref> Format: * Size: VarUint * Entries: Client(VarUint), Clock(VarUint) <syntaxhighlight lang="ts"> const toHexString = (bytes) => { return Array.from(bytes, (byte) => { return ("0" + (byte & 0xff).toString(16)).slice(-2); }).join(""); }; const doc = new Y.Doc(); console.log("doc.clientID", doc.clientID); // doc.clientID 1077651333 varUint(1077651333)=85cfee8104 console.log("state vector", toHexString(Y.encodeStateVector(doc))); // state vector 00 const root = doc.getText("root"); root.insert(0, "Hello"); console.log("state vector", toHexString(Y.encodeStateVector(doc))); // state vector 0185cfee810405 -> client(1077651333, 5) root.insert(5, "World!"); console.log("state vector", toHexString(Y.encodeStateVector(doc))); // state vector 0185cfee81040b -> client(1077651333, 11) </syntaxhighlight> [[Category:Yjs]] [[Category:CRDT]]
返回
Yjs state vector
。