Fix extents creation from a list of extents to prevent overlapping extents to be added.

This commit is contained in:
2021-04-27 13:19:31 +01:00
parent 5e8a79d678
commit 493ba5dd4c
8 changed files with 70 additions and 14 deletions

View File

@@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents
/// <summary>Initializes extents with an specific list</summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsByte(IEnumerable<Tuple<byte, byte>> list) => _backend = list.OrderBy(t => t.Item1).ToList();
public ExtentsByte(IEnumerable<Tuple<byte, byte>> list)
{
_backend = new List<Tuple<byte, byte>>();
// This ensure no overlapping extents are added on creation
foreach(Tuple<byte, byte> t in list)
Add(t.Item1, t.Item2);
}
/// <summary>Gets a count of how many extents are stored</summary>
public int Count => _backend.Count;

View File

@@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents
/// <summary>Initializes extents with an specific list</summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsInt(IEnumerable<Tuple<int, int>> list) => _backend = list.OrderBy(t => t.Item1).ToList();
public ExtentsInt(IEnumerable<Tuple<int, int>> list)
{
_backend = new List<Tuple<int, int>>();
// This ensure no overlapping extents are added on creation
foreach(Tuple<int, int> t in list)
Add(t.Item1, t.Item2);
}
/// <summary>Gets a count of how many extents are stored</summary>
public int Count => _backend.Count;

View File

@@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents
/// <summary>Initializes extents with an specific list</summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsLong(IEnumerable<Tuple<long, long>> list) => _backend = list.OrderBy(t => t.Item1).ToList();
public ExtentsLong(IEnumerable<Tuple<long, long>> list)
{
_backend = new List<Tuple<long, long>>();
// This ensure no overlapping extents are added on creation
foreach(Tuple<long, long> t in list)
Add(t.Item1, t.Item2);
}
/// <summary>Gets a count of how many extents are stored</summary>
public int Count => _backend.Count;

View File

@@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents
/// <summary>Initializes extents with an specific list</summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsSByte(IEnumerable<Tuple<sbyte, sbyte>> list) => _backend = list.OrderBy(t => t.Item1).ToList();
public ExtentsSByte(IEnumerable<Tuple<sbyte, sbyte>> list)
{
_backend = new List<Tuple<sbyte, sbyte>>();
// This ensure no overlapping extents are added on creation
foreach(Tuple<sbyte, sbyte> t in list)
Add(t.Item1, t.Item2);
}
/// <summary>Gets a count of how many extents are stored</summary>
public int Count => _backend.Count;
@@ -234,8 +241,8 @@ namespace Aaru.CommonTypes.Extents
{
start = 0;
foreach(Tuple<sbyte, sbyte> extent in _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)
)
foreach(Tuple<sbyte, sbyte> extent in
_backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
{
start = extent.Item1;

View File

@@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents
/// <summary>Initializes extents with an specific list</summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsShort(IEnumerable<Tuple<short, short>> list) => _backend = list.OrderBy(t => t.Item1).ToList();
public ExtentsShort(IEnumerable<Tuple<short, short>> list)
{
_backend = new List<Tuple<short, short>>();
// This ensure no overlapping extents are added on creation
foreach(Tuple<short, short> t in list)
Add(t.Item1, t.Item2);
}
/// <summary>Gets a count of how many extents are stored</summary>
public int Count => _backend.Count;
@@ -234,8 +241,8 @@ namespace Aaru.CommonTypes.Extents
{
start = 0;
foreach(Tuple<short, short> extent in _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)
)
foreach(Tuple<short, short> extent in
_backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
{
start = extent.Item1;

View File

@@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents
/// <summary>Initializes extents with an specific list</summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsUInt(IEnumerable<Tuple<uint, uint>> list) => _backend = list.OrderBy(t => t.Item1).ToList();
public ExtentsUInt(IEnumerable<Tuple<uint, uint>> list)
{
_backend = new List<Tuple<uint, uint>>();
// This ensure no overlapping extents are added on creation
foreach(Tuple<uint, uint> t in list)
Add(t.Item1, t.Item2);
}
/// <summary>Gets a count of how many extents are stored</summary>
public int Count => _backend.Count;

View File

@@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents
/// <summary>Initializes extents with an specific list</summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsULong(IEnumerable<Tuple<ulong, ulong>> list) => _backend = list.OrderBy(t => t.Item1).ToList();
public ExtentsULong(IEnumerable<Tuple<ulong, ulong>> list)
{
_backend = new List<Tuple<ulong, ulong>>();
// This ensure no overlapping extents are added on creation
foreach(Tuple<ulong, ulong> t in list)
Add(t.Item1, t.Item2);
}
/// <summary>Gets a count of how many extents are stored</summary>
public int Count => _backend.Count;
@@ -234,8 +241,8 @@ namespace Aaru.CommonTypes.Extents
{
start = 0;
foreach(Tuple<ulong, ulong> extent in _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)
)
foreach(Tuple<ulong, ulong> extent in
_backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
{
start = extent.Item1;

View File

@@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents
/// <summary>Initializes extents with an specific list</summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsUShort(IEnumerable<Tuple<ushort, ushort>> list) => _backend = list.OrderBy(t => t.Item1).ToList();
public ExtentsUShort(IEnumerable<Tuple<ushort, ushort>> list)
{
_backend = new List<Tuple<ushort, ushort>>();
// This ensure no overlapping extents are added on creation
foreach(Tuple<ushort, ushort> t in list)
Add(t.Item1, t.Item2);
}
/// <summary>Gets a count of how many extents are stored</summary>
public int Count => _backend.Count;