Repository navigation
Expand file tree
/
Copy pathPosition.cs
More file actions
164 lines (149 loc) · 6.07 KB
/
Copy pathPosition.cs
File metadata and controls
164 lines (149 loc) · 6.07 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using System;
namespace EventStore.ClientAPI
{
/// <summary>
/// A structure referring to a potential logical record position
/// in the Event Store transaction file.
/// </summary>
public struct Position
{
/// <summary>
/// Position representing the start of the transaction file
/// </summary>
public static readonly Position Start = new Position(0, 0);
/// <summary>
/// Position representing the end of the transaction file
/// </summary>
public static readonly Position End = new Position(-1, -1);
/// <summary>
/// The commit position of the record
/// </summary>
public readonly long CommitPosition;
/// <summary>
/// The prepare position of the record.
/// </summary>
public readonly long PreparePosition;
/// <summary>
/// Constructs a position with the given commit and prepare positions.
/// It is not guaranteed that the position is actually the start of a
/// record in the transaction file.
///
/// The commit position cannot be less than the prepare position.
/// </summary>
/// <param name="commitPosition">The commit position of the record.</param>
/// <param name="preparePosition">The prepare position of the record.</param>
public Position(long commitPosition, long preparePosition)
{
if (commitPosition < preparePosition)
throw new ArgumentException("The commit position cannot be less than the prepare position", "commitPosition");
CommitPosition = commitPosition;
PreparePosition = preparePosition;
}
/// <summary>
/// Compares whether p1 < p2.
/// </summary>
/// <param name="p1">A <see cref="Position" />.</param>
/// <param name="p2">A <see cref="Position" />.</param>
/// <returns>True if p1 < p2.</returns>
public static bool operator <(Position p1, Position p2)
{
return p1.CommitPosition < p2.CommitPosition || (p1.CommitPosition == p2.CommitPosition && p1.PreparePosition < p2.PreparePosition);
}
/// <summary>
/// Compares whether p1 > p2.
/// </summary>
/// <param name="p1">A <see cref="Position" />.</param>
/// <param name="p2">A <see cref="Position" />.</param>
/// <returns>True if p1 > p2.</returns>
public static bool operator >(Position p1, Position p2)
{
return p1.CommitPosition > p2.CommitPosition || (p1.CommitPosition == p2.CommitPosition && p1.PreparePosition > p2.PreparePosition);
}
/// <summary>
/// Compares whether p1 >= p2.
/// </summary>
/// <param name="p1">A <see cref="Position" />.</param>
/// <param name="p2">A <see cref="Position" />.</param>
/// <returns>True if p1 >= p2.</returns>
public static bool operator >=(Position p1, Position p2)
{
return p1 > p2 || p1 == p2;
}
/// <summary>
/// Compares whether p1 <= p2.
/// </summary>
/// <param name="p1">A <see cref="Position" />.</param>
/// <param name="p2">A <see cref="Position" />.</param>
/// <returns>True if p1 <= p2.</returns>
public static bool operator <=(Position p1, Position p2)
{
return p1 < p2 || p1 == p2;
}
/// <summary>
/// Compares p1 and p2 for equality.
/// </summary>
/// <param name="p1">A <see cref="Position" />.</param>
/// <param name="p2">A <see cref="Position" />.</param>
/// <returns>True if p1 is equal to p2.</returns>
public static bool operator ==(Position p1, Position p2)
{
return p1.CommitPosition == p2.CommitPosition && p1.PreparePosition == p2.PreparePosition;
}
/// <summary>
/// Compares p1 and p2 for equality.
/// </summary>
/// <param name="p1">A <see cref="Position" />.</param>
/// <param name="p2">A <see cref="Position" />.</param>
/// <returns>True if p1 is not equal to p2.</returns>
public static bool operator !=(Position p1, Position p2)
{
return !(p1 == p2);
}
/// <summary>
/// Indicates whether this instance and a specified object are equal.
/// </summary>
/// <returns>
/// true if <paramref name="obj"/> and this instance are the same type and represent the same value; otherwise, false.
/// </returns>
/// <param name="obj">Another object to compare to. </param><filterpriority>2</filterpriority>
public override bool Equals(object obj)
{
return obj is Position && Equals((Position)obj);
}
/// <summary>
/// Compares this instance of <see cref="Position" /> for equality
/// with another instance.
/// </summary>
/// <param name="other">A <see cref="Position" /></param>
/// <returns>True if this instance is equal to the other instance.</returns>
public bool Equals(Position other)
{
return this == other;
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
/// <filterpriority>2</filterpriority>
public override int GetHashCode()
{
unchecked
{
return (CommitPosition.GetHashCode()*397) ^ PreparePosition.GetHashCode();
}
}
/// <summary>
/// Returns the fully qualified type name of this instance.
/// </summary>
/// <returns>
/// A <see cref="T:System.String"/> containing a fully qualified type name.
/// </returns>
/// <filterpriority>2</filterpriority>
public override string ToString()
{
return string.Format("{0}/{1}", CommitPosition, PreparePosition);
}
}
}