From 81dd326da683f53cecee75b907f55dbd1b5d5460 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Fri, 12 Jan 2024 23:03:24 +0100 Subject: par: piece-table: useful comments --- par/piece-table.scm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/par/piece-table.scm b/par/piece-table.scm index c638a2d..6b3985b 100644 --- a/par/piece-table.scm +++ b/par/piece-table.scm @@ -113,7 +113,7 @@ ;; The piece table itself; ;; original is a ro-buffer, add is an add-buffer (a string designed to grow) -;; and pieces is a list of pieces +;; and pieces is a list of pieces (should we avoid allocations?) (define-record-type (%make-piece-table original-buffer add-buffer pieces) piece-table? @@ -129,6 +129,7 @@ (list (make-piece ro-buffer 0 (string-length original) 'normal))))) (define (piece-table-index piece-table pos) + ;; TODO: Validate input (let loop ((pieces (piece-table-pieces piece-table)) (start 0)) (let* ((piece (car pieces)) @@ -158,6 +159,10 @@ (values (take l i) (list-ref l i) (drop l (+ 1 i))))) (define (piece-table-insert! piece-table pos str type) + ;; TODO: validate input + ;; TODO: Try to reuse the caracters on the target buffer if they are already + ;; there? Is this maximum evilness? => it's just a string-ref and it prevents + ;; us from creating pieces! (define candidate ((add-buffer-append! (piece-table-add-buffer piece-table) str) type)) @@ -182,6 +187,7 @@ ; - That would need other way to find the affected pieces and manipulate them. ; > we'll leave it for the future (define (piece-table-delete! piece-table from len) + ;; TODO: Validate input (let*-values (((idx rem) (piece-table-text-pos->piece-idx+remainder piece-table from)) ; TODO because of the <= ((end-idx end-rem) (piece-table-text-pos->piece-idx+remainder -- cgit v1.2.3