1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
6
using System.Collections.Generic;
8
namespace ICSharpCode.Profiler.Controller.Queries
11
/// Describes an absolute path to an CallTreeNode.
13
public sealed class NodePath : IEquatable<NodePath>, IEnumerable<int>
16
/// Describes an empty NodePath.
18
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
19
Justification = "NodePath is immutable")]
20
public static readonly NodePath Empty = new NodePath(0, null);
26
/// Gets the top-most/last NameId in the path.
29
get { return lastId; }
33
/// Gets a reference to the previous segment of the path.
35
public NodePath Previous {
36
get { return previous; }
39
NodePath(int id, NodePath previous)
42
this.previous = previous;
46
/// Creates a new NodePath from this with a new Name Id segment attached.
48
public NodePath Append(int newValue)
50
return new NodePath(newValue, this);
54
/// Returns whether the other NodePath is equal to this NodePath.
56
public bool Equals(NodePath other)
61
return other.lastId == this.lastId && object.Equals(other.previous, this.previous);
65
public override bool Equals(object obj)
67
return Equals(obj as NodePath);
71
public override int GetHashCode()
73
// (a[0] * p + a[1]) * p + a[2]
74
const int hashPrime = 1000000007;
77
return ((previous != null) ? previous.GetHashCode() : 0) * hashPrime + lastId;
82
public IEnumerator<int> GetEnumerator()
84
var list = new List<int>();
91
return list.GetEnumerator();
94
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
96
return GetEnumerator();
100
public override string ToString()
102
return ((previous != null) ? previous.ToString() + "->" : "") + lastId;