Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Rope (data structure)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Insert === : ''Definition:'' <code>Insert(i, Sβ)</code>: insert the string ''Sβ'' beginning at position ''i'' in the string ''s'', to form a new string {{math|''C''<sub>1</sub>, ..., ''C<sub>i</sub>'', ''S''', ''C''<sub>''i'' + 1</sub>, ..., ''C<sub>m</sub>''}}. : ''Time complexity:'' {{tmath|O(\log N)}}. This operation can be done by a <code>Split()</code> and two <code>Concat()</code> operations. The cost is the sum of the three. <syntaxhighlight lang="java"> public Rope insert(int idx, CharSequence sequence) { if (idx == 0) { return prepend(sequence); } if (idx == length()) { return append(sequence); } val lhs = base.split(idx); return new Rope(Ropes.concat(lhs.fst.append(sequence), lhs.snd)); } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)