Skip to content

Commit

Permalink
Char-optimize Treap source code (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
spike1236 authored Jan 30, 2025
1 parent 7515986 commit 7b89431
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions content/data-structures/Treap.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ template<class F> void each(Node* n, F f) {
pair<Node*, Node*> split(Node* n, int k) {
if (!n) return {};
if (cnt(n->l) >= k) { // "n->val >= k" for lower_bound(k)
auto pa = split(n->l, k);
n->l = pa.second;
auto [L,R] = split(n->l, k);
n->l = R;
n->recalc();
return {pa.first, n};
return {L, n};
} else {
auto pa = split(n->r, k - cnt(n->l) - 1); // and just "k"
n->r = pa.first;
auto [L,R] = split(n->r,k - cnt(n->l) - 1); // and just "k"
n->r = L;
n->recalc();
return {n, pa.second};
return {n, R};
}
}

Expand All @@ -44,12 +44,10 @@ Node* merge(Node* l, Node* r) {
if (!r) return l;
if (l->y > r->y) {
l->r = merge(l->r, r);
l->recalc();
return l;
return l->recalc(), l;
} else {
r->l = merge(l, r->l);
r->recalc();
return r;
return r->recalc(), r;
}
}

Expand Down

0 comments on commit 7b89431

Please sign in to comment.