From 493ba5dd4c14994bbc32630feae63ae7bd7d0ed8 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 27 Apr 2021 13:19:31 +0100 Subject: [PATCH] Fix extents creation from a list of extents to prevent overlapping extents to be added. --- Extents/ExtentsByte.cs | 9 ++++++++- Extents/ExtentsInt.cs | 9 ++++++++- Extents/ExtentsLong.cs | 9 ++++++++- Extents/ExtentsSByte.cs | 13 ++++++++++--- Extents/ExtentsShort.cs | 13 ++++++++++--- Extents/ExtentsUInt.cs | 9 ++++++++- Extents/ExtentsULong.cs | 13 ++++++++++--- Extents/ExtentsUShort.cs | 9 ++++++++- 8 files changed, 70 insertions(+), 14 deletions(-) diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs index f5a3c883f..4ecdc3dba 100644 --- a/Extents/ExtentsByte.cs +++ b/Extents/ExtentsByte.cs @@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents /// Initializes extents with an specific list /// List of extents as tuples "start, end" - public ExtentsByte(IEnumerable> list) => _backend = list.OrderBy(t => t.Item1).ToList(); + public ExtentsByte(IEnumerable> list) + { + _backend = new List>(); + + // This ensure no overlapping extents are added on creation + foreach(Tuple t in list) + Add(t.Item1, t.Item2); + } /// Gets a count of how many extents are stored public int Count => _backend.Count; diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs index 78dba695d..66c12b035 100644 --- a/Extents/ExtentsInt.cs +++ b/Extents/ExtentsInt.cs @@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents /// Initializes extents with an specific list /// List of extents as tuples "start, end" - public ExtentsInt(IEnumerable> list) => _backend = list.OrderBy(t => t.Item1).ToList(); + public ExtentsInt(IEnumerable> list) + { + _backend = new List>(); + + // This ensure no overlapping extents are added on creation + foreach(Tuple t in list) + Add(t.Item1, t.Item2); + } /// Gets a count of how many extents are stored public int Count => _backend.Count; diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs index 606b96508..eb1e351cc 100644 --- a/Extents/ExtentsLong.cs +++ b/Extents/ExtentsLong.cs @@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents /// Initializes extents with an specific list /// List of extents as tuples "start, end" - public ExtentsLong(IEnumerable> list) => _backend = list.OrderBy(t => t.Item1).ToList(); + public ExtentsLong(IEnumerable> list) + { + _backend = new List>(); + + // This ensure no overlapping extents are added on creation + foreach(Tuple t in list) + Add(t.Item1, t.Item2); + } /// Gets a count of how many extents are stored public int Count => _backend.Count; diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs index faffcc271..c7a6d0ba2 100644 --- a/Extents/ExtentsSByte.cs +++ b/Extents/ExtentsSByte.cs @@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents /// Initializes extents with an specific list /// List of extents as tuples "start, end" - public ExtentsSByte(IEnumerable> list) => _backend = list.OrderBy(t => t.Item1).ToList(); + public ExtentsSByte(IEnumerable> list) + { + _backend = new List>(); + + // This ensure no overlapping extents are added on creation + foreach(Tuple t in list) + Add(t.Item1, t.Item2); + } /// Gets a count of how many extents are stored public int Count => _backend.Count; @@ -234,8 +241,8 @@ namespace Aaru.CommonTypes.Extents { start = 0; - foreach(Tuple extent in _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2) - ) + foreach(Tuple extent in + _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { start = extent.Item1; diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs index b80f0f846..360ca96ef 100644 --- a/Extents/ExtentsShort.cs +++ b/Extents/ExtentsShort.cs @@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents /// Initializes extents with an specific list /// List of extents as tuples "start, end" - public ExtentsShort(IEnumerable> list) => _backend = list.OrderBy(t => t.Item1).ToList(); + public ExtentsShort(IEnumerable> list) + { + _backend = new List>(); + + // This ensure no overlapping extents are added on creation + foreach(Tuple t in list) + Add(t.Item1, t.Item2); + } /// Gets a count of how many extents are stored public int Count => _backend.Count; @@ -234,8 +241,8 @@ namespace Aaru.CommonTypes.Extents { start = 0; - foreach(Tuple extent in _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2) - ) + foreach(Tuple extent in + _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { start = extent.Item1; diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs index cc13a00b6..c70167fb4 100644 --- a/Extents/ExtentsUInt.cs +++ b/Extents/ExtentsUInt.cs @@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents /// Initializes extents with an specific list /// List of extents as tuples "start, end" - public ExtentsUInt(IEnumerable> list) => _backend = list.OrderBy(t => t.Item1).ToList(); + public ExtentsUInt(IEnumerable> list) + { + _backend = new List>(); + + // This ensure no overlapping extents are added on creation + foreach(Tuple t in list) + Add(t.Item1, t.Item2); + } /// Gets a count of how many extents are stored public int Count => _backend.Count; diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs index 8b726eec0..cf38227dc 100644 --- a/Extents/ExtentsULong.cs +++ b/Extents/ExtentsULong.cs @@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents /// Initializes extents with an specific list /// List of extents as tuples "start, end" - public ExtentsULong(IEnumerable> list) => _backend = list.OrderBy(t => t.Item1).ToList(); + public ExtentsULong(IEnumerable> list) + { + _backend = new List>(); + + // This ensure no overlapping extents are added on creation + foreach(Tuple t in list) + Add(t.Item1, t.Item2); + } /// Gets a count of how many extents are stored public int Count => _backend.Count; @@ -234,8 +241,8 @@ namespace Aaru.CommonTypes.Extents { start = 0; - foreach(Tuple extent in _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2) - ) + foreach(Tuple extent in + _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { start = extent.Item1; diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs index e6d663da3..89e128155 100644 --- a/Extents/ExtentsUShort.cs +++ b/Extents/ExtentsUShort.cs @@ -52,7 +52,14 @@ namespace Aaru.CommonTypes.Extents /// Initializes extents with an specific list /// List of extents as tuples "start, end" - public ExtentsUShort(IEnumerable> list) => _backend = list.OrderBy(t => t.Item1).ToList(); + public ExtentsUShort(IEnumerable> list) + { + _backend = new List>(); + + // This ensure no overlapping extents are added on creation + foreach(Tuple t in list) + Add(t.Item1, t.Item2); + } /// Gets a count of how many extents are stored public int Count => _backend.Count;