コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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--;
        }
コード例 #3
0
 /// <summary>
 /// O(1) | O(n) if collision
 /// </summary>
 public bool Contains(HashedNode <T> hashedNode)
 {
     return(indexer.ContainsKey(hashedNode));
 }