anchor.diff:  	 add_element/2,
   	 add_element/3,
   	 to_list/1,
  -	 fold/3]).
  +	 fold/3,
  +	fold/4]).
  +
  +
  +-export([test/0]).
   
   -compile(export_all).
   
  
positive.code:     Start = timestamp() - Sz,
      take_since(Buf2, Start, reverse(Buf1)).
  
  fold(_Fun, _Acc, #slide{size = Sz}) when Sz == 0 ->
      [];
  fold(Fun, Acc, #slide{size = Sz, buf1 = Buf1, buf2 = Buf2}) ->
      Start = timestamp() - Sz,
      lists:foldr(
        Fun, lists:foldl(Fun, Acc, take_since(Buf2, Start, [])), Buf1).
  
  take_since([{TS,_} = H|T], Start, Acc) when TS >= Start ->
      take_since(T, Start, [H|Acc]);
  
negative.code:     %% Don't reverse; already the wanted order.
      Acc.
  
      
  test() ->
      %% Create a slotted slide covering 2000 elements (ms), where
      S = new(2000),
  
      {T1, S1 }= timer:tc(?MODULE, build_histogram, [S]),
  
      {T2, _ } = timer:tc(?MODULE, calc_total, [S1]),
      io:format("Histogram creation: ~p~n", [ T1 ]),
      io:format("Tot calculation: ~p~n", [ T2 ]).
  
  build_histogram(S) ->
      %% Create 45000 events, Each millisecond, ten
      %% elements (1-10) will be created and installed
      %% in the histogram
      %% The 10 msec slot size means that each slot will calculate
      %% the average of 10 msec * 10 elements.
      lists:foldl(fun({TS,Elem}, Acc) ->
  			add_element(TS, Elem, Acc)
  		end, S, [{TS, Elem} || TS <- lists:seq(1,4500),
  				       Elem <- lists:seq(1,10)]).
  
  calc_total(S) ->
       fold(4500, fun({_TS, Elem}, Acc) -> Elem + Acc end, 0, S).
  
  