PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: BinominalHeapIterator.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLCORE_CONTAINER_BINOMINALHEAPITERATOR_H__ 00024 #define __PLCORE_CONTAINER_BINOMINALHEAPITERATOR_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLCore/Container/Stack.h" 00032 #include "PLCore/Container/IteratorImpl.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLCore { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Forward declarations ] 00043 //[-------------------------------------------------------] 00044 template <class KeyType, class ValueType, class Comparer> class BinominalHeap; 00045 00046 00047 //[-------------------------------------------------------] 00048 //[ Classes ] 00049 //[-------------------------------------------------------] 00050 /** 00051 * @brief 00052 * Binominal heap iterator class 00053 */ 00054 template <class KeyType, class ValueType, class Comparer> 00055 class BinominalHeapIterator : public IteratorImpl<ValueType> { 00056 00057 00058 //[-------------------------------------------------------] 00059 //[ Friends ] 00060 //[-------------------------------------------------------] 00061 friend class BinominalHeap<KeyType, ValueType, Comparer>; 00062 00063 00064 //[-------------------------------------------------------] 00065 //[ Private functions ] 00066 //[-------------------------------------------------------] 00067 private: 00068 /** 00069 * @brief 00070 * Constructor 00071 * 00072 * @param[in] cHeapOwner 00073 * Binominal heap to operate on 00074 * @param[in] nIndex 00075 * Start index, if >= GetNumOfElements() the index is set to the last valid index 00076 */ 00077 BinominalHeapIterator(const BinominalHeap<KeyType, ValueType, Comparer> &cHeapOwner, uint32 nIndex); 00078 00079 /** 00080 * @brief 00081 * Constructor 00082 * 00083 * @param[in] cHeapOwner 00084 * Binominal heap to operate on 00085 * 00086 * @note 00087 * - The iterator will start at the last element 00088 */ 00089 BinominalHeapIterator(const BinominalHeap<KeyType, ValueType, Comparer> &cHeapOwner); 00090 00091 /** 00092 * @brief 00093 * Copy constructor 00094 * 00095 * @param[in] cSource 00096 * Source to copy from 00097 */ 00098 BinominalHeapIterator(const BinominalHeapIterator<KeyType, ValueType, Comparer> &cSource); 00099 00100 /** 00101 * @brief 00102 * Destructor 00103 */ 00104 virtual ~BinominalHeapIterator(); 00105 00106 /** 00107 * @brief 00108 * Returns the previous sibling of the given tree 00109 * 00110 * @param[in] pTree 00111 * Tree to return the previous sibling from, can be a null pointer 00112 * 00113 * @return 00114 * Previous sibling tree of the given one, a null pointer of there's no previous sibling tree 00115 * 00116 * @note 00117 * - Because the binominal heap provides no information about the previous sibling tree, we 00118 * have to find out the previous sibling tree by yourself (not that performant :) 00119 */ 00120 typename BinominalHeap<KeyType, ValueType, Comparer>::Tree *GetPreviousSibling(typename BinominalHeap<KeyType, ValueType, Comparer>::Tree *pTree) const; 00121 00122 00123 //[-------------------------------------------------------] 00124 //[ Private data ] 00125 //[-------------------------------------------------------] 00126 private: 00127 const BinominalHeap<KeyType, ValueType, Comparer> *m_pHeapOwner; /**< Binominal heap to operate on (always valid!) */ 00128 Stack<typename BinominalHeap<KeyType, ValueType, Comparer>::Tree*> m_lstParent; /**< Parent stack */ 00129 typename BinominalHeap<KeyType, ValueType, Comparer>::Tree *m_pNextTree; /**< Next tree, can be a null pointer */ 00130 typename BinominalHeap<KeyType, ValueType, Comparer>::Tree *m_pPreviousTree; /**< Previous tree, can be a null pointer */ 00131 00132 00133 //[-------------------------------------------------------] 00134 //[ Private virtual IteratorImpl functions ] 00135 //[-------------------------------------------------------] 00136 private: 00137 virtual IteratorImpl<ValueType> *Clone() const override; 00138 virtual bool HasNext() const override; 00139 virtual ValueType &Next() override; 00140 virtual bool HasPrevious() const override; 00141 virtual ValueType &Previous() override; 00142 00143 00144 }; 00145 00146 00147 //[-------------------------------------------------------] 00148 //[ Namespace ] 00149 //[-------------------------------------------------------] 00150 } // PLCore 00151 00152 00153 //[-------------------------------------------------------] 00154 //[ Implementation ] 00155 //[-------------------------------------------------------] 00156 #include "PLCore/Container/BinominalHeapIterator.inl" 00157 00158 00159 #endif // __PLCORE_CONTAINER_BINOMINALHEAPITERATOR_H__
|