Flexichain An editable sequence and its gap-buffer implementation - - PowerPoint PPT Presentation

flexichain an editable sequence and its gap buffer
SMART_READER_LITE
LIVE PREVIEW

Flexichain An editable sequence and its gap-buffer implementation - - PowerPoint PPT Presentation

Flexichain An editable sequence and its gap-buffer implementation Robert Strandh, Tim Moore, Matthieu Villeneuve strandh@labri.fr, moore@labri.fr, matthieu.villeneuve@free.fr Laboratoire Bordelais de Recherche en Informatique (LaBRI)


slide-1
SLIDE 1

Flexichain An editable sequence and its gap-buffer implementation

Robert Strandh, Tim Moore, Matthieu Villeneuve

strandh@labri.fr, moore@labri.fr, matthieu.villeneuve@free.fr

Laboratoire Bordelais de Recherche en Informatique (LaBRI)

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.1/19

slide-2
SLIDE 2

API Model

An editable sequence of objects containing an arbitrary number of cursors.

Arbitrary Objects Cursors

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.2/19

slide-3
SLIDE 3

Uses of API

  • Emacs-like text editors for the entire buffer
  • Emacs-like text editors for one line of a buffer
  • Emacs-like text editors for the sequence of

lines

  • Gsharp (at 4 different levels)

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.3/19

slide-4
SLIDE 4

Possible representations

  • Doubly linked list
  • Gap buffer

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.4/19

slide-5
SLIDE 5

Doubly linked list

Advantages: fast, easy to implement Inconveniences: no direct access, high memory

  • verhead

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.5/19

slide-6
SLIDE 6

Gap buffer

Advantages: direct access, low memory overhead Inconveniences: slow worst-case, hard to implement

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.6/19

slide-7
SLIDE 7

Previous work

  • Multics Emacs: a doubly-linked list of lines,

each line a vector (special instructions)

  • GNU Emacs: entire buffer is a gap buffer
  • Hemlock: doubly-linked list of lines, the open

line is a gap buffer

  • Goatee (McCLIM): doubly-linked list of lines,

each line is a gap buffer

  • Gsharp: currently uses singly-linked lists

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.7/19

slide-8
SLIDE 8

Purpose of Flexichain

In order of priorities:

  • 1. Replace specialized, slow code in Gsharp
  • 2. Replace line implementation in Goatee
  • 3. Replace list of lines in Goatee
  • 4. Perhaps use in portable Hemlock

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.8/19

slide-9
SLIDE 9

Two layers: Flexichain and cursorchain

The Flexichain layer uses positions to access, insert, and delete elements. The Cursorchain layer uses cursors. The two are compatible.

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.9/19

slide-10
SLIDE 10

The Flexichain layer

insert<* chain element position insert>* chain element position delete* chain position element* chain position (setf element*) position element chain

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.10/19

slide-11
SLIDE 11

Stack and queue operations

push-start chain element push-end chain element pop-start chain pop-end chain rotate chain &optional (n 1)

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.11/19

slide-12
SLIDE 12

Implementation of Flexichain layer

  • Use a gap buffer
  • Consider the buffer as circular (avoids bad

worst cases)

  • Expand and shrink factors
  • Moving the gap is messy

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.12/19

slide-13
SLIDE 13

Moving the gap

Three situations exist: Move left or right according to the number of elements that need to be moved in each case.

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.13/19

slide-14
SLIDE 14

Moving the gap

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.14/19

slide-15
SLIDE 15

The Cursorchain layer

at-beginning-p cursor at-end-p cursor move< cursor move> cursor insert< object cursor insert> object cursor delete< cursor &optional (n 1) delete> cursor &optional (n 1) element< cursor element> cursor

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.15/19

slide-16
SLIDE 16

The Cursorchain layer

  • cursorchain is a subclass of flexichain
  • cursors store physical position rather than

logical positions in order to avoid updating all cursors at every operation

  • to avoid memory leaks, we use weak

references to store cursors

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.16/19

slide-17
SLIDE 17

The Cursorchain layer

  • we use an internal protocol for resizing and for

moving the gap

  • cursor update are done by :before and

:after methods of internal protocol

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.17/19

slide-18
SLIDE 18

State of implementation

Flexichain is finished. Cursorchain will be finished this summer (we all have daytime jobs).

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.18/19

slide-19
SLIDE 19

That’s all

Thank You! Questions?

Flexichain – Lisp and Scheme Conference, Oslo 2004 – p.19/19