anchor.diff:  -include("record_helpers.hrl").
   
   -export([new/1]).
  --export([get_load/1, get_node/1, get_succ/1, get_items/1, get_time/1]).
  +-export([get_load/1, get_reqs/1, get_node/1, get_succ/1, get_items/1, get_time/1]).
   -export([is_succ/2, neighbors/2, get_target_load/3, get_target_load/5]).
   %% without dht size
   -export([get_load_change_slide/3, get_load_change_jump/4]).
  
positive.code: %% @doc The number of db entries the heavy node will give to the light node
  -spec get_target_load(Op::slide | jump, HeavyNode::lb_info(), LightNode::lb_info()) -> non_neg_integer().
  get_target_load(JumpOrSlide, HeavyNode, LightNode) ->
      case config:read(lb_active_metric) of
          items -> get_target_load(JumpOrSlide, HeavyNode, 1, LightNode, 1);
          _ -> get_target_load(JumpOrSlide, HeavyNode, get_load(HeavyNode), LightNode, get_load(LightNode))
      end.
  
  -define(BOUND(X,Y,Z), begin From = X, To = Z, V = Y,
                        if   V < From -> From;
                             V > To -> To;
                             true     -> V
                        end end).
  
  %% @doc The number of db entries the heavy node will give to the light node (weighted)
  -spec get_target_load(Op::slide | jump, HeavyNode::lb_info(), WeightHeavy::number(),
                                          LightNode::lb_info(), WeightLight::number())
                      -> non_neg_integer().
  get_target_load(slide, HeavyNode, WeightHeavy, LightNode, WeightLight) ->
      TotalItems = get_items(HeavyNode) + get_items(LightNode),
      AvgItems = TotalItems div 2,
      Factor = try WeightLight / WeightHeavy catch error:badarith -> 1 end,
      ItemsToShed = get_items(HeavyNode) - trunc(Factor * AvgItems),
      ?BOUND(0, ItemsToShed, get_items(HeavyNode));
  get_target_load(jump, HeavyNode, WeightHeavy, _LightNode, WeightLight) ->
      AvgItems = get_items(HeavyNode) div 2,
      Factor = try WeightLight / WeightHeavy catch error:badarith -> 1 end,
      ItemsToShed = get_items(HeavyNode) - trunc(Factor * AvgItems),
      ?BOUND(0, ItemsToShed, get_items(HeavyNode)).
  
  %% TODO generic load change
  %% @doc Calculates the change in Variance
  %% no dht size available
  -spec get_load_change_slide(TakenLoad::non_neg_integer(), HeavyNode::lb_info(), LightNode::lb_info()) -> LoadChange::integer().
  
negative.code: get_oldest_data_time([Node | Other], Oldest) ->
      OldestNew = erlang:min(get_time(Node), Oldest),
      get_oldest_data_time(Other, OldestNew).
  
  -spec bound(LowerBound::number(), Value::number(), UpperBound::number()) -> number().
  bound(LowerBound, Value, UpperBound) ->
      if Value < LowerBound -> LowerBound;
         Value > UpperBound -> UpperBound;
         true -> Value
      end.
  