Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public bool Add(T item)
- {
- if (Contains(item))
- {
- return false;
- }
- int index = Math.Abs(item.GetHashCode() % this.listWithBuckets.Length);
- if (this.listWithBuckets[index]==null)
- {
- listWithBuckets[index] = new SingleLinkedList<T>();
- }
- SingleNode<T> newNnode = new SingleNode<T>(item);
- this.listWithBuckets[index].AddLast(newNnode.Value);
- this.Count++;
- if (this.Count + 1 / this.listWithBuckets.Length > LoadFactor)
- {
- SingleLinkedList<T>[] newHashSet = new SingleLinkedList<T>[2*listLength]; //initial cap?
- foreach (var singleLinkedList in this.listWithBuckets)
- {
- foreach (var node in singleLinkedList)
- {
- int newIndex = Math.Abs(node.GetHashCode() % this.listWithBuckets.Length);
- if (newHashSet[newIndex] != null)
- {
- newHashSet[newIndex].AddLast(node);
- }
- else
- {
- newHashSet[newIndex] = new SingleLinkedList<T>();
- newHashSet[newIndex].AddFirst(node);
- }
- }
- }
- listLength *= 2;
- this.listWithBuckets = newHashSet;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement