Exemple #1
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="values"></param>
        /// <param name="distances"></param>
        /// <param name="comparer"></param>
        public FibonacciQueue(IEnumerable <TVertex> values, Func <TVertex, TDistance> distances, Func <TDistance, TDistance, int> comparer)
        {
            if (distances is null)
            {
                throw new ArgumentNullException(nameof(distances));
            }
            if (comparer is null)
            {
                throw new ArgumentNullException(nameof(comparer));
            }

            this.distances = distances;
            cells          = new Dictionary <TVertex, FibonacciHeapCell <TDistance, TVertex> >();
            heap           = new FibonacciHeap <TDistance, TVertex>(HeapDirection.Increasing, comparer);

            if (values != null)
            {
                foreach (var x in values)
                {
                    cells[x] = heap.Enqueue(this.distances(x), x);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="values"></param>
        /// <param name="comparer"></param>
        public FibonacciQueue(IDictionary <TVertex, TDistance> values, Func <TDistance, TDistance, int> comparer)
        {
            if (values is null)
            {
                throw new ArgumentNullException(nameof(values));
            }
            if (comparer == null)
            {
                throw new ArgumentNullException(nameof(comparer));
            }

            distances = GetIndexer(values);
            cells     = new Dictionary <TVertex, FibonacciHeapCell <TDistance, TVertex> >(values.Count);
            heap      = new FibonacciHeap <TDistance, TVertex>(HeapDirection.Increasing, comparer);

            if (values != null)
            {
                foreach (var kv in values)
                {
                    cells[kv.Key] = heap.Enqueue(kv.Value, kv.Key);
                }
            }
        }
Exemple #3
0
 public void Enqueue(TVertex value)
 {
     cells[value] = heap.Enqueue(distances(value), value);
 }