anchor.diff:      end;
     end;
   begin
  -  Result := False;
  -  kvp := InternalFind(key, KeySize, HashTrieNode, AChildIndex);
  -  if kvp = nil then
  -    exit;
  -  ParentNodePtr := @PHashTrieNodeArray(HashTrieNode^.Children)^[AChildIndex];
  -  Node := PHashTrieNodeArray(HashTrieNode^.Children)^[AChildIndex];
  -  if HashSize * 2 > 64 then
  -  begin
  -    CalcHash(TreeHash, key, KeySize, TREE_HASH_SEED, HashSize);
  -    Hash := TreeHash.Hash16;
  +  SmallestNode := nil;
  +  if Node^.Next <> nil then
  +  begin
  +    // There's more nodes with the same exact hash. We will pull up
  +    // the next node in the linked list of same exact hash nodes
  +    ParentNodePtr^ := Node^.Next;
  +    Node^.Next^.Left := Node^.Left;
  +    Node^.Next^.Right := Node^.Right;
     end
  -  else
  -  begin
  -    CalcHash(TreeHash, key, KeySize, TRIE_HASH_SEED, 64);
  -    Hash := TreeHash.Hash16_3;
  -  end;
  -  while Node <> nil do
  -  begin
  -    if (Hash = Node^.KVP.Hash) and
  -        CompareKeys(Node^.KVP.Key, Node^.KVP.KeySize, key, KeySize) then
  -      begin
  -        SmallestNode := nil;
  -        if Node^.Next <> nil then
  -        begin
  -          // There's more nodes with the same exact hash. We will pull up
  -          // the next node in the linked list of same exact hash nodes
  -          ParentNodePtr^ := Node^.Next;
  -          Node^.Next^.Left := Node^.Left;
  -          Node^.Next^.Right := Node^.Right;
  -        end
  -        else if (Node^.Left <> nil) and (Node^.Right <> nil) then
  -          FindSmallestNodeOnRight // Nodes left and right, find smallest node on right side
  -        // Following cases are the "easy" cases where only one node left or right
  -        // is connected to a subtree
  -        else if (Node^.Left = nil) and (Node^.Right <> nil) then
  -          ParentNodePtr^ := Node^.Right
  -        else if (Node^.Left <> nil) and (Node^.Right = nil) then
  -          ParentNodePtr^ := Node^.Left
  -        else if (Node^.Left = nil) and (Node^.Right = nil) then
  -          ParentNodePtr^ := nil; // Removing a terminal node with no linked list
  -        FreeKey(Node^.KVP.Key, Node^.KVP.KeySize);
  -        if Node^.KVP.Value <> nil then        
  -          FreeValue(Node^.KVP.Value);
  -        if SmallestNode <> nil then
  -        begin
  -          if SmallestNode <> Node^.Right then
  -          begin
  -            // When the smallest node is any other node than the one on the immediate
  -            // right of the one being removed, we will copy the contents of the smallest
  -            // node to the actual node being "removed", adjust some pointers and really
  -            // remove the smalles node
  -            SmallestNodeParent^.Left := SmallestNode^.Right;
  -            Node^.KVP := SmallestNode^.KVP;
  -            Node^.Next := SmallestNode^.Next;
  -            trieAllocators.DeAlloc(SmallestNode);
  -          end
  -          else
  -          begin
  -            // When the smallest node is the one on the immediate right, we will
  -            // connect the parent of the node being removed to the one on the immediate
  -            // right, connect this one to the whole left branch of the one being removed
  -            // and then dealloc the node being removed.
  -            // We can do this connection to the left pointer of the node to the right
  -            // because we know this node doesn't have any tree on its left by definition
  -            ParentNodePtr^ := Node^.Right;
  -            Assert(Node^.Right^.Left = nil, 'Node^.Right^.Left must be nil');
  -            Node^.Right^.Left := Node^.Left;
  -            trieAllocators.DeAlloc(Node);
  -          end;
  -        end
  -        else trieAllocators.DeAlloc(Node);
  -        Result := True;
  -        dec(FCount);
  -        exit;
  -      end;
  -    if Hash < Node^.KVP.Hash then
  -    begin
  -      ParentNodePtr := @Node^.Left;
  -      Node := Node^.Left;
  -    end
  -    else if Hash > Node^.KVP.Hash then
  -    begin
  -      ParentNodePtr := @Node^.Right;
  -      Node := Node^.Right;
  +  else if (Node^.Left <> nil) and (Node^.Right <> nil) then
  +    FindSmallestNodeOnRight // Nodes left and right, find smallest node on right side
  +  // Following cases are the "easy" cases where only one node left or right
  +  // is connected to a subtree
  +  else if (Node^.Left = nil) and (Node^.Right <> nil) then
  +    ParentNodePtr^ := Node^.Right
  +  else if (Node^.Left <> nil) and (Node^.Right = nil) then
  +    ParentNodePtr^ := Node^.Left
  +  else if (Node^.Left = nil) and (Node^.Right = nil) then
  +    ParentNodePtr^ := nil; // Removing a terminal node with no linked list
  +  FreeKey(Node^.KVP.Key, Node^.KVP.KeySize);
  +  if Node^.KVP.Value <> nil then
  +    FreeValue(Node^.KVP.Value);
  +  if SmallestNode <> nil then
  +  begin
  +    if SmallestNode <> Node^.Right then
  +    begin
  +      // When the smallest node is any other node than the one on the immediate
  +      // right of the one being removed, we will copy the contents of the smallest
  +      // node to the actual node being "removed", adjust some pointers and really
  +      // remove the smalles node
  +      SmallestNodeParent^.Left := SmallestNode^.Right;
  +      Node^.KVP := SmallestNode^.KVP;
  +      Node^.Next := SmallestNode^.Next;
  +      trieAllocators.DeAlloc(SmallestNode);
       end
       else
       begin
  -      ParentNodePtr := @Node^.Next;
  -      Node := Node^.Next;
  -      Assert(Node^.Left = nil, 'Node linked list present. Node^.Left must be nil');
  -      Assert(Node^.Right = nil, 'Node linked list present. Node^.Right must be nil');
  -    end;
  -  end;
  -end;
  -
  -procedure THashTrie.InitIterator(out AIterator: THashTrieIterator);
  -begin
  -  FContainer.InitIterator(AIterator.Base);
  -  AIterator.BackTrack := nil;
  -end;
  -
  -procedure THashTrie.NewBacktrackNode(var AIterator: THashTrieIterator; Node:
  -    PKeyValuePairNode; NextMove: TIteratorMovement);
  -var
  -  BacktrackNode : PKeyValuePairBacktrackNode;
  -begin
  -  BacktrackNode := FKeyValuePairBacktrackNodeAllocator.Alloc;
  -  BacktrackNode^.Node := Node;
  -  BacktrackNode^.Next := AIterator.BackTrack;
  -  if AIterator.Backtrack <> nil then
  -    AIterator.Backtrack^.NextMove := NextMove;
  -  AIterator.BackTrack := BacktrackNode;
  -  BacktrackNode^.NextMove := imLeft;
  -end;
  -
  -function THashTrie.NewKVPNode(const kvp: TKeyValuePair): PKeyValuePairNode;
  -begin
  -  Result := FKeyValuePairNodeAllocator.Alloc;
  -  Result^.KVP := kvp;
  -  Result^.Left := nil;
  -  Result^.Right := nil;
  -  Result^.Next := nil;
  -end;
  -
  -procedure THashTrie.Pack;
  -label
  -  ContinueOuterLoopIteration;
  -var
  -  It : THashTrieIterator;
  -  i, AChildIndex : byte;
  -  Node : PHashTrieNode;
  -begin
  -  FContainer.InitIterator(It.Base);
  -  while FContainer.Next(It.Base) do
  -  begin
  -    Node := FContainer.GetObjectFromIterator(It.Base);
  -    for i := 0 to ChildrenPerBucket - 1 do
  -    begin
  -      if GetBusyIndicator(@Node^.Base, i) then
  -      begin
  -         AChildIndex := GetChildIndex(PTrieBranchNode(Node), i);
  -         if PHashTrieNodeArray(Node^.Children)^[AChildIndex] <> nil then
  -           goto ContinueOuterLoopIteration;
  -      end;
  -    end;
  -    Node^.Base.Busy := NOT_BUSY; // We mark the record as not busy anymore, will be collected by FContainer.Pack()
  -ContinueOuterLoopIteration:
  -  end;
  -  FContainer.Pack;
  -end;
  -
  -function THashTrie.Next(var AIterator: THashTrieIterator): PKeyValuePair;
  -var
  -  AChildIndex, ABitFieldIndex : Byte;
  -  Node : PTrieBranchNode;
  -  KVPNode : PKeyValuePairNode;
  -begin
  -  if AIterator.BackTrack <> nil then
  -  begin
  -    KVPNode := AIterator.BackTrack^.Node;
  -    Result := @KVPNode^.KVP;
  -    NextLeafTreeNode(AIterator);
  -    exit;
  -  end;
  -  while FContainer.Next(AIterator.Base) do
  -  begin
  -    ABitFieldIndex := GetBitFieldIndex(AIterator.Base.LastResult64, TrieDepth - 1);
  -    Node := FContainer.GetObjectFromIterator(AIterator.Base);
  -    AChildIndex := GetChildIndex(Node, ABitFieldIndex);
  -    KVPNode := PHashTrieNodeArray(Node^.Children)^[AChildIndex];
  -    if KVPNode = nil then
  -      continue;
  -    Result := @KVPNode^.KVP;
  -    NewBacktrackNode(AIterator, KVPNode, imLeft);
  -    NextLeafTreeNode(AIterator);
  -    exit;
  -  end;
  -  Result := nil;
  -end;
  -
  -procedure THashTrie.NextLeafTreeNode(var AIterator: THashTrieIterator;
  -    AFreeNodes: Boolean = False);
  -var
  -  BacktrackNode : PKeyValuePairBacktrackNode;
  -  procedure MoveUp;
  -  var
  -    kvp : PKeyValuePair;
  -  begin
  -    if AFreeNodes then
  -    begin
  -      kvp := @AIterator.BackTrack^.Node^.KVP;
  -      FreeKey(kvp^.Key, kvp^.KeySize);
  -      if kvp^.Value <> nil then      
  -        FreeValue(kvp^.Value);
  -      trieAllocators.DeAlloc(AIterator.BackTrack^.Node);
  -    end;
  -    BacktrackNode := AIterator.BackTrack;
  -    AIterator.BackTrack := BacktrackNode^.Next;
  -    trieAllocators.Dealloc(BacktrackNode);
  -  end;
  -begin
  -  while AIterator.BackTrack <> nil do
  -    begin
  -      case AIterator.BackTrack^.NextMove of
  -        imLeft : if AIterator.BackTrack^.Node^.Left <> nil then
  -        begin
  -          NewBacktrackNode(AIterator, AIterator.BackTrack^.Node^.Left, imNext);
  -          exit;
  -        end
  -        else
  -        begin
  -          inc(AIterator.BackTrack^.NextMove);
  -          continue;
  -        end;
  -        imNext : if AIterator.BackTrack^.Node^.Next <> nil then
  -        begin
  -          NewBacktrackNode(AIterator, AIterator.BackTrack^.Node^.Next, imRight);
  -          exit;
  -        end
  -        else
  -        begin
  -          inc(AIterator.BackTrack^.NextMove);
  -          continue;
  -        end;
  -        imRight : if AIterator.BackTrack^.Node^.Right <> nil then
  -        begin
  -          NewBacktrackNode(AIterator, AIterator.BackTrack^.Node^.Right, imUp);
  -          exit;
  -        end
  -        else MoveUp;
  -        imUp : MoveUp;
  -      end;
  -    end;
  +      // When the smallest node is the one on the immediate right, we will
  +      // connect the parent of the node being removed to the one on the immediate
  +      // right, connect this one to the whole left branch of the one being removed
  +      // and then dealloc the node being removed.
  +      // We can do this connection to the left pointer of the node to the right
  +      // because we know this node doesn't have any tree on its left by definition
  +      ParentNodePtr^ := Node^.Right;
  +      Assert(Node^.Right^.Left = nil, 'Node^.Right^.Left must be nil');
  +      Node^.Right^.Left := Node^.Left;
  +      {$IFDEF DEBUG}
  +      InvalidateKVPNode(Node);
  +      {$ENDIF}
  +      trieAllocators.DeAlloc(Node);
  +    end;
  +  end
  +  else trieAllocators.DeAlloc(Node);
  +  dec(FCount);
   end;
   
   end.
  
positive.code:     Right : PKeyValuePairNode;
    end;
  
    TIteratorMovement = (imLeft, imNext, imRight, imUp);
    PKeyValuePairBacktrackNode = ^TKeyValuePairBacktrackNode;
    TKeyValuePairBacktrackNode = record
      Node : PKeyValuePairNode;
  
negative.code:     case FAutoFreeValueMode of
        afmFree             : TObject(value).Free;
        afmFreeMem          : FreeMem(value);
        afmAnsiStrDispose   : {$IFDEF UNICODE}AnsiStrings.{$ENDIF}StrDispose(PAnsiChar(value));
        afmReleaseInterface : IUnknown(Value)._Release;
      end;
  end;
  