summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--dub.json2
-rw-r--r--source/tanya/container/list.d73
-rw-r--r--source/tanya/container/queue.d27
-rw-r--r--source/tanya/container/vector.d22
5 files changed, 100 insertions, 25 deletions
diff --git a/.gitignore b/.gitignore
index 1b841d8..0bdd0d5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@
.dub
__test__*__
__test__*__.core
+/tanya-test-library
/docs/
/docs.json
diff --git a/dub.json b/dub.json
index aebdcf7..6aced0b 100644
--- a/dub.json
+++ b/dub.json
@@ -1,6 +1,6 @@
{
"name": "tanya",
- "description": "D library with event loop",
+ "description": "General purpose, @nogc library",
"license": "MPL-2.0",
"copyright": "(c) Eugene Wissner <info@caraus.de>",
"authors": [
diff --git a/source/tanya/container/list.d b/source/tanya/container/list.d
index d482df8..73bf367 100644
--- a/source/tanya/container/list.d
+++ b/source/tanya/container/list.d
@@ -10,6 +10,8 @@
*/
module tanya.container.list;
+import std.algorithm.comparison;
+import std.algorithm.searching;
import std.traits;
import tanya.container.entry;
import tanya.memory;
@@ -31,6 +33,11 @@ private struct Range(E)
return this;
}
+ @property size_t length() const
+ {
+ return count(opIndex());
+ }
+
@property bool empty() const
{
return head is null;
@@ -159,6 +166,72 @@ struct SList(T)
}
/**
+ * Returns: How many elements are in the list.
+ */
+ @property size_t length() const
+ {
+ return count(opIndex());
+ }
+
+ ///
+ unittest
+ {
+ SList!int l;
+
+ l.insertFront(8);
+ l.insertFront(9);
+ assert(l.length == 2);
+ l.removeFront();
+ assert(l.length == 1);
+ l.removeFront();
+ assert(l.length == 0);
+ }
+
+ /**
+ * Comparison for equality.
+ *
+ * Params:
+ * that = The list to compare with.
+ *
+ * Returns: $(D_KEYWORD true) if the lists are equal, $(D_KEYWORD false)
+ * otherwise.
+ */
+ bool opEquals()(auto ref typeof(this) that) @trusted
+ {
+ return equal(opIndex(), that[]);
+ }
+
+ /// Ditto.
+ bool opEquals()(in auto ref typeof(this) that) const @trusted
+ {
+ return equal(opIndex(), that[]);
+ }
+
+ ///
+ unittest
+ {
+ SList!int l1, l2;
+
+ l1.insertFront(8);
+ l1.insertFront(9);
+ l2.insertFront(8);
+ l2.insertFront(10);
+ assert(l1 != l2);
+
+ l1.removeFront();
+ assert(l1 != l2);
+
+ l2.removeFront();
+ assert(l1 == l2);
+
+ l1.removeFront();
+ assert(l1 != l2);
+
+ l2.removeFront();
+ assert(l1 == l2);
+ }
+
+ /**
* Returns: $(D_KEYWORD true) if the list is empty.
*/
@property bool empty() const
diff --git a/source/tanya/container/queue.d b/source/tanya/container/queue.d
index d94486d..f197687 100644
--- a/source/tanya/container/queue.d
+++ b/source/tanya/container/queue.d
@@ -100,10 +100,8 @@ struct Queue(T)
*
* Params:
* x = New element.
- *
- * Returns: $(D_KEYWORD this).
*/
- ref typeof(this) enqueue(ref T x)
+ void enqueue(ref T x)
{
auto temp = allocateEntry();
@@ -111,12 +109,10 @@ struct Queue(T)
temp.content = x;
enqueueEntry(temp);
-
- return this;
}
/// Ditto.
- ref typeof(this) enqueue(T x)
+ void enqueue(T x)
{
auto temp = allocateEntry();
@@ -124,8 +120,6 @@ struct Queue(T)
(*temp).next = null;
enqueueEntry(temp);
-
- return this;
}
///
@@ -134,7 +128,8 @@ struct Queue(T)
Queue!int q;
assert(q.empty);
- q.enqueue(8).enqueue(9);
+ q.enqueue(8);
+ q.enqueue(9);
assert(q.dequeue() == 8);
assert(q.dequeue() == 9);
}
@@ -183,7 +178,8 @@ struct Queue(T)
{
Queue!int q;
- q.enqueue(8).enqueue(9);
+ q.enqueue(8);
+ q.enqueue(9);
assert(q.dequeue() == 8);
assert(q.dequeue() == 9);
}
@@ -232,7 +228,9 @@ struct Queue(T)
Queue!int q;
size_t j;
- q.enqueue(5).enqueue(4).enqueue(9);
+ q.enqueue(5);
+ q.enqueue(4);
+ q.enqueue(9);
foreach (i, e; q)
{
assert(i != 2 || e == 9);
@@ -244,7 +242,9 @@ struct Queue(T)
assert(q.empty);
j = 0;
- q.enqueue(5).enqueue(4).enqueue(9);
+ q.enqueue(5);
+ q.enqueue(4);
+ q.enqueue(9);
foreach (e; q)
{
assert(j != 2 || e == 9);
@@ -270,7 +270,8 @@ unittest
q.enqueue(5);
assert(!q.empty);
- q.enqueue(4).enqueue(9);
+ q.enqueue(4);
+ q.enqueue(9);
assert(q.dequeue() == 5);
diff --git a/source/tanya/container/vector.d b/source/tanya/container/vector.d
index e6dc861..94325e2 100644
--- a/source/tanya/container/vector.d
+++ b/source/tanya/container/vector.d
@@ -1060,42 +1060,42 @@ struct Vector(T)
* Comparison for equality.
*
* Params:
- * v = The vector to compare with.
+ * that = The vector to compare with.
*
* Returns: $(D_KEYWORD true) if the vectors are equal, $(D_KEYWORD false)
* otherwise.
*/
- bool opEquals()(auto ref typeof(this) v) @trusted
+ bool opEquals()(auto ref typeof(this) that) @trusted
{
- return equal(vector[0 .. length_], v.vector[0 .. v.length_]);
+ return equal(vector[0 .. length_], that.vector[0 .. that.length_]);
}
/// Ditto.
- bool opEquals()(in auto ref typeof(this) v) const @trusted
+ bool opEquals()(in auto ref typeof(this) that) const @trusted
{
- return equal(vector[0 .. length_], v.vector[0 .. length_]);
+ return equal(vector[0 .. length_], that.vector[0 .. that.length_]);
}
/// Ditto.
- bool opEquals(Range!T v)
+ bool opEquals(Range!T that)
{
- return equal(opIndex(), v);
+ return equal(opIndex(), that);
}
/**
* Comparison for equality.
*
* Params:
- * R = Right hand side type.
- * v = Right hand side vector range.
+ * R = Right hand side type.
+ * that = Right hand side vector range.
*
* Returns: $(D_KEYWORD true) if the vector and the range are equal,
* $(D_KEYWORD false) otherwise.
*/
- bool opEquals(R)(Range!R v) const
+ bool opEquals(R)(Range!R that) const
if (is(Unqual!R == T))
{
- return equal(opIndex(), v);
+ return equal(opIndex(), that);
}
///