array initialization can be optional
This commit is contained in:
parent
108e1ad5e6
commit
6e8a1e0e31
@ -31,12 +31,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include <google/sparse_hash_map>
|
#include <google/sparse_hash_map>
|
||||||
#include <google/sparsetable>
|
#include <google/sparsetable>
|
||||||
|
|
||||||
template< typename NodeID, typename Key >
|
template< typename NodeID, typename Key, bool initialize = false >
|
||||||
class ArrayStorage {
|
class ArrayStorage {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ArrayStorage( size_t size )
|
ArrayStorage( size_t size )
|
||||||
: positions( new Key[size] ) {}
|
: positions( new Key[size] ) { if(initialize) { memset(positions, 0, size*sizeof(Key));} }
|
||||||
|
|
||||||
~ArrayStorage() {
|
~ArrayStorage() {
|
||||||
delete[] positions;
|
delete[] positions;
|
||||||
@ -120,6 +120,10 @@ struct _SimpleHeapData {
|
|||||||
_SimpleHeapData( NodeID p ) : parent(p) { }
|
_SimpleHeapData( NodeID p ) : parent(p) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct _NullHeapData {
|
||||||
|
_NullHeapData(NodeID p) {}
|
||||||
|
};
|
||||||
|
|
||||||
template < typename NodeID, typename Key, typename Weight, typename Data, typename IndexStorage = ArrayStorage<NodeID, NodeID> >
|
template < typename NodeID, typename Key, typename Weight, typename Data, typename IndexStorage = ArrayStorage<NodeID, NodeID> >
|
||||||
class BinaryHeap {
|
class BinaryHeap {
|
||||||
private:
|
private:
|
||||||
@ -244,8 +248,7 @@ private:
|
|||||||
Key nextKey = key << 1;
|
Key nextKey = key << 1;
|
||||||
while ( nextKey < ( Key ) heap.size() ) {
|
while ( nextKey < ( Key ) heap.size() ) {
|
||||||
const Key nextKeyOther = nextKey + 1;
|
const Key nextKeyOther = nextKey + 1;
|
||||||
if ( ( nextKeyOther < ( Key ) heap.size() ) )
|
if ( ( nextKeyOther < ( Key ) heap.size() )&& ( heap[nextKey].weight > heap[nextKeyOther].weight) )
|
||||||
if ( heap[nextKey].weight > heap[nextKeyOther].weight )
|
|
||||||
nextKey = nextKeyOther;
|
nextKey = nextKeyOther;
|
||||||
|
|
||||||
if ( weight <= heap[nextKey].weight )
|
if ( weight <= heap[nextKey].weight )
|
||||||
|
Loading…
Reference in New Issue
Block a user