Commit ee7576fa authored by Nick Craver's avatar Nick Craver

Cleanup: SortedSetEntry

parent 343d1345
...@@ -4,10 +4,6 @@ ...@@ -4,10 +4,6 @@
namespace StackExchange.Redis namespace StackExchange.Redis
{ {
/// <summary> /// <summary>
/// Describes a sorted-set element with the corresponding value /// Describes a sorted-set element with the corresponding value
/// </summary> /// </summary>
...@@ -17,13 +13,16 @@ public struct SortedSetEntry : IEquatable<SortedSetEntry>, IComparable, ICompara ...@@ -17,13 +13,16 @@ public struct SortedSetEntry : IEquatable<SortedSetEntry>, IComparable, ICompara
internal readonly double score; internal readonly double score;
/// <summary> /// <summary>
/// Initializes a SortedSetEntry value /// Initializes a <see cref="SortedSetEntry"/> value.
/// </summary> /// </summary>
/// <param name="element">The <see cref="RedisValue"/> to get an entry for.</param>
/// <param name="score">The redis score for <paramref name="element"/>.</param>
public SortedSetEntry(RedisValue element, double score) public SortedSetEntry(RedisValue element, double score)
{ {
this.element = element; this.element = element;
this.score = score; this.score = score;
} }
/// <summary> /// <summary>
/// The unique element stored in the sorted set /// The unique element stored in the sorted set
/// </summary> /// </summary>
...@@ -51,78 +50,61 @@ public SortedSetEntry(RedisValue element, double score) ...@@ -51,78 +50,61 @@ public SortedSetEntry(RedisValue element, double score)
/// <summary> /// <summary>
/// Converts to a key/value pair /// Converts to a key/value pair
/// </summary> /// </summary>
public static implicit operator KeyValuePair<RedisValue,double>(SortedSetEntry value) /// <param name="value">The <see cref="SortedSetEntry"/> to get a <see cref="KeyValuePair{TKey, TValue}"/> for.</param>
{ public static implicit operator KeyValuePair<RedisValue, double>(SortedSetEntry value) => new KeyValuePair<RedisValue, double>(value.element, value.score);
return new KeyValuePair<RedisValue, double>(value.element, value.score);
}
/// <summary> /// <summary>
/// Converts from a key/value pair /// Converts from a key/value pair
/// </summary> /// </summary>
public static implicit operator SortedSetEntry(KeyValuePair<RedisValue, double> value) /// <param name="value">The <see cref="KeyValuePair{TKey, TValue}"/> to get a <see cref="SortedSetEntry"/> for.</param>
{ public static implicit operator SortedSetEntry(KeyValuePair<RedisValue, double> value) => new SortedSetEntry(value.Key, value.Value);
return new SortedSetEntry(value.Key, value.Value);
}
/// <summary> /// <summary>
/// See Object.ToString() /// See Object.ToString()
/// </summary> /// </summary>
public override string ToString() public override string ToString() => element + ": " + score;
{
return element + ": " + score;
}
/// <summary> /// <summary>
/// See Object.GetHashCode() /// See Object.GetHashCode()
/// </summary> /// </summary>
public override int GetHashCode() public override int GetHashCode() => element.GetHashCode() ^ score.GetHashCode();
{
return element.GetHashCode() ^ score.GetHashCode();
}
/// <summary> /// <summary>
/// Compares two values for equality /// Compares two values for equality
/// </summary> /// </summary>
public override bool Equals(object obj) /// <param name="obj">The <see cref="SortedSetEntry"/> to compare to.</param>
{ public override bool Equals(object obj) => obj is SortedSetEntry ssObj && Equals(ssObj);
return obj is SortedSetEntry && Equals((SortedSetEntry)obj);
}
/// <summary> /// <summary>
/// Compares two values for equality /// Compares two values for equality
/// </summary> /// </summary>
public bool Equals(SortedSetEntry other) /// <param name="other">The <see cref="SortedSetEntry"/> to compare to.</param>
{ public bool Equals(SortedSetEntry other) => score == other.score && element == other.element;
return score == other.score && element == other.element;
}
/// <summary> /// <summary>
/// Compares two values by score /// Compares two values by score
/// </summary> /// </summary>
public int CompareTo(SortedSetEntry other) /// <param name="other">The <see cref="SortedSetEntry"/> to compare to.</param>
{ public int CompareTo(SortedSetEntry other) => score.CompareTo(other.score);
return score.CompareTo(other.score);
}
/// <summary> /// <summary>
/// Compares two values by score /// Compares two values by score
/// </summary> /// </summary>
public int CompareTo(object obj) /// <param name="obj">The <see cref="SortedSetEntry"/> to compare to.</param>
{ public int CompareTo(object obj) => obj is SortedSetEntry ssObj ? CompareTo(ssObj) : -1;
return obj is SortedSetEntry ? CompareTo((SortedSetEntry)obj) : -1;
}
/// <summary> /// <summary>
/// Compares two values for equality /// Compares two values for equality
/// </summary> /// </summary>
public static bool operator ==(SortedSetEntry x, SortedSetEntry y) /// <param name="x">The first <see cref="SortedSetEntry"/> to compare.</param>
{ /// <param name="y">The second <see cref="SortedSetEntry"/> to compare.</param>
return x.score == y.score && x.element == y.element; public static bool operator ==(SortedSetEntry x, SortedSetEntry y) => x.score == y.score && x.element == y.element;
}
/// <summary> /// <summary>
/// Compares two values for non-equality /// Compares two values for non-equality
/// </summary> /// </summary>
public static bool operator !=(SortedSetEntry x, SortedSetEntry y) /// <param name="x">The first <see cref="SortedSetEntry"/> to compare.</param>
{ /// <param name="y">The second <see cref="SortedSetEntry"/> to compare.</param>
return x.score != y.score || x.element != y.element; public static bool operator !=(SortedSetEntry x, SortedSetEntry y) => x.score != y.score || x.element != y.element;
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment