Skip to content

Commit

Permalink
Update byot.html
Browse files Browse the repository at this point in the history
  • Loading branch information
caterpillow authored Nov 16, 2024
1 parent 2f8476a commit 05426f9
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions byot.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ <h1>Build your own treap!</h1>
<label><input type="checkbox" id="size_option"> Include size</label><br>
<label><input type="checkbox" id="spliti_option"> Include split by index</label><br>
<label><input type="checkbox" id="three_spliti_option"> Include 3-way split by index</label><br>
<label><input type="checkbox" id="findi_option"> Include find by index</label><br>
<label><input type="checkbox" id="insi_option"> Include point insert by index</label><br>
<label><input type="checkbox" id="deli_option"> Include point deletion by index</label><br>
</div>
Expand Down Expand Up @@ -189,6 +190,7 @@ <h1>Build your own treap!</h1>
let del_option = false;
let size_option = false;
let spliti_option = false;
let findi_option = false;
let three_spliti_option = false;
let insi_option = false;
let deli_option = false;
Expand Down Expand Up @@ -233,6 +235,7 @@ <h1>Build your own treap!</h1>
["ins_option", "split_option"],
["spliti_option", "size_option"],
["insi_option", "spliti_option"],
["findi_option", "size_option"],
["range_add", "lazy_prop"],
["range_set", "lazy_prop"],
["key_add", "lazy_prop"],
Expand Down Expand Up @@ -401,6 +404,7 @@ <h1>Build your own treap!</h1>
split_option = document.getElementById("split_option").checked;
three_split_option = document.getElementById("three_split_option").checked;
find_option = document.getElementById("find_option").checked;
findi_option = document.getElementById("findi_option").checked;
ins_option = document.getElementById("ins_option").checked;
del_option = document.getElementById("del_option").checked;
size_option = document.getElementById("size_option").checked;
Expand Down Expand Up @@ -743,14 +747,25 @@ <h1>Build your own treap!</h1>
}

if (find_option) {
code += `bool find(ptr n, ${key_type} k) {\n` +
' if (!n) return false;\n' +
' if (n->key == k) return true;\n' +
code += 'ptr find(ptr n, int k) {\n' +
' if (!n) return 0;\n'
if (push) code += ' push(n);\n';
code += ' if (n->key == k) return n;\n' +
' if (k <= n->key) return find(n->l, k);\n' +
' else return find(n->r, k);\n' +
'}\n\n'
}

if (findi_option) {
code += 'ptr findi(ptr n, int i) {\n' +
' if (!n) return 0;\n'
if (push) code += ' push(n);\n'
code += ' if (sz(n->l) == i) return n;\n' +
' if (i < sz(n->l)) return findi(n->l, i);\n' +
' else return findi(n->r, i - sz(n->l) - 1);\n' +
'}\n\n'
}

if (ins_option) {
if (comments) code += '// returns root of new treap. only insert single nodes\n'
code += 'ptr ins(ptr n, ptr it) {\n' +
Expand Down

0 comments on commit 05426f9

Please sign in to comment.