
GapList – A Lightning-Fast List Implementation - saurabh
http://java.dzone.com/articles/gaplist-lightning-fast-list
======
jaimzob
This is often how text buffers are implemented in editors. Since most text
edits are contiguous, the gap means you don't keep shuffling memory around
with each insertion and therefore it's extremely fast. I think it dates back
to a pretty early version of emacs, maybe even before.

For anyone interested in a C version, I wrote this a while ago, YMMV:
[https://github.com/jaimz/core_ds/blob/master/MxStringBuffer....](https://github.com/jaimz/core_ds/blob/master/MxStringBuffer.h)

~~~
ExpiredLink
Some stylistic remarks:

\- _MxStringBuffer need not be defined in the header, a forward declaration
would be sufficient (a.k.a. encapsulation).

\- the two #defines can be removed form the header, too.

\- I wouldn't try to typedef away a pointer (as in typedef struct
_MxStringBuffer * MxStringBufferRef) but either use the pointer
(MxStringBuffer* ) or create a handle: struct MxHandleStringBuffer {
_MxStringBuffer * impl; };

~~~
gravitronic
Pretty jerk response to someone sharing something for free.

It's on github. Post a pull request or keep it to yourself. Especially as your
comments are stylistic.

~~~
dpark
Why is it a jerk response? He took the time to look at the code and offer
suggestions. That hardly seems like a negative thing.

~~~
gravitronic
If I was sharing code and the response I got was "you should dot your i's and
cross your t's" instead of "thanks for providing functional code for free" it
would make me reconsider sharing more in the future.

~~~
jaimzob
Meh. I'm sure his comment was well-intentioned: If you spend most of your time
communicating with computers then your communication with humans can sometimes
tend toward the 'abrupt', after this long in the industry I'm pretty used to
it.

~~~
ExpiredLink
> Meh. I'm sure his comment was well-intentioned

I'm surprised about the possibility of misunderstanding.

BTW, the code is 'open source' and copyrighted: I have found no license to use
it freely.

------
fendrak
This appears to me to be an implementation of a gap buffer:

<http://en.wikipedia.org/wiki/Gap_buffer>

I actually just implemented one in Python on top of the array module, planning
to use it in a text editor:

<https://github.com/jasontbradshaw/gapbuffer>

------
rollypolly
I wonder how the GapList performance compares to unrolled linked lists.

<http://en.wikipedia.org/wiki/Unrolled_linked_list>

------
Leszek
I find it odd that "get" is faster on a GapList than an ArrayList. Surely
"get" on an ArrayList should be unbeatable.

~~~
Tuna-Fish
from GapList.java:get // A note about the inlining capabilities of the Java
HotSpot Performance Engine //
([http://java.sun.com/developer/technicalArticles/Networking/H...](http://java.sun.com/developer/technicalArticles/Networking/HotSpot/inlining.html))
// The JVM seems not able to inline the methods called within // this method,
irrespective whether they are "private final" or not. // Also
-XX:+AggressiveOpts seems not to help. // We therefore do inlining manually.

GapList.get inlines everything, including the rangechecks. ArrayList has two
calls to functions.

~~~
_casperc
Out of curiosity, how do you go about finding out if your code is inlined or
not?

