[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[FR-devel] Shifting array element & regex on array element
From: |
Yohanes Santoso |
Subject: |
[FR-devel] Shifting array element & regex on array element |
Date: |
17 May 2002 03:45:07 -0700 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 |
In implementing a buffer gap mechanism, I was wondering if there is
any efficient way to shift elements in an array.
Suppose that I have 80000 elements in an array. I would like to insert
a new element between the 1st and 2nd elements by making the 2nd
element be the 3rd and so on.
In C, the way to do this is to do bcopy/memmove or
something like while (--1 >= 0) *--to = *--from;
The way I am implementing right now is:
80000.downto(2) {|i| array[i+1]=array[i]}
1. Is this as efficient as it gets? It looks fast enough so far.
The next future of the buffer is that it supports regex. Ruby's
standard Regex class can't operate over array, especially array with a
gap.
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?
TIA,
YS.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [FR-devel] Shifting array element & regex on array element,
Yohanes Santoso <=