Holden Glova <dsafari / xtra.co.nz> writes:

> On Fri, 17 May 2002 22:45, Yohanes Santoso wrote:
> > The way I am implementing right now is:
> > 80000.downto(2) {|i| array[i+1]=array[i]}
> irb(main):023:0> array[0..0] + [2] + array[1..-1]
> [1, 2, 3, 4, 5]

Wow, this is cleaner and I don't see any difference in performance to
my approach. I'll choose your approach. Thanks!

> > 2. Anyone know of a Regex library that can operate over an array (either
> >    Ruby's Array or C's array (unsigned char*) ) with a gap?
> I'm not sure what you mean here.

Perhaps you know buffer gap by other name because I don't know the
appropriate term for this (I made up the term buffer gap). In text
editing, the most efficient, both in terms of space and computation,
model for storing the text is a buffer with a gap. A buffer is simply
a long sequential storage (array). If the text is put in a buffer
without a gap, insertion and deletion operations will be expensive
because of the constant element shifting.

So, a gap at the currently operated character is created. The gap is
set to, say 20-30 characters. So, insertion will simply consume the
gap and deletion will simply enlarge the gap. This strategy postpones
the shifting and the mapping from the underlying storage to what the
user sees is simple and fast. The gap takes advantage of the locality
behaviour of human editing.

But when asked to perform a regex search, the regex code must be able
to ignore the gap. Some text are to the left of the gap and some more
to the right. The regex code must be able to evaluate the whole text
as if the gap is not there. That's what I mean by a Regex library that
can operate over a gap, or on two disjointed memory ranges.

TIA,
YS.