1 module collections.commons;
2 
3 import std.digest.murmurhash;
4 
5 ///Contains all possible basic attributes that might be used in a foreach situation
6 static immutable string[] attrList = ["@trusted", "@safe", "@nogc", "nothrow", "pure",
7 	"@nogc nothrow", "@nogc pure", "nothrow pure", "@nogc nothrow pure",
8 	/+"@trusted @nogc nothrow", "@trusted @nogc pure", "@trusted nothrow pure", "@trusted @nogc nothrow pure",+/
9 	"@safe @nogc nothrow", "@safe @nogc pure", "@safe nothrow pure", "@safe @nogc nothrow pure",];
10 ///Generates overrides to be mixed in with regular code
11 string generateOverrides()(){
12 	string result;
13 	foreach (attr; attrList)
14 		result ~= Func(attr);
15 	return result;
16 }
17 ///Thrown if an element is nog found
18 public class ElementNotFoundException : Exception {
19 	@nogc @safe pure nothrow this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable nextInChain = null) {
20 		super(msg, file, line, nextInChain);
21 	}
22 
23 	@nogc @safe pure nothrow this(string msg, Throwable nextInChain, string file = __FILE__, size_t line = __LINE__)
24 	{
25 		super(msg, file, line, nextInChain);
26 	}
27 }
28 ///Thrown if incorrect arguments are passed to a function
29 public class IncorrectArgumentsException : Exception {
30 	@nogc @safe pure nothrow this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable nextInChain = null) {
31 		super(msg, file, line, nextInChain);
32 	}
33 
34 	@nogc @safe pure nothrow this(string msg, Throwable nextInChain, string file = __FILE__, size_t line = __LINE__)
35 	{
36 		super(msg, file, line, nextInChain);
37 	}
38 }
39 /**
40  * Standard digest function for hashing, using the MurMurHash3/32 algorithm
41  */
42 uint defaultHash(R)(R src) @nogc @trusted pure nothrow {
43 	const (ubyte)[] helperFunc() @nogc @system pure nothrow {
44 		return cast(const (ubyte)[])(cast(const (void)[])src);
45 	}
46 	MurmurHash3!32 hashFunc;
47 	hashFunc.put(helperFunc);
48 	hashFunc.finish();
49 	return hashFunc.get();
50 }
51 /**
52  * Standard digest function for hashing, using the MurMurHash3/128 algorithm
53  */
54 ubyte[16] defaultHash128(R)(R src) @nogc @trusted pure nothrow {
55 	const (ubyte)[] helperFunc() @nogc @system pure nothrow {
56 		return cast(const (ubyte)[])(cast(const (void)[])src);
57 	}
58 	MurmurHash3!128 hashFunc;
59 	hashFunc.put(helperFunc);
60 	return hashFunc.finish();
61 }