anchor.diff:  -author({ "David J Goehrig", "dave@dloh.org" }).
   -copyright(<<"© 2016 David J Goehrig"/utf8>>).
   -behavior(gen_server).
  --export([ start_link/0, stop/0, log/2, dump/0 ]).
  +-export([ start_link/0, stop/0, log/2, dump/0, allot/2, clear/1 ]).
   -export([ code_change/3, handle_call/3, handle_cast/2, handle_info/2, init/1,
   	terminate/2 ]).
   
  --record(stats, { windows, size }).
  +-record(stats, { windows, sizes }).
   
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   % Public APU
  
positive.code: stop() ->
  	gen_server:call(?MODULE,stop).
  
  log(Stat,Value) ->
  	gen_server:call(?MODULE, { log, Stat, Value }).
  
  dump() ->
  	gen_server:call(?MODULE, dump).
  
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % Private APU
  %
  
  init([]) ->
  	{ ok, #stats{ windows = [], size = 10 }}.
  
  handle_call(stop,_From,Stats) ->
  	{ stop, stopped, Stats };
  
negative.code: 
  terminate(_Reason,_Stats) ->
  	ok.
  
  populate(Size) ->
  	[ 0 || _X <- lists:seq(1,Size) ].
  
  allocate(Stats = #stats{ windows = Windows, sizes = Sizes },Stat,Size) ->
  	Stats#stats{
  		windows = [ { Stat, populate(Size) } | proplists:delete(Stat,Windows) ],
  		sizes = [ { Stat, Size } | proplists:delete(Stat,Sizes) ]
  	}.
  
  rotate(Stats = #stats{ windows = Windows }, Stat, Value) ->
  	case proplists:lookup(Stat,Windows) of 
  		{ Stat, Values } -> [ _H | T ] = Values;
  		none -> T = []	%% assume we are only tracking a single value
  	end,	
  	Stats#stats{ windows = [ { Stat, T ++ [Value] } | proplists:delete(Stat,Windows) ]}.
  
  reset(Stats = #stats{ windows = Windows, sizes = Sizes }, Stat) ->
  	case proplists:lookup(Stat,Sizes) of
  		{ Stat, Size } -> Window = populate(Size);
  		none -> Window = [0]
  	end,
  	Stats#stats{ windows =  [ { Stat, Window } | proplists:delete(Stat,Windows) ]}.
  
  
  