Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaperju committed Aug 14, 2024
1 parent 0f76307 commit fe5641d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions include/random_walks/uniform_accelerated_billiard_walk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Heap {
heap_size = 0;
for(int i = 0; i < n; ++i) {
vec[i].second = -1;
if(vec[i].first > moved_dist) {
if(vec[i].first - eps > moved_dist) {
vec[i].second = heap_size;
heap[heap_size++] = {vec[i].first, i};
}
Expand All @@ -83,7 +83,8 @@ class Heap {
return heap[0];
}

void remove (int index) { // takes the index from the heap
void remove (int index) { // takes the index from the vec
index = vec[index].second;
if(index == -1) {
return;
}
Expand All @@ -96,24 +97,26 @@ class Heap {
}

void insert (const std::pair<NT, int> val) {
vec[val.second].second = heap_size;
vec[val.second].first = val.first;
heap[heap_size++] = val;
siftUp(heap_size - 1);
}

void change_val(const int& index, const NT& new_val, const NT& moved_dist) { // takes the index from the vec
if(new_val < moved_dist) { // should not be inserted into the heap
remove(vec[index].second);
} else { // should be inserted into the heap
if(new_val < moved_dist - eps) {
vec[index].first = new_val;
remove(index);
} else {
if(vec[index].second == -1) {
vec[index].second = heap_size;
insert({new_val, index});
} else {
heap[vec[index].second].first = new_val;
vec[index].first = new_val;
siftDown(vec[index].second);
siftUp(vec[index].second);

Check warning on line 117 in include/random_walks/uniform_accelerated_billiard_walk.hpp

View check run for this annotation

Codecov / codecov/patch

include/random_walks/uniform_accelerated_billiard_walk.hpp#L114-L117

Added lines #L114 - L117 were not covered by tests
}
}
vec[index].first = new_val;
}
};

Expand Down

0 comments on commit fe5641d

Please sign in to comment.