Skip to content

Commit fe5641d

Browse files
committed
minor changes
1 parent 0f76307 commit fe5641d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

include/random_walks/uniform_accelerated_billiard_walk.hpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Heap {
6565
heap_size = 0;
6666
for(int i = 0; i < n; ++i) {
6767
vec[i].second = -1;
68-
if(vec[i].first > moved_dist) {
68+
if(vec[i].first - eps > moved_dist) {
6969
vec[i].second = heap_size;
7070
heap[heap_size++] = {vec[i].first, i};
7171
}
@@ -83,7 +83,8 @@ class Heap {
8383
return heap[0];
8484
}
8585

86-
void remove (int index) { // takes the index from the heap
86+
void remove (int index) { // takes the index from the vec
87+
index = vec[index].second;
8788
if(index == -1) {
8889
return;
8990
}
@@ -96,24 +97,26 @@ class Heap {
9697
}
9798

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

103106
void change_val(const int& index, const NT& new_val, const NT& moved_dist) { // takes the index from the vec
104-
if(new_val < moved_dist) { // should not be inserted into the heap
105-
remove(vec[index].second);
106-
} else { // should be inserted into the heap
107+
if(new_val < moved_dist - eps) {
108+
vec[index].first = new_val;
109+
remove(index);
110+
} else {
107111
if(vec[index].second == -1) {
108-
vec[index].second = heap_size;
109112
insert({new_val, index});
110113
} else {
111114
heap[vec[index].second].first = new_val;
115+
vec[index].first = new_val;
112116
siftDown(vec[index].second);
113117
siftUp(vec[index].second);
114118
}
115119
}
116-
vec[index].first = new_val;
117120
}
118121
};
119122

0 commit comments

Comments
 (0)