PageRenderTime 562ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/sys/dotnet/fanx/fcode/FTuple.cs

https://bitbucket.org/bedlaczech/fan-1.0
C# | 85 lines | 52 code | 13 blank | 20 comment | 10 complexity | f0167c9520243eff45e5368d02ef740b MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. //
  2. // Copyright (c) 2006, Brian Frank and Andy Frank
  3. // Licensed under the Academic Free License version 3.0
  4. //
  5. // History:
  6. // 12 Sep 06 Andy Frank Creation
  7. //
  8. using System;
  9. using System.Text;
  10. namespace Fanx.Fcode
  11. {
  12. ///
  13. /// FTuple stores a list of FTable indices to model a more complex
  14. /// struction like a type's qname or a slot signature.
  15. ///
  16. public class FTuple
  17. {
  18. //////////////////////////////////////////////////////////////////////////
  19. // Constructors
  20. //////////////////////////////////////////////////////////////////////////
  21. public FTuple(int a, int b)
  22. {
  23. this.val = new int[] { a, b };
  24. }
  25. public FTuple(int a, int b, int c)
  26. {
  27. this.val = new int[] { a, b, c };
  28. }
  29. public FTuple(int[] val)
  30. {
  31. this.val = val;
  32. }
  33. //////////////////////////////////////////////////////////////////////////
  34. // .NET
  35. //////////////////////////////////////////////////////////////////////////
  36. public override int GetHashCode()
  37. {
  38. if (hashCode == 0)
  39. {
  40. int hash = 33;
  41. for (int i=0; i<val.Length; ++i)
  42. hash ^= val[i] << i;
  43. }
  44. return hashCode;
  45. }
  46. public override bool Equals(object obj)
  47. {
  48. FTuple x = (FTuple)obj;
  49. if (val.Length != x.val.Length) return false;
  50. for (int i=0; i<val.Length; ++i)
  51. if (val[i] != x.val[i]) return false;
  52. return true;
  53. }
  54. public override string ToString()
  55. {
  56. StringBuilder s = new StringBuilder();
  57. s.Append('{');
  58. for (int i=0; i<val.Length; i++)
  59. {
  60. if (i > 0) s.Append(", ");
  61. s.Append(val[i]);
  62. }
  63. s.Append('}');
  64. return s.ToString();
  65. }
  66. //////////////////////////////////////////////////////////////////////////
  67. // Fields
  68. //////////////////////////////////////////////////////////////////////////
  69. public int[] val;
  70. private int hashCode = 0;
  71. }
  72. }