/* =========================================================================== Copyright (C) 2000 - 2013, Raven Software, Inc. Copyright (C) 2001 - 2013, Activision, Inc. Copyright (C) 2013 - 2015, OpenJK contributors This file is part of the OpenJK source code. OpenJK is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see . =========================================================================== */ //////////////////////////////////////////////////////////////////////////////////////// // RAVEN STANDARD TEMPLATE LIBRARY // (c) 2002 Activision // // // Heap // ------ // // // // // TODO: // // // NOTES: // // //////////////////////////////////////////////////////////////////////////////////////// #if !defined(RATL_HEAP_VS_INC) #define RATL_HEAP_VS_INC //////////////////////////////////////////////////////////////////////////////////////// // Includes //////////////////////////////////////////////////////////////////////////////////////// #if !defined(RATL_COMMON_INC) #include "ratl_common.h" #endif namespace ratl { //////////////////////////////////////////////////////////////////////////////////////// // The Vector Class //////////////////////////////////////////////////////////////////////////////////////// template class heap_base : public ratl_base { public: typedef typename T TStorageTraits; typedef typename T::TValue TTValue; //////////////////////////////////////////////////////////////////////////////////// // Capacity Enum //////////////////////////////////////////////////////////////////////////////////// static const int CAPACITY = T::CAPACITY; //////////////////////////////////////////////////////////////////////////////////// // Data //////////////////////////////////////////////////////////////////////////////////// private: array_base mData; // The Memory int mPush; // Address Of Next Add Location //////////////////////////////////////////////////////////////////////////////////// // Returns The Location Of Node (i)'s Parent Node (The Parent Node Of Zero Is Zero) //////////////////////////////////////////////////////////////////////////////////// static int parent(int i) { return ((i-1)/2); } //////////////////////////////////////////////////////////////////////////////////// // Returns The Location Of Node (i)'s Left Child (The Child Of A Leaf Is The Leaf) //////////////////////////////////////////////////////////////////////////////////// static int left(int i) { return (2*i)+1; } //////////////////////////////////////////////////////////////////////////////////// // Returns The Location Of Node (i)'s Right Child (The Child Of A Leaf Is The Leaf) //////////////////////////////////////////////////////////////////////////////////// static int right(int i) { return (2*i)+2; } //////////////////////////////////////////////////////////////////////////////////// // Returns The Location Of Largest Child Of Node (i) //////////////////////////////////////////////////////////////////////////////////// int largest_child(int i) const { if (left(i)=0 && b>=0 && a0); // Don't Try To Look At This If There Is Nothing In Here return mData[0]; } //////////////////////////////////////////////////////////////////////////////////// // Add A Value To The Queue //////////////////////////////////////////////////////////////////////////////////// void push(const TTValue& nValue) { assert(size()0); mPush--; // Swap The Lowest Element Up To The Spot We Just "Erased" //--------------------------------------------------------- swap(0, mPush); mData.destruct(mPush); // Fix Possible Heap Inconsistancies //----------------------------------- reheapify_downward(0); assert(valid()); } }; template class heap_vs : public heap_base > { public: typedef typename storage::value_semantics TStorageTraits; typedef typename TStorageTraits::TValue TTValue; static const int CAPACITY = ARG_CAPACITY; heap_vs() {} }; template class heap_os : public heap_base > { public: typedef typename storage::object_semantics TStorageTraits; typedef typename TStorageTraits::TValue TTValue; static const int CAPACITY = ARG_CAPACITY; heap_os() {} }; template class heap_is : public heap_base > { public: typedef typename storage::virtual_semantics TStorageTraits; typedef typename TStorageTraits::TValue TTValue; static const int CAPACITY = ARG_CAPACITY; static const int MAX_CLASS_SIZE = ARG_MAX_CLASS_SIZE; heap_is() {} }; } #endif