1 /**
2  * Copyright: Copyright Jason White, 2016
3  * License:   MIT
4  * Authors:   Jason White
5  */
6 module button.edge;
7 
8 /**
9  * An edge. Because the graph must be bipartite, an edge can never connect two
10  * vertices of the same type.
11  */
12 struct Edge(From, To)
13     if (!is(From == To))
14 {
15     From from;
16     To to;
17 
18     /**
19      * Compares two edges.
20      */
21     int opCmp()(const auto ref typeof(this) rhs) const pure nothrow
22     {
23         if (this.from != rhs.from)
24             return this.from < rhs.from ? -1 : 1;
25 
26         if (this.to != rhs.to)
27             return this.to < rhs.to ? -1 : 1;
28 
29         return 0;
30     }
31 
32     /**
33      * Returns true if both edges are the same.
34      */
35     bool opEquals()(const auto ref typeof(this) rhs) const pure
36     {
37         return from == rhs.from &&
38                to == rhs.to;
39     }
40 }
41 
42 /// Ditto
43 struct Edge(From, To, Data)
44     if (!is(From == To))
45 {
46     From from;
47     To to;
48 
49     Data data;
50 
51     /**
52      * Compares two edges.
53      */
54     int opCmp()(const auto ref typeof(this) rhs) const pure
55     {
56         if (this.from != rhs.from)
57             return this.from < rhs.from ? -1 : 1;
58 
59         if (this.to != rhs.to)
60             return this.to < rhs.to ? -1 : 1;
61 
62         if (this.data != rhs.data)
63             return this.data < rhs.data ? -1 : 1;
64 
65         return 0;
66     }
67 
68     /**
69      * Returns true if both edges are the same.
70      */
71     bool opEquals()(const auto ref typeof(this) rhs) const pure
72     {
73         return from == rhs.from &&
74                to == rhs.to &&
75                data == rhs.data;
76     }
77 }