From: Yohanes Santoso Date: 2002-05-17T19:45:12+09:00 Subject: Shifting array element & regex on array element 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.