Last active
December 26, 2015 01:28
-
-
Save Varriount/7071043 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc delete*[T](s: var seq[T], first, last: int) = | |
## Deletes in `s` the items at position `first` .. `last`. This modifies | |
## `s` itself, it does not return a copy. | |
var i = first | |
var j = last+1 | |
var newLen = len(s)-j+i | |
while i < newLen: | |
s[i].shallowCopy(s[j]) | |
inc(i) | |
inc(j) | |
setlen(s, newLen) | |
proc insert*[T](sOne: var seq[T], sTwo: var seq[T], pos: int) = | |
## Inserts items in `sTwo` into `sOne` at position `pos`. This modifies | |
## `sOne` itself, it does not return a copy. | |
var j = len(sOne) | |
var i = len(sOne)+len(sTwo) | |
sOne.setLen(i) | |
dec(j) | |
dec(i) | |
# Move items after `pos` to the end of the sequence. | |
while j >= pos: | |
sOne[i].shallowCopy(sOne[j]) | |
dec(i) | |
dec(j) | |
# Insert items from `sTwo` into `sOne` at `pos` | |
j = pos | |
for item in sTwo: | |
sOne[j] = item | |
inc(j) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment