GapList – A Lightning-Fast List Implementation
java.dzone.com
java.dzone.com
For anyone interested in a C version, I wrote this a while ago, YMMV: https://github.com/jaimz/core_ds/blob/master/MxStringBuffer....
- _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; };
It's on github. Post a pull request or keep it to yourself. Especially as your comments are stylistic.
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.
(As one other reply has put it, "constructive criticism".
In this case, the great-grandparent is free to reflect upon the g.p response, or not, depending upon their inclination and time. Perhaps it sparks further refinement; perhaps not. But I don't see it as being personally critical; to reiterate, it offers a perspective of possible refinement.
In the past some months, I've noticed the tone of comments on HN becoming more "emotional". That, I believe, is a slippery slope for the community. HN seems to function best when we all exercise emotional restraint, along with our technical and professional enthusiasm.
With regard, and hopefully not "calling out" the parent too much (or at all) in what I have taken primarily as an opportunity to make a more general comment.
Edit: In fact, you must need the declaration to access the internals.
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:
GapList.get inlines everything, including the rangechecks. ArrayList has two calls to functions.
It might be due to caching, but even so it's going to depend on how big the data is. When the data's bigger than cache and the GapList is copying large amounts of data for every random insert, the O(1) linked-list insert is going to beat it.
Or maybe he's inserting to an indexed location, and counting the time required for the LinkedList to traverse to that location.