using System.Collections.Generic; namespace Tracing { public class AddressStack { // the first frame is the address of the last called method private readonly List _stack; public AddressStack( int capacity ) { _stack = new List( capacity ); } // No need to override GetHashCode because we don't want to use it as a key in a dictionary public override bool Equals( object obj ) { if( obj == null ) return false; var stack = obj as AddressStack; if( stack == null ) return false; var frameCount = _stack.Count; if( frameCount != stack._stack.Count ) return false; for( int i = 0; i < frameCount; i++ ) { if( _stack[i] != stack._stack[i] ) return false; } return true; } public override int GetHashCode() => _stack.GetHashCode(); public IReadOnlyList Stack => _stack; public void AddFrame( ulong address ) { _stack.Add( address ); } } }