Gap buffer

295 views
Skip to first unread message

Archos

unread,
Jun 4, 2013, 5:28:49 AM6/4/13
to golan...@googlegroups.com
I'm implementing a gap buffer since it looks the better way to edit a line; it is not to be used into a editor else for the command line.

The next printing shows how is working now, where '*' indicates data set to zero and |__| is the gap (the space to use when data is inserted).
The gap slice is moved when the cursor is between data (no home neither end of line) since the user could inset data just there.

// []rune with len=32
 Cursor:  0 · Gap start: 15 · Gap end: 31  [***************|_______________|]
// data entered: 0-9 so the cursor is in position 10.
 Cursor: 10 · Gap start: 15 · Gap end: 31  [0123456789*****|_______________|]

// I'm moving the cursor one character to left, until after of character 4; like you can see all data
// after of the cursor is moved after of the gap.
 Cursor:  9 · Gap start: 14 · Gap end: 30  [012345678*****|_______________|9]
 Cursor:  8 · Gap start: 13 · Gap end: 29  [01234567*****|_______________|89]
 Cursor:  7 · Gap start: 12 · Gap end: 28  [0123456*****|_______________|789]
 Cursor:  6 · Gap start: 11 · Gap end: 27  [012345*****|_______________|6789]
 Cursor:  5 · Gap start: 10 · Gap end: 26  [01234*****|_______________|56789]

My question is: When the gap is moved, those data to zero (*),

(a) should be moved at the end of the buffer,
    [01234|_______________|56789*****]

(b) after of the gap,
    [01234|_______________|*****56789]

(c) or is right like it is now?

* I was thinking that other option could be to use 2 buffers, one to insert data linearly (when cursor is outside of home or end of line) and the other one when data is inserted which would be inserted in the first buffer when the cursor is moved or at pressing enter.

Brad Fitzpatrick

unread,
Jun 4, 2013, 11:50:40 AM6/4/13
to Archos, golang-nuts
This is golang-nuts, not Stackoverflow.





--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Archos

unread,
Jun 4, 2013, 3:23:42 PM6/4/13
to golan...@googlegroups.com
So, here is the source code in Go:

https://github.com/kless/term/blob/master/gapbuffer/gap.go

because it is not StackOverflow, it is golang-nuts.

peterGo

unread,
Jun 5, 2013, 11:00:43 AM6/5/13
to golan...@googlegroups.com
Archos,

Brad's point is that your question is about data structures and algorithms (stackoverflow), not the Go programming language (golang-nuts): http://en.wikipedia.org/wiki/Gap_buffer.

Rephrasing your question in the Go programming language still leaves it as a data structures and algorithms question (stackoverflow).

Peter

Archos

unread,
Jun 5, 2013, 12:33:33 PM6/5/13
to golan...@googlegroups.com
Well, I found help in Reddit
Reply all
Reply to author
Forward
0 new messages