BWAPI
|
#include <Heap.h>
Public Member Functions | |
Heap (bool isMinHeap=false) | |
void | push (const std::pair< Key, Val > &val) |
void | pop () |
const std::pair< Key, Val > & | top () const |
bool | empty () const |
bool | set (const Key &key, const Val &val) |
const Val & | get (const Key &key) const |
bool | contains (const Key &key) const |
int | size () const |
void | clear () |
bool | erase (const Key &key) |
Private Member Functions | |
int | percolate_up (int index) |
int | percolate_down (int index) |
Private Attributes | |
std::vector< std::pair< Key, Val > > | mData |
std::map< Key, int > | mMapping |
bool | mIsMinHeap |
Definition at line 9 of file Heap.h.
: mIsMinHeap(isMinHeap) {}
Definition at line 91 of file Heap.h.
References Heap< Key, Val >::mData, and Heap< Key, Val >::mMapping.
Referenced by Heap< Key, Val >::erase().
Definition at line 80 of file Heap.h.
References Heap< Key, Val >::mMapping.
Definition at line 46 of file Heap.h.
References Heap< Key, Val >::mData.
Referenced by TerrainAnaysisClass::calculateWalkTileClearance(), PathFinderClass::CreateRegionPath(), TerrainAnaysisClass::createRegions(), PathFinderClass::CreateTilePath(), PathFinderClass::CreateWalkPath(), and MapHelper::walkSearch().
{ return mData.empty(); }
Definition at line 97 of file Heap.h.
References Heap< Key, Val >::clear(), Heap< Key, Val >::mData, Heap< Key, Val >::mMapping, and Heap< Key, Val >::percolate_down().
Referenced by TerrainAnaysisClass::createRegions().
{ std::map<Key, int>::iterator it = mMapping.find(key); if(it == mMapping.end()) return false; if(mData.size() == 1) clear(); else { int index = it->second; mData[index] = mData.back(); mData.pop_back(); mMapping.erase(it); percolate_down(index); } return true; }
Definition at line 73 of file Heap.h.
References Heap< Key, Val >::mData, and Heap< Key, Val >::mMapping.
int Heap< Key, Val >::percolate_down | ( | int | index | ) | [inline, private] |
Definition at line 142 of file Heap.h.
References Heap< Key, Val >::mData, Heap< Key, Val >::mIsMinHeap, and Heap< Key, Val >::mMapping.
Referenced by Heap< Key, Val >::erase(), Heap< Key, Val >::pop(), and Heap< Key, Val >::set().
{ if(index < 0 || index >= (int)mData.size()) return -1; unsigned int lchild = index * 2 + 1; unsigned int rchild = index * 2 + 2; unsigned int mchild; int m = mIsMinHeap ? -1 : 1; while((mData.size() > lchild && m * mData[index].second < m * mData[lchild].second) || (mData.size() > rchild && m * mData[index].second < m * mData[rchild].second)) { mchild = lchild; if(mData.size() > rchild && m * mData[rchild].second > m * mData[lchild].second) mchild = rchild; std::swap(mData[mchild], mData[index]); mMapping.find(mData[index].first)->second = index; index = mchild; lchild = index * 2 + 1; rchild = index * 2 + 2; } mMapping.find(mData[index].first)->second = index; return index; }
int Heap< Key, Val >::percolate_up | ( | int | index | ) | [inline, private] |
Definition at line 122 of file Heap.h.
References Heap< Key, Val >::mData, Heap< Key, Val >::mIsMinHeap, and Heap< Key, Val >::mMapping.
Referenced by Heap< Key, Val >::push(), and Heap< Key, Val >::set().
{ if(index < 0 || index >= (int)mData.size()) return -1; unsigned int parent = (index - 1) / 2; int m = mIsMinHeap ? -1 : 1; while(index > 0 && m * mData[parent].second < m * mData[index].second) { std::swap(mData[parent], mData[index]); mMapping.find(mData[index].first)->second = index; index = parent; parent = (index - 1) / 2; } mMapping.find(mData[index].first)->second = index; return index; }
Definition at line 21 of file Heap.h.
References Heap< Key, Val >::mData, Heap< Key, Val >::mMapping, and Heap< Key, Val >::percolate_down().
Referenced by TerrainAnaysisClass::calculateWalkTileClearance(), PathFinderClass::CreateRegionPath(), TerrainAnaysisClass::createRegions(), PathFinderClass::CreateTilePath(), PathFinderClass::CreateWalkPath(), and MapHelper::walkSearch().
{ if(mData.empty()) return; mMapping.erase(mData.front().first); mData.front() = mData.back(); mData.pop_back(); if(mData.empty()) return; std::map<Key, int>::iterator it = mMapping.find(mData.front().first); if(it != mMapping.end()) { it->second = 0; percolate_down(0); } }
void Heap< Key, Val >::push | ( | const std::pair< Key, Val > & | val | ) | [inline] |
Definition at line 11 of file Heap.h.
References Heap< Key, Val >::mData, Heap< Key, Val >::mMapping, and Heap< Key, Val >::percolate_up().
Referenced by PathFinderClass::CreateRegionPath(), PathFinderClass::CreateTilePath(), PathFinderClass::CreateWalkPath(), Heap< Key, Val >::set(), and MapHelper::walkSearch().
{ int index = mData.size(); if(mMapping.insert(std::make_pair(val.first, index)).second) { mData.push_back(val); percolate_up(index); } }
bool Heap< Key, Val >::set | ( | const Key & | key, |
const Val & | val | ||
) | [inline] |
Definition at line 51 of file Heap.h.
References Heap< Key, Val >::mData, Heap< Key, Val >::mMapping, Heap< Key, Val >::percolate_down(), Heap< Key, Val >::percolate_up(), and Heap< Key, Val >::push().
Referenced by TerrainAnaysisClass::calculateWalkTileClearance(), PathFinderClass::CreateRegionPath(), TerrainAnaysisClass::createRegions(), PathFinderClass::CreateTilePath(), PathFinderClass::CreateWalkPath(), and MapHelper::walkSearch().
{ std::map<Key, int>::iterator it = mMapping.find(key); if(it == mMapping.end()) { push(std::make_pair(key, val)); return true; } int index = it->second; mData[index].second = val; index = percolate_up(index); if(index >= 0 && index < (int)mData.size()) { percolate_down(index); return true; } return false; }
Definition at line 41 of file Heap.h.
References Heap< Key, Val >::mData.
Referenced by TerrainAnaysisClass::calculateWalkTileClearance(), PathFinderClass::CreateRegionPath(), TerrainAnaysisClass::createRegions(), PathFinderClass::CreateTilePath(), PathFinderClass::CreateWalkPath(), and MapHelper::walkSearch().
{ return mData.front(); }
Definition at line 118 of file Heap.h.
Referenced by Heap< Key, Val >::clear(), Heap< Key, Val >::empty(), Heap< Key, Val >::erase(), Heap< Key, Val >::get(), Heap< Key, Val >::percolate_down(), Heap< Key, Val >::percolate_up(), Heap< Key, Val >::pop(), Heap< Key, Val >::push(), Heap< Key, Val >::set(), Heap< Key, Val >::size(), and Heap< Key, Val >::top().
bool Heap< Key, Val >::mIsMinHeap [private] |
Definition at line 120 of file Heap.h.
Referenced by Heap< Key, Val >::percolate_down(), and Heap< Key, Val >::percolate_up().
Definition at line 119 of file Heap.h.
Referenced by Heap< Key, Val >::clear(), Heap< Key, Val >::contains(), Heap< Key, Val >::erase(), Heap< Key, Val >::get(), Heap< Key, Val >::percolate_down(), Heap< Key, Val >::percolate_up(), Heap< Key, Val >::pop(), Heap< Key, Val >::push(), and Heap< Key, Val >::set().