Skip to content

Commit d869245

Browse files
committed
go back to old interface of undo
1 parent ec87fdf commit d869245

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

library/data_structures_[l,r)/uncommon/priority_queue_of_updates.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
//! @code
44
//! vector<pair<int, int>> updates;
55
//! pq_updates pq([&](int update_id) {},
6-
//! [&](int t) {});
6+
//! [&]() {});
77
//! updates.push_back({u, v});
88
//! pq.push(pri, ssize(updates) - 1);
99
//! @endcode
1010
//! @time O(n log n)
1111
//! @space O(n)
1212
template<class F, class G> struct pq_updates {
1313
F update;
14-
G rollback;
14+
G undo;
1515
using upd = pair<multimap<int, int>::iterator, int>;
1616
vector<upd> st;
1717
multimap<int, int> mp;
18-
pq_updates(F update, G rollback):
19-
update(update), rollback(rollback) {}
18+
pq_updates(F update, G undo):
19+
update(update), undo(undo) {}
2020
void pop() {
2121
vector<upd> extra;
2222
int t = sz(st) - 1;
@@ -26,7 +26,7 @@ template<class F, class G> struct pq_updates {
2626
t = min(t, it->second);
2727
it->second = -1;
2828
}
29-
rollback(t);
29+
rep(i, t, sz(st)) undo();
3030
ranges::reverse_copy(extra,
3131
remove_if(t + all(st),
3232
[](upd& x) { return x.first->second == -1; }));

tests/library_checker_aizu_tests/data_structures/pq_ds_undo_sliding_window.test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct stack_with_get_max {
1111
st.emplace_back(val,
1212
empty(st) ? val : min(val, st.back().second));
1313
}
14-
void rollback(int siz) { st.resize(siz); }
14+
void undo() { st.pop_back(); }
1515
int get_max() const { return st.back().second; }
1616
};
1717
int main() {
@@ -23,7 +23,7 @@ int main() {
2323
vector<int> updates;
2424
stack_with_get_max stm;
2525
pq_updates pq([&](int id) { stm.join(updates[id]); },
26-
[&](int t) { stm.rollback(t); });
26+
[&]() { stm.undo(); });
2727
int pri = (n - l) / 2;
2828
rep(i, 0, l) {
2929
updates.push_back(arr[i]);

tests/library_checker_aizu_tests/handmade_tests/pq_updates.test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ int main() {
1111
auto update = [&](int id) {
1212
ds_history.push_back(id);
1313
};
14-
auto rollback = [&](int t) { ds_history.resize(t); };
15-
pq_updates solver(update, rollback);
14+
auto undo = [&]() { ds_history.pop_back(); };
15+
pq_updates solver(update, undo);
1616
map<pair<int, int>, int> naive_mp;
1717
int upd_id_counter = 0;
1818
rep(op, 0, 200) {

0 commit comments

Comments
 (0)