Exemplo n.º 1
0
 public INode assoc(int shift, int hash, object key, object val, Box addedLeaf)
 {
     if (hash == _hash)
     {
         if (Util.equals(key, _key))
         {
             if (val == _val)
             {
                 return(this);
             }
             // note - do not set AddedLeaf, since we are replacing
             else
             {
                 return(new LeafNode(hash, key, val));
             }
         }
         else
         {
             // hash collision, same hash, different keys
             LeafNode newLeaf = new LeafNode(hash, key, val);
             addedLeaf.Val = newLeaf;
             return(new HashCollisionNode(hash, this, newLeaf));
         }
     }
     else
     {
         return(BitmapIndexedNode.create(shift, this, hash, key, val, addedLeaf));
     }
 }
Exemplo n.º 2
0
 public INode assoc(int shift, int hash, object key, object val, Box addedLeaf)
 {
     if (_hash == hash)
     {
         int idx = findIndex(hash, key);
         if (idx != -1)
         {
             if (_leaves[idx].val() == val)
             {
                 return(this);
             }
             LeafNode[] newLeaves1 = (LeafNode[])_leaves.Clone();
             // Note: do not set addedLeaf, since we are replacing
             newLeaves1[idx] = new LeafNode(hash, key, val);
             return(new HashCollisionNode(hash, newLeaves1));
         }
         LeafNode[] newLeaves = new LeafNode[_leaves.Length + 1];
         Array.Copy(_leaves, 0, newLeaves, 0, _leaves.Length);
         addedLeaf.Val = newLeaves[_leaves.Length] = new LeafNode(hash, key, val);
         return(new HashCollisionNode(hash, newLeaves));
     }
     return(BitmapIndexedNode.create(shift, this, hash, key, val, addedLeaf));
 }