anchor.diff:      end.
   
   % @doc Transfer ownership of partition at Idx to Node.
  -% @spec transfer_node(Idx :: integer(), Node :: term(), MyState :: hstate()) ->
  -%           hstate()
  +% @spec transfer_node(Idx :: integer(), Node :: term(), MyState :: chstate()) ->
  +%           chstate()
   transfer_node(Idx, Node, MyState) ->
  -    case chash:lookup(Idx, MyState#hstate.ring) of
  +    case chash:lookup(Idx, MyState#chstate.chring) of
   	Node ->
   	    MyState;
   	_ ->
  -	    Me = MyState#hstate.nodename,
  -	    VClock = vclock:increment(Me, MyState#hstate.vclock),
  -	    Ring = chash:update(Idx, Node, MyState#hstate.ring),
  -	    #hstate{nodename=Me,vclock=VClock,ring=Ring,
  -                    meta=MyState#hstate.meta}
  +	    Me = MyState#chstate.nodename,
  +	    VClock = vclock:increment(Me, MyState#chstate.vclock),
  +	    CHRing = chash:update(Idx, Node, MyState#chstate.chring),
  +	    #chstate{nodename=Me,vclock=VClock,chring=CHRing,
  +                    meta=MyState#chstate.meta}
       end.
   
   ancestors(RingStates) ->
       Ancest = [[O2 || O2 <- RingStates,
  -     vclock:descends(O1#hstate.vclock,O2#hstate.vclock),
  -     (vclock:descends(O2#hstate.vclock,O1#hstate.vclock) == false)]
  +     vclock:descends(O1#chstate.vclock,O2#chstate.vclock),
  +     (vclock:descends(O2#chstate.vclock,O1#chstate.vclock) == false)]
   		|| O1 <- RingStates],
       lists:flatten(Ancest).
   
   % @doc Incorporate another node's state into our view of the Riak world.
  -% @spec reconcile(ExternState :: hstate(), MyState :: hstate()) ->
  -%       {no_change, hstate()} | {new_ring, hstate()}
  +% @spec reconcile(ExternState :: chstate(), MyState :: chstate()) ->
  +%       {no_change, chstate()} | {new_ring, chstate()}
   reconcile(ExternState, MyState) ->
  -    case vclock:equal(MyState#hstate.vclock, vclock:fresh()) of
  +    case vclock:equal(MyState#chstate.vclock, vclock:fresh()) of
           true -> 
  -            {new_ring, #hstate{nodename=MyState#hstate.nodename,
  -                               vclock=ExternState#hstate.vclock,
  -                               ring=ExternState#hstate.ring,
  -                               meta=ExternState#hstate.meta}};
  +            {new_ring, #chstate{nodename=MyState#chstate.nodename,
  +                                vclock=ExternState#chstate.vclock,
  +                                chring=ExternState#chstate.chring,
  +                                meta=ExternState#chstate.meta}};
           false ->
               case ancestors([ExternState, MyState]) of
                   [OlderState] ->
  -                    case vclock:equal(OlderState#hstate.vclock,
  -                                      MyState#hstate.vclock) of
  +                    case vclock:equal(OlderState#chstate.vclock,
  +                                      MyState#chstate.vclock) of
                           true ->
  -                            {new_ring, #hstate{nodename=MyState#hstate.nodename,
  -                                               vclock=ExternState#hstate.vclock,
  -                                               ring=ExternState#hstate.ring,
  -                                               meta=ExternState#hstate.meta}};
  +                            {new_ring,
  +                             #chstate{nodename=MyState#chstate.nodename,
  +                                      vclock=ExternState#chstate.vclock,
  +                                      chring=ExternState#chstate.chring,
  +                                      meta=ExternState#chstate.meta}};
                           false -> {no_change, MyState}
                       end;
                   [] -> 
                       case equal_rings(ExternState,MyState) of
                           true -> {no_change, MyState};
  -                        false -> {new_ring, reconcile(MyState#hstate.nodename,
  +                        false -> {new_ring, reconcile(MyState#chstate.nodename,
                                                         ExternState, MyState)}
                       end
               end
       end.
   
   % @private
  -equal_rings(_A=#hstate{ring=RA,meta=MA},_B=#hstate{ring=RB,meta=MB}) ->
  +equal_rings(_A=#chstate{chring=RA,meta=MA},_B=#chstate{chring=RB,meta=MB}) ->
       MDA = lists:sort(dict:to_list(MA)),
       MDB = lists:sort(dict:to_list(MB)),
       case MDA =:= MDB of
  
positive.code:     end.
  
  % @doc Return the node that owns the given index.
  % @spec index_owner(State :: hstate(), Idx :: integer()) -> Node :: term()
  index_owner(State, Idx) ->
      hd([Owner || {I, Owner} <- ?MODULE:all_owners(State), I =:= Idx]).
  
  % @doc Return the node that is responsible for a given hstate.
  % owner_node(State :: hstate()) -> Node :: term()
  owner_node(State) ->
      State#hstate.nodename.
  
  % @doc Produce a list of all nodes that own any partitions.
  % @spec all_members(State :: hstate()) -> [Node :: term()]
  all_members(State) ->
      chash:members(State#hstate.ring).
  
  % @doc Return a randomly-chosen node from amongst the owners.
  % @spec random_node(State :: hstate()) -> Node :: term()
  random_node(State) ->
      L = lists:usort(all_members(State)),
      lists:nth(crypto:rand_uniform(1, length(L)+1), L).
  
  % @doc Provide all ownership information in the form of {Index,Node} pairs.
  % @spec all_owners(State :: hstate()) -> [{Index :: integer(), Node :: term()}]
  all_owners(State) ->
      chash:nodes(State#hstate.ring).
  
  % @doc For two rings, return the list of owners that have differing ownership.
  % @spec diff_nodes(State1,State2) -> [node()]
  
negative.code:     {new_ring, C4} = reconcile(A3,C3),
      {new_ring, A4} = reconcile(C4,A3),
      {new_ring, B3} = reconcile(A4,B2),
      ?assertEqual(A4#chstate.chring, B3#chstate.chring),
      ?assertEqual(B3#chstate.chring, C4#chstate.chring).
  
  param_fresh_test() ->
      application:set_env(riak,ring_creation_size,4),
  