public Node(int pos) { key = Nil.Instance; val = Nil.Instance; next = null; position = pos; }
public void Copy(Node c) { key = c.key; val = c.val; next = c.next; }
void Resize(int nasize, int nhsize) { int i; int oldasize = this.sizeArray; int oldhsize = this.logSizeNode; Node[] nold; Node[] temp = new Node[] { new Node(0) }; if(oldhsize != 0) nold = this.node; /* save old hash ... */ else { /* old hash is `dummynode' */ temp[0].key = this.node[0].key; /* copy it to `temp' */ temp[0].val = this.node[0].val; temp[0].next = this.node[0].next; nold = temp; Node.DummyNode.key = Nil.Instance; /* restate invariant */ Node.DummyNode.val = Nil.Instance; Node.DummyNode.next = null; } if (nasize > oldasize) /* array part must grow? */ SetArrayVector(nasize); /* create new hash part with appropriate size */ SetNodeVector(nhsize); /* re-insert elements */ if (nasize < oldasize) { /* array part must shrink? */ this.sizeArray = nasize; /* re-insert elements from vanishing slice */ for (i = nasize; i < oldasize; i++) { if (this.array[i].val != Nil.Instance) SetNum(i+1, this.array[i].val); } /* shrink array */ Node[] newarr = new Node[nasize]; for(i=0; i < newarr.Length; i++) newarr[i] = this.array[i]; this.array = newarr; } /* re-insert elements in hash part */ for (i = (1 << oldhsize) - 1; i >= 0; i--) { Node old = nold[i]; if (old.val != Nil.Instance) { Set(old.key, old.val); } } }
void SetArrayVector(int size) { Node[] newArr=new Node[size]; for(int i = 0; i < this.sizeArray; i++) newArr[i] = this.array[i]; for(int i = this.sizeArray; i < newArr.Length; i++) newArr[i] = new Node(i); this.array = newArr; this.sizeArray = size; }