From 03c40ecace46778ef2ac80a7bce08d706de7e4c6 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 25 Feb 2018 18:25:19 +0100 Subject: [PATCH] Fix removing all elements from DList --- source/tanya/container/list.d | 131 +++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 58 deletions(-) diff --git a/source/tanya/container/list.d b/source/tanya/container/list.d index f9dfc9f..f930240 100644 --- a/source/tanya/container/list.d +++ b/source/tanya/container/list.d @@ -179,12 +179,6 @@ struct SList(T) assert(l.front == 3); } - @nogc nothrow pure @safe unittest - { - auto l = SList!int(0, 0); - assert(l.empty); - } - /// ditto this(const size_t len, shared Allocator allocator = defaultAllocator) { @@ -842,14 +836,6 @@ struct SList(T) assert(l1 == l2); } - @nogc nothrow pure @safe unittest - { - auto l1 = SList!int(); - auto l2 = SList!int([9, 4]); - l1 = l2[]; - assert(l1 == l2); - } - /** * Assigns a static array. * @@ -903,6 +889,12 @@ struct SList(T) static assert(is(SList!Stuff)); } +@nogc nothrow pure @safe unittest +{ + auto l = SList!int(0, 0); + assert(l.empty); +} + // foreach called using opIndex(). @nogc nothrow pure @safe unittest { @@ -921,6 +913,14 @@ struct SList(T) } } +@nogc nothrow pure @safe unittest +{ + auto l1 = SList!int(); + auto l2 = SList!int([9, 4]); + l1 = l2[]; + assert(l1 == l2); +} + /** * Forward range for the $(D_PSYMBOL DList). * @@ -1109,12 +1109,6 @@ struct DList(T) assert(l.back == 3); } - @nogc nothrow pure @safe unittest - { - auto l = DList!int(0, 0); - assert(l.empty); - } - /// ditto this(const size_t len, shared Allocator allocator = defaultAllocator) { @@ -1408,12 +1402,6 @@ struct DList(T) return inserted; } - @nogc nothrow pure @safe unittest - { - auto l1 = DList!int([5, 234]); - assert(l1.head is l1.head.next.prev); - } - /// ditto size_t insertFront(size_t R)(T[R] el) { @@ -1726,15 +1714,6 @@ struct DList(T) assert(l1 == l2); } - @nogc nothrow pure @safe unittest - { - DList!int l; - l.insertAfter(l[], 234); - assert(l.front == 234); - assert(l.back == 234); - assert(l.length == 1); - } - /// ditto size_t insertAfter(Range r, ref T el) @trusted in @@ -2068,6 +2047,15 @@ struct DList(T) { tailNext.prev = headPrev; } + if (headPrev !is null) + { + headPrev.next = tailNext; + } + else if (headPrev is null && tailNext is null) + { + this.tail = null; + this.head = null; + } *r.head = tailNext; *r.tail = tail; @@ -2087,21 +2075,6 @@ struct DList(T) assert(l1 == l2); } - @nogc nothrow pure @safe unittest - { - auto l1 = DList!int([5, 234, 30, 1]); - auto l2 = DList!int([5, 1]); - auto r = l1[]; - - r.popFront(); - r.popBack(); - assert(r.front == 234); - assert(r.back == 30); - - assert(!l1.remove(r).empty); - assert(l1 == l2); - } - /** * Returns: Range that iterates over all elements of the container, in * forward order. @@ -2190,14 +2163,6 @@ struct DList(T) assert(l1 == l2); } - @nogc nothrow pure @safe unittest - { - auto l1 = DList!int(); - auto l2 = DList!int([9, 4]); - l1 = l2[]; - assert(l1 == l2); - } - /** * Assigns a static array. * @@ -2251,3 +2216,53 @@ struct DList(T) static assert(is(SList!(A*))); static assert(is(DList!(A*))); } + +@nogc nothrow pure @safe unittest +{ + auto l = DList!int([5]); + assert(l.remove(l[]).empty); +} + +@nogc nothrow pure @safe unittest +{ + auto l1 = DList!int([5, 234, 30, 1]); + auto l2 = DList!int([5, 1]); + auto r = l1[]; + + r.popFront(); + r.popBack(); + assert(r.front == 234); + assert(r.back == 30); + + assert(!l1.remove(r).empty); + assert(l1 == l2); +} + +@nogc nothrow pure @safe unittest +{ + auto l = DList!int(0, 0); + assert(l.empty); +} + +@nogc nothrow pure @safe unittest +{ + auto l1 = DList!int([5, 234]); + assert(l1.head is l1.head.next.prev); +} + +@nogc nothrow pure @safe unittest +{ + DList!int l; + l.insertAfter(l[], 234); + assert(l.front == 234); + assert(l.back == 234); + assert(l.length == 1); +} + +@nogc nothrow pure @safe unittest +{ + auto l1 = DList!int(); + auto l2 = DList!int([9, 4]); + l1 = l2[]; + assert(l1 == l2); +}