예제 #1
0
        public IndexedHeap(HeapMode mode, int size)
        {
            if (size < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(size));
            }

            switch (mode)
            {
            case HeapMode.MinHeap:
                this.heapifyBottomToTopMethod = this.HeapifyMinBottomToTop;
                this.heapifyTopToBottomMethod = this.HeapifyMinTopToBottom;
                break;

            case HeapMode.MaxHeap:
                this.heapifyBottomToTopMethod = this.HeapifyMaxBottomToTop;
                this.heapifyTopToBottomMethod = this.HeapifyMaxTopToBottom;
                break;

            default:
                throw new ArgumentException(nameof(mode));
            }

            // +1 because index zero is never used.
            this._array = new T[size + 1];
            this._index = new Dictionary <T, int>(size);
        }
 protected abstract IHeap <byte> CreateInstance(HeapMode mode, int initialSize);
 protected override IHeap <byte> CreateInstance(HeapMode mode, int initialSize)
 {
     return(new IndexedHeap <byte>(mode, initialSize));
 }