diff options
| author | Eugen Wissner <belka@caraus.de> | 2021-06-04 09:37:50 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2021-06-04 09:37:50 +0200 |
| commit | 01550390718185445b2f852fd84d184a9c5eba76 (patch) | |
| tree | 8390cb9ec6cbdabcee1337e545a6e5990fa21116 /source | |
| parent | c15a8993ecc3c6dfdba430cca331534a1eef3ed8 (diff) | |
| download | tanya-01550390718185445b2f852fd84d184a9c5eba76.tar.gz | |
Replace rotate with bringToFront
Diffstat (limited to 'source')
| -rw-r--r-- | source/tanya/algorithm/mutation.d | 51 | ||||
| -rw-r--r-- | source/tanya/container/array.d | 7 | ||||
| -rw-r--r-- | source/tanya/container/string.d | 3 |
3 files changed, 6 insertions, 55 deletions
diff --git a/source/tanya/algorithm/mutation.d b/source/tanya/algorithm/mutation.d index 1a51a49..88f7da3 100644 --- a/source/tanya/algorithm/mutation.d +++ b/source/tanya/algorithm/mutation.d @@ -244,54 +244,3 @@ if (isInputRange!Range && hasLvalueElements!Range) assert(counter == 2); } - -/** - * Rotates the elements of a union of two ranges. - * - * Performs a left rotation on the given ranges, as if it would be a signle - * range, so that [`front.front`, `back.front`$(RPAREN) is a valid range, that - * is $(D_PARAM back) would continue $(D_PARAM front). - * - * The elements are moved so, that the first element of $(D_PARAM back) becomes - * the first element of $(D_PARAM front) without changing the relative order of - * their elements. - * - * Params: - * Range = Range type. - * front = Left half. - * back = Right half. - */ -void rotate(Range)(Range front, Range back) -if (isForwardRange!Range && hasSwappableElements!Range) -{ - auto next = back.save(); - - while (!front.empty && !next.empty && !sameHead(front, next)) - { - tanya.memory.lifetime.swap(front.front, next.front); - front.popFront(); - next.popFront(); - - if (next.empty) - { - next = back.save(); - } - else if (front.empty) - { - front = back.save(); - back = next.save(); - } - } -} - -/// -@nogc nothrow pure @safe unittest -{ - import std.algorithm.comparison : equal; - - const int[7] expected = [1, 2, 3, 4, 5, 6, 7]; - int[7] actual = [5, 6, 3, 4, 1, 2, 7]; - - rotate(actual[0 .. 2], actual[4 .. 6]); - assert(equal(actual[], expected[])); -} diff --git a/source/tanya/container/array.d b/source/tanya/container/array.d index c6d06ad..f5aabcf 100644 --- a/source/tanya/container/array.d +++ b/source/tanya/container/array.d @@ -17,6 +17,7 @@ module tanya.container.array; import core.checkedint; import std.algorithm.comparison; import std.algorithm.iteration; +import std.algorithm.mutation : bringToFront; import tanya.algorithm.mutation; import tanya.memory.allocator; import tanya.memory.lifetime; @@ -815,7 +816,7 @@ struct Array(T) const after = r.end - this.data; const inserted = insertBack(el); - rotate(this.data[after .. oldLength], this.data[oldLength .. length]); + bringToFront(this.data[after .. oldLength], this.data[oldLength .. length]); return inserted; } @@ -854,7 +855,7 @@ struct Array(T) { moveBack(el); } - rotate(this.data[offset .. oldLen], this.data[oldLen .. length]); + bringToFront(this.data[offset .. oldLen], this.data[oldLen .. length]); return 1; } @@ -910,7 +911,7 @@ struct Array(T) { moveBack(el); } - rotate(this.data[offset .. oldLen], this.data[oldLen .. length]); + bringToFront(this.data[offset .. oldLen], this.data[oldLen .. length]); return 1; } diff --git a/source/tanya/container/string.d b/source/tanya/container/string.d index e25e13c..88c82d2 100644 --- a/source/tanya/container/string.d +++ b/source/tanya/container/string.d @@ -27,6 +27,7 @@ module tanya.container.string; import std.algorithm.comparison; +import std.algorithm.mutation : bringToFront; import tanya.algorithm.mutation; import tanya.hash.lookup; import tanya.memory.allocator; @@ -1488,7 +1489,7 @@ struct String const after = r.end - this.data; const inserted = insertBack(el); - rotate(this.data[after .. oldLength], this.data[oldLength .. length]); + bringToFront(this.data[after .. oldLength], this.data[oldLength .. length]); return inserted; } |
