anchor.diff:  -include("antidote.hrl").
   -include_lib("riak_core/include/riak_core_vnode.hrl").
   
  -
  +%% Number of snapshots to trigger GC
   -define(SNAPSHOT_THRESHOLD, 10).
  +%% Number of snapshots to keep after GC
   -define(SNAPSHOT_MIN, 3).
  +%% Number of ops to keep before GC
   -define(OPS_THRESHOLD, 50).
  +%% The first 3 elements in operations list are meta-data
  +%% First is the key
  +%% Second is a tuple {current op list size, max op list size}
  +%% Thrid is a counter that assigns each op 1 larger than the previous
  +%% Fourth is where the list of ops start
   -define(FIRST_OP, 4).
  +%% If after the op GC there are only this many or less spaces
  +%% free in the op list then increase the list size
  +-define(RESIZE_THRESHOLD, 5).
   
   -ifdef(TEST).
   -include_lib("eunit/include/eunit.hrl").
  
positive.code: -spec tuple_to_key(tuple()) -> {any(),non_neg_integer(),non_neg_integer(),list()}.
  tuple_to_key(Tuple) ->
      Key = element(1, Tuple),
      Length = element(2, Tuple),
      OpId = element(3, Tuple),
      Ops = tuple_to_key_int(?FIRST_OP,Length+?FIRST_OP,Tuple,[]),
      {Key,Length,OpId,Ops}.
  tuple_to_key_int(Next,Next,_Tuple,Acc) ->
      Acc;
  tuple_to_key_int(Next,Last,Tuple,Acc) ->
  
negative.code: 	    CommitTime = lists:foldl(fun({CT1,_ST}, Acc) ->
  					     vectorclock:min([CT1, Acc])
  				     end, CT, vector_orddict:to_list(PrunedSnapshots)),
  	    {Key,Length,OpId,ListLen,OpsDict} = case ets:lookup(OpsCache, Key) of
  						    [] ->
  							{Key, 0, 0, 0, []};
  						    [Tuple] ->
  							tuple_to_key(Tuple)
  						end,
              {NewLength,PrunedOps}=prune_ops({Length,OpsDict}, CommitTime),
              ets:insert(SnapshotCache, {Key, PrunedSnapshots}),
  	    %% Check if the pruned ops are lager or smaller than the minimum list size
  	    %% if so create a larger or smaller list (by dividing or multiplying by 2)
  	    NewListLen = case Length - ?RESIZE_THRESHOLD > ListLen of
  			     true ->
  				 Length * 2;
  			     false ->
  				 case ListLen =< ?OPS_THRESHOLD of
  				     true ->
  					 ?OPS_THRESHOLD;
  				     false ->
  					 HalfListLen = ListLen div 2,
  					 case HalfListLen - ?RESIZE_THRESHOLD > Length of
  					     true ->
  						 HalfListLen;
  					     false ->
  						 ListLen
  					 end
  				 end
  			 end,
  	    true = ets:insert(OpsCache, erlang:make_tuple(?FIRST_OP+NewListLen,0,[{1,Key},{2,{NewLength,NewListLen}},{3,OpId}|PrunedOps]));
          false ->
              true = ets:insert(SnapshotCache, {Key, SnapshotDict})
      end.
  