daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Mar 14th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 01000000-0000-0000-0000-000000000000
  2. 10000000-0000-0000-0000-000000000000
  3. 00010000-0000-0000-0000-000000000000
  4. 00100000-0000-0000-0000-000000000000
  5. 00000100-0000-0000-0000-000000000000
  6. 00001000-0000-0000-0000-000000000000
  7. 00000001-0000-0000-0000-000000000000
  8. 00000010-0000-0000-0000-000000000000
  9. 00000000-0100-0000-0000-000000000000
  10. 00000000-1000-0000-0000-000000000000
  11. 00000000-0001-0000-0000-000000000000
  12. 00000000-0010-0000-0000-000000000000
  13. 00000000-0000-0100-0000-000000000000
  14. 00000000-0000-1000-0000-000000000000
  15. 00000000-0000-0001-0000-000000000000
  16. 00000000-0000-0010-0000-000000000000
  17. 00000000-0000-0000-0001-000000000000
  18. 00000000-0000-0000-0010-000000000000
  19. 00000000-0000-0000-0100-000000000000
  20. 00000000-0000-0000-1000-000000000000
  21. 00000000-0000-0000-0000-000000000001
  22. 00000000-0000-0000-0000-000000000010
  23. 00000000-0000-0000-0000-000000000100
  24. 00000000-0000-0000-0000-000000001000
  25. 00000000-0000-0000-0000-000000010000
  26. 00000000-0000-0000-0000-000000100000
  27. 00000000-0000-0000-0000-000001000000
  28. 00000000-0000-0000-0000-000010000000
  29. 00000000-0000-0000-0000-000100000000
  30. 00000000-0000-0000-0000-001000000000
  31. 00000000-0000-0000-0000-010000000000
  32. 00000000-0000-0000-0000-100000000000
  33.    
  34. 00000000-0000-0000-0000-000000000001
  35. 00000000-0000-0000-0000-000000000010
  36. 00000000-0000-0000-0000-000000000100
  37. 00000000-0000-0000-0000-000000001000
  38. 00000000-0000-0000-0000-000000010000
  39. 00000000-0000-0000-0000-000000100000
  40. 00000000-0000-0000-0000-000001000000
  41. 00000000-0000-0000-0000-000010000000
  42. 00000000-0000-0000-0000-000100000000
  43. 00000000-0000-0000-0000-001000000000
  44. 00000000-0000-0000-0000-010000000000
  45. 00000000-0000-0000-0000-100000000000
  46. 00000000-0000-0000-0001-000000000000
  47. 00000000-0000-0000-0010-000000000000
  48. 00000000-0000-0000-0100-000000000000
  49. 00000000-0000-0000-1000-000000000000
  50. 00000000-0000-0001-0000-000000000000
  51. 00000000-0000-0010-0000-000000000000
  52. 00000000-0000-0100-0000-000000000000
  53. 00000000-0000-1000-0000-000000000000
  54. 00000000-0001-0000-0000-000000000000
  55. 00000000-0010-0000-0000-000000000000
  56. 00000000-0100-0000-0000-000000000000
  57. 00000000-1000-0000-0000-000000000000
  58. 00000001-0000-0000-0000-000000000000
  59. 00000010-0000-0000-0000-000000000000
  60. 00000100-0000-0000-0000-000000000000
  61. 00001000-0000-0000-0000-000000000000
  62. 00010000-0000-0000-0000-000000000000
  63. 00100000-0000-0000-0000-000000000000
  64. 01000000-0000-0000-0000-000000000000
  65. 10000000-0000-0000-0000-000000000000
  66.    
  67. List<Guid> a = new List<Guid>();
  68. a.Add(new Guid("3AAAAAAA-BBBB-CCCC-DDDD-2EEEEEEEEEEE"));
  69. a.Add(new Guid("2AAAAAAA-BBBB-CCCC-DDDD-1EEEEEEEEEEE"));
  70. a.Add(new Guid("1AAAAAAA-BBBB-CCCC-DDDD-3EEEEEEEEEEE"));
  71. Console.WriteLine("--Unsorted Guids--");
  72. foreach (Guid g in a)
  73. {
  74.     Console.WriteLine("{0}", g);
  75. }
  76. a.Sort();
  77. Console.WriteLine("--Sorted Guids--");
  78. foreach (Guid g in a)
  79. {
  80.     Console.WriteLine("{0}", g);
  81. }
  82.  
  83. List<SqlGuid> b = new List<SqlGuid>();
  84. b.Add(new SqlGuid("3AAAAAAA-BBBB-CCCC-DDDD-2EEEEEEEEEEE"));
  85. b.Add(new SqlGuid("2AAAAAAA-BBBB-CCCC-DDDD-1EEEEEEEEEEE"));
  86. b.Add(new SqlGuid("1AAAAAAA-BBBB-CCCC-DDDD-3EEEEEEEEEEE"));
  87. b.Sort();
  88. Console.WriteLine("--Sorted SqlGuids--");
  89. foreach (SqlGuid sg in b)
  90. {
  91.     Console.WriteLine("{0}", sg);
  92. }
  93.    
  94. List<SqlGuid> c = a.Select(g => new SqlGuid(g)).ToList();
  95. c.Sort();
  96. Console.WriteLine("--Sorted SqlGuids 2--");
  97. foreach (SqlGuid sg2 in c)
  98. {
  99.     Console.WriteLine("{0}", sg2);
  100. }
  101.    
  102. private static readonly int[] x_rgiGuidOrder = new int[16] // 16 Bytes = 128 Bit
  103.         {10, 11, 12, 13, 14, 15, 8, 9, 6, 7, 4, 5, 0, 1, 2, 3};
  104.    
  105. public class SqlGuid
  106.     : System.IComparable
  107.     , System.IComparable<SqlGuid>
  108.     , System.Collections.Generic.IComparer<SqlGuid>
  109.     , System.IEquatable<SqlGuid>
  110. {
  111.     private const int NUM_BYTES_IN_GUID = 16;
  112.  
  113.     // Comparison orders.
  114.     private static readonly int[] m_byteOrder = new int[16] // 16 Bytes = 128 Bit
  115.     {10, 11, 12, 13, 14, 15, 8, 9, 6, 7, 4, 5, 0, 1, 2, 3};
  116.  
  117.     private byte[] m_bytes; // the SqlGuid is null if m_value is null
  118.  
  119.  
  120.     public SqlGuid(byte[] guidBytes)
  121.     {
  122.         if (guidBytes == null || guidBytes.Length != NUM_BYTES_IN_GUID)
  123.             throw new System.ArgumentException("Invalid array size");
  124.  
  125.         m_bytes = new byte[NUM_BYTES_IN_GUID];
  126.         guidBytes.CopyTo(m_bytes, 0);
  127.     }
  128.  
  129.  
  130.     public SqlGuid(System.Guid g)
  131.     {
  132.         m_bytes = g.ToByteArray();
  133.     }
  134.  
  135.  
  136.     public byte[] ToByteArray()
  137.     {
  138.         byte[] ret = new byte[NUM_BYTES_IN_GUID];
  139.         m_bytes.CopyTo(ret, 0);
  140.         return ret;
  141.     }
  142.  
  143.     int CompareTo(object obj)
  144.     {
  145.         if (obj == null)
  146.             return 1; // https://msdn.microsoft.com/en-us/library/system.icomparable.compareto(v=vs.110).aspx
  147.  
  148.         System.Type t = obj.GetType();
  149.  
  150.         if (object.ReferenceEquals(t, typeof(System.DBNull)))
  151.             return 1;
  152.  
  153.         if (object.ReferenceEquals(t, typeof(SqlGuid)))
  154.         {
  155.             SqlGuid ui = (SqlGuid)obj;
  156.             return this.Compare(this, ui);
  157.         } // End if (object.ReferenceEquals(t, typeof(UInt128)))
  158.  
  159.         return 1;
  160.     } // End Function CompareTo(object obj)
  161.  
  162.  
  163.     int System.IComparable.CompareTo(object obj)
  164.     {
  165.         return this.CompareTo(obj);
  166.     }
  167.  
  168.  
  169.     int CompareTo(SqlGuid other)
  170.     {
  171.         return this.Compare(this, other);
  172.     }
  173.  
  174.  
  175.     int System.IComparable<SqlGuid>.CompareTo(SqlGuid other)
  176.     {
  177.         return this.Compare(this, other);
  178.     }
  179.  
  180.  
  181.     enum EComparison : int
  182.     {
  183.         LT = -1, // itemA precedes itemB in the sort order.
  184.         EQ = 0, // itemA occurs in the same position as itemB in the sort order.
  185.         GT = 1 // itemA follows itemB in the sort order.
  186.     }
  187.  
  188.  
  189.     public int Compare(SqlGuid x, SqlGuid y)
  190.     {
  191.         byte byte1, byte2;
  192.  
  193.         //Swap to the correct order to be compared
  194.         for (int i = 0; i < NUM_BYTES_IN_GUID; i++)
  195.         {
  196.             byte1 = x.m_bytes[m_byteOrder[i]];
  197.             byte2 = y.m_bytes[m_byteOrder[i]];
  198.             if (byte1 != byte2)
  199.                 return (byte1 < byte2) ?  (int) EComparison.LT : (int) EComparison.GT;
  200.         } // Next i
  201.  
  202.         return (int) EComparison.EQ;
  203.     }
  204.  
  205.  
  206.     int System.Collections.Generic.IComparer<SqlGuid>.Compare(SqlGuid x, SqlGuid y)
  207.     {
  208.         return this.Compare(x, y);
  209.     }
  210.  
  211.  
  212.     public bool Equals(SqlGuid other)
  213.     {
  214.         return Compare(this, other) == 0;
  215.     }
  216.  
  217.  
  218.     bool System.IEquatable<SqlGuid>.Equals(SqlGuid other)
  219.     {
  220.         return this.Equals(other);
  221.     }
  222.  
  223.  
  224. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top