-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.cs
73 lines (59 loc) · 1.71 KB
/
Node.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using QuikGraph;
namespace GraphRewriteEngine
{
public class Node : IEquatable<Node>, IComparable<Node>, ITagged<string>, ICloneable { //Add IComparable
public int Index {get; set;}
public string Tag {get; set;}
public Node(int index) {
this.Index = index;
this.Tag = "";
}
public Node(int index, string tag) {
this.Index = index;
this.Tag = tag;
}
//overriding for hashing purposes
public override int GetHashCode()
{
return this.Index;
}
public override bool Equals(object obj) {
if (obj is int) {
return Equals(obj);
}
return Equals(obj as Node);
}
public int CompareTo(Node n) {
if (n == null) {
return 1;
}
return this.Index.CompareTo(n.Index);
}
//defining for convinience
public override string ToString()
{
return $"v{this.Index}.L:{this.Tag}";
}
//to define overwritten
public bool Equals(Node n) {
if (n == null) {
return false;
}
return this.Index.Equals(n.Index);
}
//for indexing!
public bool Equals(int i) {
return this.Index.Equals(i);
}
public object Clone() {
return new Node(this.Index, this.Tag);
}
//label equivalence is not node equality
public bool IsEquivalent(Node n) {
return this.Tag.Equals(n.Tag);
}
public event EventHandler TagChanged;
}
}