Skip to content

Commit

Permalink
Fix #22
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackerpilot committed Oct 29, 2015
1 parent ef43ca7 commit b428d13
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/containers/treemap.d
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ struct TreeMap(K, V, Allocator = Mallocator, alias less = "a < b",
return tree.length;
}

auto keys() const pure nothrow @property @safe @nogc
{
import std.algorithm.iteration : map;
return tree[].map!(a => a.key);
}

auto values() const pure nothrow @property @safe @nogc
{
import std.algorithm.iteration : map;
return tree[].map!(a => a.value);
}

/// Supports $(B foreach(k, v; treeMap)) syntax.
int opApply(this This)(int delegate(ref K, ref V) loopBody)
{
Expand Down Expand Up @@ -159,3 +171,16 @@ unittest
assert(allocator.numAllocate == allocator.numDeallocate);
assert(allocator.bytesUsed == 0);
}

unittest
{
import std.algorithm.iteration : each;
import std.algorithm.comparison : equal;
import std.range : repeat, take;

TreeMap!(int, int) tm;
int[] a = [1, 2, 3, 4, 5];
a.each!(a => tm[a] = 0);
assert(equal(tm.keys, a));
assert(equal(tm.values, repeat(0).take(a.length)));
}

0 comments on commit b428d13

Please sign in to comment.