push_element/2 - efficient sliding window

Richard A. O'Keefe <>
Fri Aug 12 04:44:34 CEST 2005


Suppose you want to maintain a sliding window of 20 elements,
with new elements coming in from the left.

initial_window(X) ->
    {X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X}.

add_to_window(X, {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T}) ->
    {X,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S}.

Do we really need built-in support for this?




More information about the erlang-questions mailing list