mirror of
https://github.com/boostorg/graph.git
synced 2026-02-01 08:32:11 +00:00
Added ability to check whether an element is in the heap, and do conditional insert/update operations based on that
[SVN r51021]
This commit is contained in:
@@ -104,6 +104,7 @@ namespace boost {
|
||||
}
|
||||
|
||||
void pop() {
|
||||
put(index_in_heap, data[0], (size_type)(-1));
|
||||
data[0] = data.back();
|
||||
put(index_in_heap, data[0], 0);
|
||||
data.pop_back();
|
||||
@@ -120,6 +121,21 @@ namespace boost {
|
||||
verify_heap();
|
||||
}
|
||||
|
||||
bool contains(const Value& v) const {
|
||||
return (index != (size_type)(-1));
|
||||
}
|
||||
|
||||
void push_or_update(const Value& v) { /* insert if not present, else update */
|
||||
size_type index = get(index_in_heap, v);
|
||||
if (index == (size_type)(-1)) {
|
||||
index = data.size();
|
||||
data.push_back(v);
|
||||
put(index_in_heap, v, index);
|
||||
}
|
||||
preserve_heap_property_up(index);
|
||||
verify_heap();
|
||||
}
|
||||
|
||||
private:
|
||||
Compare compare;
|
||||
Container data;
|
||||
@@ -211,6 +227,7 @@ namespace boost {
|
||||
// From the root, swap elements (each one with its smallest child) if there
|
||||
// are any parent-child pairs that violate the heap property
|
||||
void preserve_heap_property_down() {
|
||||
if (data.empty()) return;
|
||||
size_type index = 0;
|
||||
Value currently_being_moved = data[0];
|
||||
distance_type currently_being_moved_dist =
|
||||
|
||||
Reference in New Issue
Block a user