[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/crdt 432b5f8 04/80: two bug fixes for CRDT algorithm
From: |
ELPA Syncer |
Subject: |
[elpa] externals/crdt 432b5f8 04/80: two bug fixes for CRDT algorithm |
Date: |
Sat, 28 Aug 2021 10:57:30 -0400 (EDT) |
branch: externals/crdt
commit 432b5f8609eccf23286cd6ff041ea772020a56a3
Author: Qiantan Hong <qhong@mit.edu>
Commit: Qiantan Hong <qhong@mit.edu>
two bug fixes for CRDT algorithm
---
crdt.el | 73 ++++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 38 insertions(+), 35 deletions(-)
diff --git a/crdt.el b/crdt.el
index 3f34480..761c676 100644
--- a/crdt.el
+++ b/crdt.el
@@ -27,7 +27,7 @@
;; Text-based version
;; (it should be easy to migrate to a binary version. Using text for better
debugging for now)
;; Every message takes the form (type . body)
-;; type can be: insert hello cursor challenge sync
+;; type can be: insert delete cursor hello challenge sync
;; - insert
;; body takes the form (crdt-id position-hint content)
;; - position-hint is the buffer position where the operation happens at
the site
@@ -125,8 +125,8 @@
;; For base IDs, last two bytes are always representing site ID
;; Stored strings are BASE-ID:OFFSETs. So the last two bytes represent offset,
;; and second last two bytes represent site ID
-(defconst crdt--max-value (lsh 1 16))
-;; (defconst crdt--max-value 16)
+;; (defconst crdt--max-value (lsh 1 16))
+(defconst crdt--max-value 16)
;; for debug
(defconst crdt--low-byte-mask 255)
(defsubst crdt--get-two-bytes (string index)
@@ -354,6 +354,7 @@ Returns a list of (insert type) messages to be sent."
(push `(insert ,(base64-encode-string virtual-id) ,beg
,(buffer-substring-no-properties beg merge-end))
resulting-commands))
+ (cl-incf left-offset (- merge-end beg))
(setq beg merge-end)))))
(while (< beg end)
(let ((block-end (min end (+ crdt--max-value beg))))
@@ -424,15 +425,15 @@ Returns a list of (insert type) messages to be sent."
(let ((outer-end end))
(crdt--with-insertion-information
(beg 0 nil crdt--changed-string nil (length crdt--changed-string))
- (if (crdt--split-maybe)
- (let* ((not-end (< outer-end (point-max)))
- (ending-id (when not-end (crdt--get-starting-id outer-end))))
- (when (and not-end (eq starting-id (crdt--get-starting-id
outer-end)))
- (crdt--set-id outer-end (crdt--id-replace-offset starting-id (+ 1
left-offset (length crdt--changed-string))))
- t))
- (crdt--with-insertion-information
- ((length crdt--changed-string) outer-end crdt--changed-string nil 0
nil)
- (crdt--split-maybe)))))
+ (when (crdt--split-maybe)
+ (let* ((not-end (< outer-end (point-max)))
+ (ending-id (when not-end (crdt--get-starting-id outer-end))))
+ (when (and not-end (eq starting-id (crdt--get-starting-id outer-end)))
+ (crdt--set-id outer-end (crdt--id-replace-offset starting-id (+ 1
left-offset (length crdt--changed-string))))))
+ ))
+ (crdt--with-insertion-information
+ ((length crdt--changed-string) outer-end crdt--changed-string nil 0 nil)
+ (crdt--split-maybe)))
;; (crdt--verify-buffer)
`(delete ,beg ,@ (crdt--dump-ids 0 (length crdt--changed-string)
crdt--changed-string t)))
(defun crdt--remote-delete (position-hint id-pairs)
@@ -450,9 +451,10 @@ Returns a list of (insert type) messages to be sent."
(setq length 0))
((-1)
(let* ((starting-id (crdt--get-starting-id (point)))
+ (eob (crdt--end-of-block-p (point)))
(left-offset (crdt--get-id-offset starting-id (point))))
(delete-char length)
- (crdt--set-id (point) (crdt--id-replace-offset starting-id (+
left-offset length))))
+ (crdt--set-id (point) (crdt--id-replace-offset starting-id (+
left-offset length)) eob))
(setq length 0)))))
;; (crdt--verify-buffer)
)))
@@ -490,26 +492,27 @@ Returns a list of (insert type) messages to be sent."
(1- (crdt--find-id id hint))
(point-max)))
(defun crdt--remote-cursor (site-id point-position-hint point-crdt-id
mark-position-hint mark-crdt-id)
- (let ((ov-pair (gethash site-id crdt--overlay-table)))
- (if point-crdt-id
- (let* ((point (crdt--id-to-pos point-crdt-id point-position-hint))
- (mark (if mark-crdt-id
- (crdt--id-to-pos mark-crdt-id mark-position-hint)
- point)))
- (unless ov-pair
- (let ((new-cursor (make-overlay 1 1))
- (new-region (make-overlay 1 1)))
- (overlay-put new-cursor 'face `(:background
,(crdt--get-cursor-color site-id)))
- (overlay-put new-cursor 'category 'crdt-pseudo-cursor)
- (overlay-put new-region 'face `(:background
,(crdt--get-region-color site-id) :extend t))
- (setq ov-pair (puthash site-id (cons new-cursor new-region)
- crdt--overlay-table))))
- (crdt--move-cursor (car ov-pair) point)
- (crdt--move-region (cdr ov-pair) point mark))
- (when ov-pair
- (remhash site-id crdt--overlay-table)
- (delete-overlay (car ov-pair))
- (delete-overlay (cdr ov-pair))))))
+ (when site-id
+ (let ((ov-pair (gethash site-id crdt--overlay-table)))
+ (if point-crdt-id
+ (let* ((point (crdt--id-to-pos point-crdt-id point-position-hint))
+ (mark (if mark-crdt-id
+ (crdt--id-to-pos mark-crdt-id mark-position-hint)
+ point)))
+ (unless ov-pair
+ (let ((new-cursor (make-overlay 1 1))
+ (new-region (make-overlay 1 1)))
+ (overlay-put new-cursor 'face `(:background
,(crdt--get-cursor-color site-id)))
+ (overlay-put new-cursor 'category 'crdt-pseudo-cursor)
+ (overlay-put new-region 'face `(:background
,(crdt--get-region-color site-id) :extend t))
+ (setq ov-pair (puthash site-id (cons new-cursor new-region)
+ crdt--overlay-table))))
+ (crdt--move-cursor (car ov-pair) point)
+ (crdt--move-region (cdr ov-pair) point mark))
+ (when ov-pair
+ (remhash site-id crdt--overlay-table)
+ (delete-overlay (car ov-pair))
+ (delete-overlay (cdr ov-pair)))))))
(cl-defun crdt--local-cursor (&optional (lazy t))
(let ((point (point))
@@ -585,7 +588,7 @@ If CRDT--NETWORK-PROCESS is a server process, broadcast
MESSAGE-STRING
to clients except the one of which CLIENT-ID property is EQ to WITHOUT.
If CRDT--NETWORK-PROCESS is a server process, send MESSAGE-STRING
to server unless WITHOUT is NIL."
- ;; (message message-string)
+ ;; (message "Send %s" message-string)
(if (process-contact crdt--network-process :server)
(dolist (client crdt--network-clients)
(when (and (eq (process-status client) 'open)
@@ -705,7 +708,7 @@ to server unless WITHOUT is NIL."
(goto-char (point-min))
(let (message)
(while (setq message (ignore-errors (read (current-buffer))))
- (print message)
+ ;; (print message)
(with-current-buffer (process-get process 'crdt-buffer)
(save-excursion
(widen)
- [elpa] externals/crdt 6b320c7 11/80: bug fix, (continued)
- [elpa] externals/crdt 6b320c7 11/80: bug fix, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt bfce95c 17/80: formatting, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt 692d2cc 24/80: initial work for lazily pulling buffer, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt b8cd461 22/80: Minor improvements, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt 8307092 29/80: better read function, tab width wider, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt 4c7e12d 37/80: documentation, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt 53e5676 33/80: fix bug with org table, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt fcc6a47 38/80: fix upper/lowercase convention, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt e1b0fe9 02/80: Fixed silly typo!, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt 88cd9a1 03/80: refactorz, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt 432b5f8 04/80: two bug fixes for CRDT algorithm,
ELPA Syncer <=
- [elpa] externals/crdt 82a7565 10/80: fix authentication bug, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt b95111c 15/80: add makefile, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt 60bb2ac 07/80: lots of functionalities, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt a157310 12/80: better formatting, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt 5ec25f7 20/80: input method seems to work now, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt ea632a3 26/80: some docstring and unused variable, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt 68d3067 18/80: bug fix, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt d9d7100 53/80: remote process support, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt 9a7ce57 56/80: fix fill-paragraph bug, ELPA Syncer, 2021/08/28
- [elpa] externals/crdt bc98495 60/80: I imagine this fix an imaginary bug with tuntox, ELPA Syncer, 2021/08/28