/// <summary> /// O(1) | O(n) if collision | O(p) if passed priority greater than initial capacity. /// </summary> public HashedNode <T> Add(T @object, int priority) { if (priority < 0) { throw new ArgumentException("Priority must be a positive value!"); } var element = new HashedNode <T>(@object, priority); if (indexer.ContainsKey(element)) { throw new InvalidOperationException($"Element: {@object} already exist."); } if (priority > priorityGroups.Length - 1) { ReallocateMemory(priority + 1); } indexer.Add(element, priorityGroups[priority].AddLast(element)); Count++; if (current == null) { Reset(); } return(element); }
/// <summary> /// O(1) | O(n) if collision /// </summary> public void Remove(HashedNode <T> element) { if (!indexer.ContainsKey(element)) { throw new InvalidOperationException($"Element: {element.Value} does not exist."); } var linkedListNode = indexer[element]; priorityGroups[element.Priority].Remove(linkedListNode); indexer.Remove(element); Count--; }
/// <summary> /// O(1) | O(n) if collision /// </summary> public bool Contains(HashedNode <T> hashedNode) { return(indexer.ContainsKey(hashedNode)); }