Add algorithm.mutation.rotate

This commit is contained in:
2018-11-12 07:54:52 +01:00
parent 3f66782368
commit 9e6f5c3105
3 changed files with 95 additions and 11 deletions

View File

@@ -15,7 +15,6 @@
module tanya.container.array;
import core.checkedint;
import std.algorithm.mutation : bringToFront;
import tanya.algorithm.comparison;
import tanya.algorithm.mutation;
import tanya.exception;
@@ -804,10 +803,11 @@ struct Array(T)
}
do
{
const oldLen = length;
const offset = r.end - this.data;
const oldLength = length;
const after = r.end - this.data;
const inserted = insertBack(el);
bringToFront(this.data[offset .. oldLen], this.data[oldLen .. length]);
rotate(this.data[after .. oldLength], this.data[oldLength .. length]);
return inserted;
}
@@ -846,7 +846,7 @@ struct Array(T)
{
moveBack(el);
}
bringToFront(this.data[offset .. oldLen], this.data[oldLen .. length]);
rotate(this.data[offset .. oldLen], this.data[oldLen .. length]);
return 1;
}
@@ -902,7 +902,7 @@ struct Array(T)
{
moveBack(el);
}
bringToFront(this.data[offset .. oldLen], this.data[oldLen .. length]);
rotate(this.data[offset .. oldLen], this.data[oldLen .. length]);
return 1;
}

View File

@@ -26,7 +26,6 @@
*/
module tanya.container.string;
import std.algorithm.mutation : bringToFront;
import tanya.algorithm.comparison;
import tanya.algorithm.mutation;
import tanya.hash.lookup;
@@ -1531,11 +1530,10 @@ struct String
do
{
const oldLength = length;
const rangeEnd = r.end - this.data;
const after = r.end - this.data;
const inserted = insertBack(el);
auto containerEnd = this.data + oldLength;
bringToFront(ByCodeUnit!char(this, this.data + rangeEnd, containerEnd),
ByCodeUnit!char(this, containerEnd, this.data + length));
rotate(this.data[after .. oldLength], this.data[oldLength .. length]);
return inserted;
}