예제 #1
0
        /// <summary>
        /// Prints the heap statistics.
        /// </summary>
        public void PrintStats()
        {
            Stats.PrintStats();

            long totalAgesSum  = 0;
            int  oldestElement = 0;
            int  numberOfElementsGreaterThanExtractionLimit = 0;

            while (InternalHeap.GetSize() > 0)
            {
                var element = InternalHeap.RemoveMin();
                var age     = TimeStamp - element.TimeStamp;
                if (oldestElement < age)
                {
                    oldestElement = age;
                }
                totalAgesSum += age;

                if (element.Key > Stats.HighestExtractedElement)
                {
                    numberOfElementsGreaterThanExtractionLimit++;
                }
            }

            totalAgesSum += Stats.ExtractedElementsAgeTotalSum;
            Console.WriteLine("\t\tAverage element's age (all):\t" + totalAgesSum / (Stats.ElementsAges.Count + Stats.CurrentHeapSize));
            Console.WriteLine("\t\tOldest extracted:\t\t" + Stats.OldestExtractedElement);
            Console.WriteLine("\t\tOldest not extracted:\t\t" + oldestElement);
            Console.WriteLine("\t\tElements beyond extraction limit:\t" + numberOfElementsGreaterThanExtractionLimit);
        }
예제 #2
0
        /// <summary>
        /// Gets the value item with the minimal key and deletes the element from the collection.
        /// </summary>
        /// <returns>Value item with the minimal key.</returns>
        public Value RemoveMin()
        {
            var result = InternalHeap.RemoveMin();

            Logger?.WriteLine("r\t" + result.Key);
            Stats.UpdateAfterRemove(result);
            return(result.Value);
        }
예제 #3
0
        /// <summary>
        /// Adds a new key-value pair into the collection.
        /// </summary>
        /// <param name="key">Key item.</param>
        /// <param name="value">Value item.</param>
        public void Add(int key, Value value)
        {
            var newElement = new HeapNode(key, value, TimeStamp++);

            InternalHeap.Add(newElement.Key, newElement);

            Logger?.WriteLine("i\t" + key);
            Stats.UpdateAfterInsert(newElement);
        }
예제 #4
0
 /// <summary>
 /// Clears the collection.
 /// </summary>
 public void Clear()
 {
     InternalHeap.Clear();
     Stats.Clear();
     TimeStamp = 0;
 }
예제 #5
0
 /// <summary>
 /// Gets the size of the collection, i.e. number of included elements.
 /// </summary>
 /// <returns>Collection size.</returns>
 public int GetSize()
 {
     return(InternalHeap.GetSize());
 }
예제 #6
0
 /// <summary>
 /// Gets the minimal key of the collection.
 /// </summary>
 /// <returns>Minimal key.</returns>
 public int GetMinKey()
 {
     return((int)InternalHeap.GetMinKey());
 }