push_element/2 - efficient sliding window

Joel Reymont joelr1@REDACTED
Wed Aug 10 16:45:32 CEST 2005


Go Uffe!

Now I just need another BIF to slide a tuple of a fixed size over a  
large tuple. Then I would be happy :-). Say you have a tuple of  
1,000,000 items and I want to move a window of 100 items through it,  
shifting it from 1 to 100 then from 2 to 101 and so on.

For extra credit it should not copy data but return a "reference"  
which would indeed make it a "window".

     Joel

On Aug 10, 2005, at 4:23 PM, Ulf Wiger (AL/EAB) wrote:

> erlang:push_element(Tuple, Value) pushes value into position 1 of  
> Tuple, shifting the existing values one step to the right. This can  
> be used as a fixed-size sliding window which costs the same as  
> setelement/3 to update.

--
http://wagerlabs.com/uptick






More information about the erlang-questions mailing list