mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Added equality and comparison overrides to Partition struct.
This commit is contained in:
@@ -30,12 +30,14 @@
|
|||||||
// Copyright © 2011-2017 Natalia Portillo
|
// Copyright © 2011-2017 Natalia Portillo
|
||||||
// ****************************************************************************/
|
// ****************************************************************************/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace DiscImageChef.CommonTypes
|
namespace DiscImageChef.CommonTypes
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Partition structure.
|
/// Partition structure.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct Partition
|
public struct Partition : IEquatable<Partition>, IComparable<Partition>
|
||||||
{
|
{
|
||||||
/// <summary>Partition number, 0-started</summary>
|
/// <summary>Partition number, 0-started</summary>
|
||||||
public ulong Sequence;
|
public ulong Sequence;
|
||||||
@@ -57,6 +59,71 @@ namespace DiscImageChef.CommonTypes
|
|||||||
public ulong End { get { return Start + Length - 1; }}
|
public ulong End { get { return Start + Length - 1; }}
|
||||||
/// <summary>Name of partition scheme that contains this partition</summary>
|
/// <summary>Name of partition scheme that contains this partition</summary>
|
||||||
public string Scheme;
|
public string Scheme;
|
||||||
|
|
||||||
|
public bool Equals(Partition other)
|
||||||
|
{
|
||||||
|
return Start == other.Start && Length == other.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(Object obj)
|
||||||
|
{
|
||||||
|
if(obj == null || !(obj is Partition))
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return Equals((Partition)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Start.GetHashCode() + End.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CompareTo(Partition other)
|
||||||
|
{
|
||||||
|
if(Start == other.Start && End == other.End)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if(Start > other.Start || End > other.End)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the equality operator.
|
||||||
|
public static bool operator ==(Partition operand1, Partition operand2)
|
||||||
|
{
|
||||||
|
return operand1.Equals(operand2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the inequality operator.
|
||||||
|
public static bool operator !=(Partition operand1, Partition operand2)
|
||||||
|
{
|
||||||
|
return !operand1.Equals(operand2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the is greater than operator.
|
||||||
|
public static bool operator >(Partition operand1, Partition operand2)
|
||||||
|
{
|
||||||
|
return operand1.CompareTo(operand2) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the is less than operator.
|
||||||
|
public static bool operator <(Partition operand1, Partition operand2)
|
||||||
|
{
|
||||||
|
return operand1.CompareTo(operand2) == -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the is greater than or equal to operator.
|
||||||
|
public static bool operator >=(Partition operand1, Partition operand2)
|
||||||
|
{
|
||||||
|
return operand1.CompareTo(operand2) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the is less than or equal to operator.
|
||||||
|
public static bool operator <=(Partition operand1, Partition operand2)
|
||||||
|
{
|
||||||
|
return operand1.CompareTo(operand2) <= 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ namespace DiscImageChef.Core
|
|||||||
|
|
||||||
foreach(Partition child in childs)
|
foreach(Partition child in childs)
|
||||||
{
|
{
|
||||||
if(child.Start == father.Start)
|
if(child == father)
|
||||||
childPartitions.Add(father);
|
childPartitions.Add(father);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user