diff --git a/DataStructures/BinaryHeap.h b/DataStructures/BinaryHeap.h index b64608829..5f6a6531c 100644 --- a/DataStructures/BinaryHeap.h +++ b/DataStructures/BinaryHeap.h @@ -31,12 +31,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include -template< typename NodeID, typename Key > +template< typename NodeID, typename Key, bool initialize = false > class ArrayStorage { public: ArrayStorage( size_t size ) - : positions( new Key[size] ) {} + : positions( new Key[size] ) { if(initialize) { memset(positions, 0, size*sizeof(Key));} } ~ArrayStorage() { delete[] positions; @@ -120,6 +120,10 @@ struct _SimpleHeapData { _SimpleHeapData( NodeID p ) : parent(p) { } }; +struct _NullHeapData { + _NullHeapData(NodeID p) {} +}; + template < typename NodeID, typename Key, typename Weight, typename Data, typename IndexStorage = ArrayStorage > class BinaryHeap { private: @@ -244,8 +248,7 @@ private: Key nextKey = key << 1; while ( nextKey < ( Key ) heap.size() ) { const Key nextKeyOther = nextKey + 1; - if ( ( nextKeyOther < ( Key ) heap.size() ) ) - if ( heap[nextKey].weight > heap[nextKeyOther].weight ) + if ( ( nextKeyOther < ( Key ) heap.size() )&& ( heap[nextKey].weight > heap[nextKeyOther].weight) ) nextKey = nextKeyOther; if ( weight <= heap[nextKey].weight )