Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Issue 5158004: Generic Gap Buffer data structure (Closed)

Created:
10 years, 1 month ago by varunjain
Modified:
9 years, 7 months ago
CC:
chromium-reviews, ben+cc_chromium.org, Paweł Hajdan Jr., brettw-cc_chromium.org
Visibility:
Public.

Description

Generic Gap Buffer data structure BUG=none TEST=unittest added for new GapBuffer class

Patch Set 1 #

Patch Set 2 : removed unrelated files #

Patch Set 3 : Addressed reviewer's comments #

Total comments: 21

Patch Set 4 : addressed comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+386 lines, -0 lines) Patch
M base/base.gyp View 1 chunk +1 line, -0 lines 0 comments Download
M base/base.gypi View 1 chunk +1 line, -0 lines 0 comments Download
A base/gap_buffer.h View 1 2 3 1 chunk +219 lines, -0 lines 0 comments Download
A base/gap_buffer_unittest.cc View 1 2 1 chunk +165 lines, -0 lines 0 comments Download

Messages

Total messages: 8 (0 generated)
varunjain
10 years, 1 month ago (2010-11-18 03:46:19 UTC) #1
tfarina
http://codereview.chromium.org/5158004/diff/4001/base/gap_buffer.h File base/gap_buffer.h (right): http://codereview.chromium.org/5158004/diff/4001/base/gap_buffer.h#newcode9 base/gap_buffer.h:9: #include <stdio.h> Hum? Why do you need this here? ...
10 years, 1 month ago (2010-11-18 12:03:22 UTC) #2
varunjain
http://codereview.chromium.org/5158004/diff/4001/base/gap_buffer.h File base/gap_buffer.h (right): http://codereview.chromium.org/5158004/diff/4001/base/gap_buffer.h#newcode9 base/gap_buffer.h:9: #include <stdio.h> On 2010/11/18 12:03:23, tfarina wrote: > Hum? ...
10 years, 1 month ago (2010-11-18 17:53:44 UTC) #3
sky
Meta comment. I get that you're trying to implement gap buffer, but as the API ...
10 years, 1 month ago (2010-11-18 18:26:07 UTC) #4
rjkroege
assorted comments on an older revision. http://codereview.chromium.org/5158004/diff/4001/base/gap_buffer.h File base/gap_buffer.h (right): http://codereview.chromium.org/5158004/diff/4001/base/gap_buffer.h#newcode20 base/gap_buffer.h:20: // This class ...
10 years, 1 month ago (2010-11-18 19:34:28 UTC) #5
varunjain
Hi Scott, Rob, While I am taking care of code comments, I thought I would ...
10 years, 1 month ago (2010-11-18 20:35:19 UTC) #6
Ben Goodger (Google)
This file should live in views/controls/textfield. There is another effort under way to reduce the ...
10 years, 1 month ago (2010-11-18 20:46:47 UTC) #7
sky
10 years, 1 month ago (2010-11-18 20:57:34 UTC) #8
On Thu, Nov 18, 2010 at 12:35 PM,  <varunjain@chromium.org> wrote:
> Hi Scott, Rob,
>
> While I am taking care of code comments, I thought I would reply to the API
> concerns you have raised..
>
> @Scott
> For a generic string data structure your API suffices. But for a gap buffer,
> I
> think it is important to expose api for gap movement as well.

Why? Like I said, why do you as the user of such an API care where the
gap is? Let the implementation deal with it.

> You have to
> think
> of it in terms of a textfield with a cursor. If the user moves the cursor
> for a
> while and then inserts/deletes a char, your api will have to move the gap to
> the
> new location at the time of insertion/deletion.

The API I am proposing does not explicitly move any gaps. It just
invokes insert/delete, the implementation takes care of whatever it
needs to do.

> Whereas, if the gap is moved
> with the cursor (by exposing a MoveGapBlah API) then the cost of moving the
> gap
> is amortized over all the cursor movements made by the user.

I find that hard to believe. But either way, this is hardly going to
be the expensive part of a textfield. In all honesty I wouldn't bother
designing this as a gap buffer now. I would be inclined to implement
it on top of string16. The important thing is to design a flexible API
that doesn't lock down the implementation. Your design is incredibly
specific and so mostly locks you down to a particular implementation.
If you go with what I have suggested you'll have the flexibility to
change the underlying storage without impacting users of the API.

> I am very open to changing the api... but I would request you to take into
> consideration the various operations the user could perform on a textfield
> and
> then evaluate the API I have written.

If anything the API I am proposing is more efficient than what you are
proposing. With what I'm suggesting the buffer only changes when you
need it to, not when the cursor changes.

Here's similar APIs from other platforms:

Mac:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundat...
Swing:
http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/text/AbstractDoc...

  -Scott

> @Rob
> the API that I have written is pretty much the same as yours with the
> following
> differences:
> 1. Instead of moving based on the sign of the position I have two separate
> methods for moving left or right. I think it is more readable and cleaner
> this
> way but I can change it if you strongly feel about it.
> 2. I have two methods for moving the cursor (gap) to the first occurrence of
> a
> particular character (in either direction). These were added for handling
> Ctrl+<arrow-key>. In absence of these methods, the user will have to find
> the
> end/beginning of word and move the gap to it. This will require getting
> partial/all contents of the gap buffer creating unnecessary overhead.
> 3. For your InsertRune, I have 3 methods Insert(for inserting a character),
> RemoveFromGapStart(for inserting backspace) and RemoveFromGapEnd(for
> inserting
> delete). I can combine these into one if you like.
>
> I get the feeling that you guys dont like the "Gap" exposed in the API. Is
> it
> just a terminology issue? would it help if I called it "Cursor" in the
> method
> names?
>
> http://codereview.chromium.org/5158004/
>

Powered by Google App Engine
This is Rietveld 408576698