diff --git a/design/data-structure.md b/design/data-structure.md index ec4711bb2..beeba1d1e 100644 --- a/design/data-structure.md +++ b/design/data-structure.md @@ -44,7 +44,7 @@ JSON-like data strucutres are used when editing JSON-like documents. - `Primitive`: represents primitive data like `string`, `number`, `boolean`, `null`, etc. - `Object`: represents [object type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) of JavaScript. Just like JavaScript, you can use `Object` as [hash table](https://en.wikipedia.org/wiki/Hash_table). -- `Array`: represents [array type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) of JavaScript. You can also use `Array` as [list](https://en.wikipedia.org/wiki/List_(abstract_data_type)). +- `Array`: represents [array type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) of JavaScript. You can also use `Array` as [list](). - `Text`: represents text with style attributes in rich text editors such as [Quill](https://github.com/yorkie-team/yorkie-js-sdk/blob/main/examples/quill.html). Users can express styles such as bold, italic, and underline to text content. Of course, it can represent just a plain text in text-based editors such as [CodeMirror](https://github.com/yorkie-team/yorkie-js-sdk/blob/main/examples/index.html). It supports collaborative editing; multiple users can modify parts of the contents without conflict. JSON-like data structures can be edited through proxies. For example: @@ -79,8 +79,8 @@ Common data structures can be used for general purposes. - [`SplayTree`](https://en.wikipedia.org/wiki/Splay_tree): A tree that moves nodes to the root by splaying. This is effective when user frequently access the same location, such as text editing. We use `SplayTree` as an index tree to give each node a weight, and to quickly access the node based on the index. - [`LLRBTree`](https://en.wikipedia.org/wiki/Left-leaning_red%E2%80%93black_tree): A tree simpler than Red-Black Tree. Newly added `floor` method finds the node of the largest key less than or equal to the given key. -- [`Trie`](https://en.wikipedia.org/wiki/Trie): A data structure that can quickly search for prefixes of sequence data such as strings. We use `Trie` to remove nested events when the contents of the `Document`' are modified at once. +- [`Trie`](https://en.wikipedia.org/wiki/Trie): A data structure that can quickly search for prefixes of sequence data such as strings. We use `Trie` to remove nested events when the contents of the `Document` are modified at once. ### Risks and Mitigation -We can replace the data structures with better ones for some reason, such as performance. For example, `SplayTree` used in `RGATreeList` can be replaced with [TreeList](https://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/list/TreeList.html). \ No newline at end of file +We can replace the data structures with better ones for some reason, such as performance. For example, `SplayTree` used in `RGATreeList` can be replaced with [TreeList](https://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/list/TreeList.html). diff --git a/design/range-deletion-in-splay-tree.md b/design/range-deletion-in-splay-tree.md index 114f25f78..cc479337a 100644 --- a/design/range-deletion-in-splay-tree.md +++ b/design/range-deletion-in-splay-tree.md @@ -2,6 +2,7 @@ title: delete-range-in-splay-tree target-version: 0.2.12 --- + --- # Range Deletion in Splay Tree @@ -14,7 +15,7 @@ Using the feature of a splay tree that changes the root freely, `splay.DeleteRan ### Goals -The function `DeleteRange` should separate all nodes exactly in the given range as a subtree. After executing the function, the entire tree from and weight of every node must be correct just as when the nodes were deleted one by one. +The function `DeleteRange` should separate all nodes exactly in the given range as a subtree. After executing the function, the entire tree structure and weight of every node must be correct just as when the nodes were deleted one by one. ## Proposal Details @@ -24,8 +25,7 @@ From the property of indexed BST, all nodes with a smaller index than the root a And also, Splay Tree can change the root freely to use `Splay`. -Then using the properties, when we want to delete the range from index `L` to `R` we can make the shape of tree like the figure avobe to `Splay(L-1)` then `Splay(R+1)`. - +Then using the properties, when we want to delete the range from index `L` to `R` we can make the shape of tree like the figure above to `Splay(L-1)` then `Splay(R+1)`. ![delete-range-in-splay-tree-2](./media/range-deletion-in-splay-tree-2-separation.png) @@ -39,10 +39,10 @@ func (t *Tree[V]) DeleteRange(leftBoundary, rightBoundary *Node[V]) { t.cutOffRight(leftBoundary) return } - + t.Splay(leftBoundary) t.Splay(rightBoundary) - + // refer case 2 of second figure if rightBoundary.left != leftBoundary { t.rotateRight(leftBoundary) @@ -51,9 +51,11 @@ func (t *Tree[V]) DeleteRange(leftBoundary, rightBoundary *Node[V]) { } ``` + Sometimes the tree shapes like case 2 after `Splay`s because of the zig-zig case of `Splay`. But it simply changes to the same shapes as case 1 in one rotation for `L-1`. Then now to cut off the right child(subtree) of `L-1`, we can separate all nodes in the given range to be deleted. + ### Risks and Mitigation `DeleteRange` does not consider the occurrence of new nodes due to concurrent editing in the range to be deleted. They should be filtered before using `DeleteRange`, and `DeleteRange` should be executed continuously in the smaller ranges that do not include them.