1 module cassowary.set;
2 
3 import std.conv;
4 
5 class Set(TKey = Object)
6 {
7 	bool opBinary(string op) (const TKey o) if (op == "in")
8 	{
9 		return (o in hash) !is null;
10 	}
11 
12 	auto opOpAssign(string op) (ref TKey o) if (op == "~")
13 	{
14 		hash[o] = 1;
15 		return this;
16 	}
17 
18 	void remove(TKey o)
19 	{
20 		hash.remove(o);
21 	}
22 
23 	void clear()
24 	{
25 		hash = null;
26 	}
27 
28 	@property auto length() const
29 	{
30 		return hash.length;
31 	}
32 
33 	bool isEmpty() const
34 	{
35 		return length == 0;
36 	}
37 
38 	@property auto anyElement()
39 	{
40 		return hash.byKey().front;
41 	}
42 
43 	override string toString() const
44 	{
45 		return hash.keys().to!string();
46 	}
47 
48 	int opApply(int delegate(ref TKey) operations)
49 	{
50 		int res = 0;
51 		foreach(ref key; hash.byKey())
52 		{
53 			res = operations(key);
54 			if (res) break;
55 		}
56 		return res;
57 	}
58 
59 	private byte[TKey] hash;
60 }