diff --git a/Delegates.cs b/Delegates.cs
index 454c7c95f..357142152 100644
--- a/Delegates.cs
+++ b/Delegates.cs
@@ -30,61 +30,60 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
-namespace Aaru.CommonTypes
-{
- /// Initializes a progress indicator (e.g. makes a progress bar visible)
- public delegate void InitProgressHandler();
+namespace Aaru.CommonTypes;
- /// Updates a progress indicator with text
- public delegate void UpdateProgressHandler(string text, long current, long maximum);
+/// Initializes a progress indicator (e.g. makes a progress bar visible)
+public delegate void InitProgressHandler();
- /// Pulses a progress indicator with indeterminate boundaries
- public delegate void PulseProgressHandler(string text);
+/// Updates a progress indicator with text
+public delegate void UpdateProgressHandler(string text, long current, long maximum);
- /// Uninitializes a progress indicator (e.g. adds a newline to the console)
- public delegate void EndProgressHandler();
+/// Pulses a progress indicator with indeterminate boundaries
+public delegate void PulseProgressHandler(string text);
- /// Initializes a secondary progress indicator (e.g. makes a progress bar visible)
- public delegate void InitProgressHandler2();
+/// Uninitializes a progress indicator (e.g. adds a newline to the console)
+public delegate void EndProgressHandler();
- /// Updates a secondary progress indicator with text
- public delegate void UpdateProgressHandler2(string text, long current, long maximum);
+/// Initializes a secondary progress indicator (e.g. makes a progress bar visible)
+public delegate void InitProgressHandler2();
- /// Pulses a secondary progress indicator with indeterminate boundaries
- public delegate void PulseProgressHandler2(string text);
+/// Updates a secondary progress indicator with text
+public delegate void UpdateProgressHandler2(string text, long current, long maximum);
- /// Uninitializes a secondary progress indicator (e.g. adds a newline to the console)
- public delegate void EndProgressHandler2();
+/// Pulses a secondary progress indicator with indeterminate boundaries
+public delegate void PulseProgressHandler2(string text);
- /// Initializes two progress indicators (e.g. makes a progress bar visible)
- public delegate void InitTwoProgressHandler();
+/// Uninitializes a secondary progress indicator (e.g. adds a newline to the console)
+public delegate void EndProgressHandler2();
- /// Updates two progress indicators with text
- public delegate void UpdateTwoProgressHandler(string text, long current, long maximum, string text2, long current2,
- long maximum2);
+/// Initializes two progress indicators (e.g. makes a progress bar visible)
+public delegate void InitTwoProgressHandler();
- /// Pulses a progress indicator with indeterminate boundaries
- public delegate void PulseTwoProgressHandler(string text, string text2);
+/// Updates two progress indicators with text
+public delegate void UpdateTwoProgressHandler(string text, long current, long maximum, string text2, long current2,
+ long maximum2);
- /// Uninitializes a progress indicator (e.g. adds a newline to the console)
- public delegate void EndTwoProgressHandler();
+/// Pulses a progress indicator with indeterminate boundaries
+public delegate void PulseTwoProgressHandler(string text, string text2);
- /// Updates a status indicator
- public delegate void UpdateStatusHandler(string text);
+/// Uninitializes a progress indicator (e.g. adds a newline to the console)
+public delegate void EndTwoProgressHandler();
- /// Shows an error message
- public delegate void ErrorMessageHandler(string text);
+/// Updates a status indicator
+public delegate void UpdateStatusHandler(string text);
- /// Initializes a block map that's going to be filled with a media scan
- public delegate void InitBlockMapHandler(ulong blocks, ulong blockSize, ulong blocksToRead, ushort currentProfile);
+/// Shows an error message
+public delegate void ErrorMessageHandler(string text);
- /// Updates lists of time taken on scanning from the specified sector
- /// Time in milliseconds
- public delegate void ScanTimeHandler(ulong sector, double duration);
+/// Initializes a block map that's going to be filled with a media scan
+public delegate void InitBlockMapHandler(ulong blocks, ulong blockSize, ulong blocksToRead, ushort currentProfile);
- /// Specified a number of blocks could not be read on scan
- public delegate void ScanUnreadableHandler(ulong sector);
+/// Updates lists of time taken on scanning from the specified sector
+/// Time in milliseconds
+public delegate void ScanTimeHandler(ulong sector, double duration);
- /// Sends the speed of scanning a specific sector
- public delegate void ScanSpeedHandler(ulong sector, double currentSpeed);
-}
\ No newline at end of file
+/// Specified a number of blocks could not be read on scan
+public delegate void ScanUnreadableHandler(ulong sector);
+
+/// Sends the speed of scanning a specific sector
+public delegate void ScanSpeedHandler(ulong sector, double currentSpeed);
\ No newline at end of file
diff --git a/Enums/DeviceType.cs b/Enums/DeviceType.cs
index 7c7b32ff9..f4ae1c326 100644
--- a/Enums/DeviceType.cs
+++ b/Enums/DeviceType.cs
@@ -36,24 +36,23 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
-namespace Aaru.CommonTypes.Enums
+namespace Aaru.CommonTypes.Enums;
+
+/// Device types
+public enum DeviceType
{
- /// Device types
- public enum DeviceType
- {
- /// Unknown device type
- Unknown = -1,
- /// ATA device
- ATA = 1,
- /// ATA Packet device (aka SCSI over ATA)
- ATAPI = 2,
- /// SCSI device (or USB-MSC, SBP2, FC, UAS, etc)
- SCSI = 3,
- /// SecureDigital memory card
- SecureDigital = 4,
- /// MultiMediaCard memory card
- MMC = 5,
- /// NVMe device
- NVMe = 6
- }
+ /// Unknown device type
+ Unknown = -1,
+ /// ATA device
+ ATA = 1,
+ /// ATA Packet device (aka SCSI over ATA)
+ ATAPI = 2,
+ /// SCSI device (or USB-MSC, SBP2, FC, UAS, etc)
+ SCSI = 3,
+ /// SecureDigital memory card
+ SecureDigital = 4,
+ /// MultiMediaCard memory card
+ MMC = 5,
+ /// NVMe device
+ NVMe = 6
}
\ No newline at end of file
diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs
index e74a81691..cb388b9d6 100644
--- a/Extents/ExtentsByte.cs
+++ b/Extents/ExtentsByte.cs
@@ -40,215 +40,214 @@ using System;
using System.Collections.Generic;
using System.Linq;
-namespace Aaru.CommonTypes.Extents
+namespace Aaru.CommonTypes.Extents;
+
+/// Implements extents for
+public class ExtentsByte
{
- /// Implements extents for
- public class ExtentsByte
+ List> _backend;
+
+ /// Initialize an empty list of extents
+ public ExtentsByte() => _backend = new List>();
+
+ /// Initializes extents with an specific list
+ /// List of extents as tuples "start, end"
+ public ExtentsByte(IEnumerable> list)
{
- List> _backend;
+ _backend = new List>();
- /// Initialize an empty list of extents
- public ExtentsByte() => _backend = new List>();
+ // This ensure no overlapping extents are added on creation
+ foreach(Tuple t in list)
+ Add(t.Item1, t.Item2);
+ }
- /// Initializes extents with an specific list
- /// List of extents as tuples "start, end"
- public ExtentsByte(IEnumerable> list)
+ /// Gets a count of how many extents are stored
+ public int Count => _backend.Count;
+
+ /// Adds the specified number to the corresponding extent, or creates a new one
+ ///
+ public void Add(byte item)
+ {
+ Tuple removeOne = null;
+ Tuple removeTwo = null;
+ Tuple itemToAdd = null;
+
+ for(int i = 0; i < _backend.Count; i++)
{
- _backend = new List>();
+ // Already contained in an extent
+ if(item >= _backend[i].Item1 &&
+ item <= _backend[i].Item2)
+ return;
- // 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;
-
- /// Adds the specified number to the corresponding extent, or creates a new one
- ///
- public void Add(byte item)
- {
- Tuple removeOne = null;
- Tuple removeTwo = null;
- Tuple itemToAdd = null;
-
- for(int i = 0; i < _backend.Count; i++)
+ // Expands existing extent start
+ if(item == _backend[i].Item1 - 1)
{
- // Already contained in an extent
- if(item >= _backend[i].Item1 &&
- item <= _backend[i].Item2)
- return;
-
- // Expands existing extent start
- if(item == _backend[i].Item1 - 1)
- {
- removeOne = _backend[i];
-
- if(i > 0 &&
- item == _backend[i - 1].Item2 + 1)
- {
- removeTwo = _backend[i - 1];
- itemToAdd = new Tuple(_backend[i - 1].Item1, _backend[i].Item2);
- }
- else
- itemToAdd = new Tuple(item, _backend[i].Item2);
-
- break;
- }
-
- // Expands existing extent end
- if(item != _backend[i].Item2 + 1)
- continue;
-
removeOne = _backend[i];
- if(i < _backend.Count - 1 &&
- item == _backend[i + 1].Item1 - 1)
+ if(i > 0 &&
+ item == _backend[i - 1].Item2 + 1)
{
- removeTwo = _backend[i + 1];
- itemToAdd = new Tuple(_backend[i].Item1, _backend[i + 1].Item2);
+ removeTwo = _backend[i - 1];
+ itemToAdd = new Tuple(_backend[i - 1].Item1, _backend[i].Item2);
}
else
- itemToAdd = new Tuple(_backend[i].Item1, item);
+ itemToAdd = new Tuple(item, _backend[i].Item2);
break;
}
- if(itemToAdd != null)
+ // Expands existing extent end
+ if(item != _backend[i].Item2 + 1)
+ continue;
+
+ removeOne = _backend[i];
+
+ if(i < _backend.Count - 1 &&
+ item == _backend[i + 1].Item1 - 1)
{
- _backend.Remove(removeOne);
- _backend.Remove(removeTwo);
- _backend.Add(itemToAdd);
+ removeTwo = _backend[i + 1];
+ itemToAdd = new Tuple(_backend[i].Item1, _backend[i + 1].Item2);
}
else
- _backend.Add(new Tuple(item, item));
+ itemToAdd = new Tuple(_backend[i].Item1, item);
- // Sort
- _backend = _backend.OrderBy(t => t.Item1).ToList();
+ break;
}
- /// Adds a new extent
- /// First element of the extent
- ///
- /// Last element of the extent or if is true how many elements the extent runs
- /// for
- ///
- /// If set to true, indicates how many elements the extent runs for
- public void Add(byte start, byte end, bool run = false)
+ if(itemToAdd != null)
{
- byte realEnd;
-
- if(run)
- realEnd = (byte)(start + end - 1);
- else
- realEnd = end;
-
- // TODO: Optimize this
- for(byte t = start; t <= realEnd; t++)
- Add(t);
+ _backend.Remove(removeOne);
+ _backend.Remove(removeTwo);
+ _backend.Add(itemToAdd);
}
+ else
+ _backend.Add(new Tuple(item, item));
- /// Checks if the specified item is contained by an extent on this instance
- /// Item to search for
- /// true if any of the extents on this instance contains the item
- public bool Contains(byte item) => _backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
+ // Sort
+ _backend = _backend.OrderBy(t => t.Item1).ToList();
+ }
- /// Removes all extents from this instance
- public void Clear() => _backend.Clear();
+ /// Adds a new extent
+ /// First element of the extent
+ ///
+ /// Last element of the extent or if is true how many elements the extent runs
+ /// for
+ ///
+ /// If set to true, indicates how many elements the extent runs for
+ public void Add(byte start, byte end, bool run = false)
+ {
+ byte realEnd;
- /// Removes an item from the extents in this instance
- /// Item to remove
- /// true if the item was contained in a known extent and removed, false otherwise
- public bool Remove(byte item)
+ if(run)
+ realEnd = (byte)(start + end - 1);
+ else
+ realEnd = end;
+
+ // TODO: Optimize this
+ for(byte t = start; t <= realEnd; t++)
+ Add(t);
+ }
+
+ /// Checks if the specified item is contained by an extent on this instance
+ /// Item to search for
+ /// true if any of the extents on this instance contains the item
+ public bool Contains(byte item) => _backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
+
+ /// Removes all extents from this instance
+ public void Clear() => _backend.Clear();
+
+ /// Removes an item from the extents in this instance
+ /// Item to remove
+ /// true if the item was contained in a known extent and removed, false otherwise
+ public bool Remove(byte item)
+ {
+ Tuple toRemove = null;
+ Tuple toAddOne = null;
+ Tuple toAddTwo = null;
+
+ foreach(Tuple extent in _backend)
{
- Tuple toRemove = null;
- Tuple toAddOne = null;
- Tuple toAddTwo = null;
-
- foreach(Tuple extent in _backend)
+ // Extent is contained and not a border
+ if(item > extent.Item1 &&
+ item < extent.Item2)
{
- // Extent is contained and not a border
- if(item > extent.Item1 &&
- item < extent.Item2)
- {
- toRemove = extent;
- toAddOne = new Tuple(extent.Item1, (byte)(item - 1));
- toAddTwo = new Tuple((byte)(item + 1), extent.Item2);
-
- break;
- }
-
- // Extent is left border, but not only element
- if(item == extent.Item1 &&
- item != extent.Item2)
- {
- toRemove = extent;
- toAddOne = new Tuple((byte)(item + 1), extent.Item2);
-
- break;
- }
-
- // Extent is right border, but not only element
- if(item != extent.Item1 &&
- item == extent.Item2)
- {
- toRemove = extent;
- toAddOne = new Tuple(extent.Item1, (byte)(item - 1));
-
- break;
- }
-
- // Extent is only element
- if(item != extent.Item1 ||
- item != extent.Item2)
- continue;
-
toRemove = extent;
+ toAddOne = new Tuple(extent.Item1, (byte)(item - 1));
+ toAddTwo = new Tuple((byte)(item + 1), extent.Item2);
break;
}
- // Item not found
- if(toRemove == null)
- return false;
+ // Extent is left border, but not only element
+ if(item == extent.Item1 &&
+ item != extent.Item2)
+ {
+ toRemove = extent;
+ toAddOne = new Tuple((byte)(item + 1), extent.Item2);
- _backend.Remove(toRemove);
+ break;
+ }
- if(toAddOne != null)
- _backend.Add(toAddOne);
+ // Extent is right border, but not only element
+ if(item != extent.Item1 &&
+ item == extent.Item2)
+ {
+ toRemove = extent;
+ toAddOne = new Tuple(extent.Item1, (byte)(item - 1));
- if(toAddTwo != null)
- _backend.Add(toAddTwo);
+ break;
+ }
- // Sort
- _backend = _backend.OrderBy(t => t.Item1).ToList();
+ // Extent is only element
+ if(item != extent.Item1 ||
+ item != extent.Item2)
+ continue;
+
+ toRemove = extent;
+
+ break;
+ }
+
+ // Item not found
+ if(toRemove == null)
+ return false;
+
+ _backend.Remove(toRemove);
+
+ if(toAddOne != null)
+ _backend.Add(toAddOne);
+
+ if(toAddTwo != null)
+ _backend.Add(toAddTwo);
+
+ // Sort
+ _backend = _backend.OrderBy(t => t.Item1).ToList();
+
+ return true;
+ }
+
+ ///
+ /// Converts the list of extents to an array of where T1 is first element of the extent and
+ /// T2 is last element
+ ///
+ /// Array of
+ public Tuple[] ToArray() => _backend.ToArray();
+
+ /// Gets the first element of the extent that contains the specified item
+ /// Item
+ /// First element of extent
+ /// true if item was found in an extent, false otherwise
+ public bool GetStart(byte item, out byte start)
+ {
+ start = 0;
+
+ foreach(Tuple extent in _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
+ {
+ start = extent.Item1;
return true;
}
- ///
- /// Converts the list of extents to an array of where T1 is first element of the extent and
- /// T2 is last element
- ///
- /// Array of
- public Tuple[] ToArray() => _backend.ToArray();
-
- /// Gets the first element of the extent that contains the specified item
- /// Item
- /// First element of extent
- /// true if item was found in an extent, false otherwise
- public bool GetStart(byte item, out byte start)
- {
- start = 0;
-
- foreach(Tuple extent in _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
- {
- start = extent.Item1;
-
- return true;
- }
-
- return false;
- }
+ return false;
}
}
\ No newline at end of file
diff --git a/Extents/ExtentsConverter.cs b/Extents/ExtentsConverter.cs
index dde75e6c7..f3a3ad7aa 100644
--- a/Extents/ExtentsConverter.cs
+++ b/Extents/ExtentsConverter.cs
@@ -41,44 +41,43 @@ using System.Collections.Generic;
using System.Linq;
using Schemas;
-namespace Aaru.CommonTypes.Extents
+namespace Aaru.CommonTypes.Extents;
+
+/// Converts extents
+public static class ExtentsConverter
{
- /// Converts extents
- public static class ExtentsConverter
+ /// Converts unsigned long integer extents into XML based extents
+ /// Extents
+ /// XML based extents
+ public static ExtentType[] ToMetadata(ExtentsULong extents)
{
- /// Converts unsigned long integer extents into XML based extents
- /// Extents
- /// XML based extents
- public static ExtentType[] ToMetadata(ExtentsULong extents)
- {
- if(extents == null)
- return null;
+ if(extents == null)
+ return null;
- Tuple[] tuples = extents.ToArray();
- ExtentType[] array = new ExtentType[tuples.Length];
+ Tuple[] tuples = extents.ToArray();
+ ExtentType[] array = new ExtentType[tuples.Length];
- for(ulong i = 0; i < (ulong)array.LongLength; i++)
- array[i] = new ExtentType
- {
- Start = tuples[i].Item1,
- End = tuples[i].Item2
- };
+ for(ulong i = 0; i < (ulong)array.LongLength; i++)
+ array[i] = new ExtentType
+ {
+ Start = tuples[i].Item1,
+ End = tuples[i].Item2
+ };
- return array;
- }
+ return array;
+ }
- /// Converts XML based extents into unsigned long integer extents
- /// XML based extents
- /// Extents
- public static ExtentsULong FromMetadata(ExtentType[] extents)
- {
- if(extents == null)
- return null;
+ /// Converts XML based extents into unsigned long integer extents
+ /// XML based extents
+ /// Extents
+ public static ExtentsULong FromMetadata(ExtentType[] extents)
+ {
+ if(extents == null)
+ return null;
- List> tuples =
- extents.Select(extent => new Tuple(extent.Start, extent.End)).ToList();
+ List> tuples =
+ extents.Select(extent => new Tuple(extent.Start, extent.End)).ToList();
- return new ExtentsULong(tuples);
- }
+ return new ExtentsULong(tuples);
}
}
\ No newline at end of file
diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs
index c98382d9e..0b5ed01c8 100644
--- a/Extents/ExtentsInt.cs
+++ b/Extents/ExtentsInt.cs
@@ -40,215 +40,214 @@ using System;
using System.Collections.Generic;
using System.Linq;
-namespace Aaru.CommonTypes.Extents
+namespace Aaru.CommonTypes.Extents;
+
+/// Implements extents for
+public class ExtentsInt
{
- /// Implements extents for
- public class ExtentsInt
+ List> _backend;
+
+ /// Initialize an empty list of extents
+ public ExtentsInt() => _backend = new List>();
+
+ /// Initializes extents with an specific list
+ /// List of extents as tuples "start, end"
+ public ExtentsInt(IEnumerable> list)
{
- List> _backend;
+ _backend = new List>();
- /// Initialize an empty list of extents
- public ExtentsInt() => _backend = new List>();
+ // This ensure no overlapping extents are added on creation
+ foreach(Tuple t in list)
+ Add(t.Item1, t.Item2);
+ }
- /// Initializes extents with an specific list
- /// List of extents as tuples "start, end"
- public ExtentsInt(IEnumerable> list)
+ /// Gets a count of how many extents are stored
+ public int Count => _backend.Count;
+
+ /// Adds the specified number to the corresponding extent, or creates a new one
+ ///
+ public void Add(int item)
+ {
+ Tuple removeOne = null;
+ Tuple removeTwo = null;
+ Tuple itemToAdd = null;
+
+ for(int i = 0; i < _backend.Count; i++)
{
- _backend = new List>();
+ // Already contained in an extent
+ if(item >= _backend[i].Item1 &&
+ item <= _backend[i].Item2)
+ return;
- // 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;
-
- /// Adds the specified number to the corresponding extent, or creates a new one
- ///
- public void Add(int item)
- {
- Tuple removeOne = null;
- Tuple removeTwo = null;
- Tuple itemToAdd = null;
-
- for(int i = 0; i < _backend.Count; i++)
+ // Expands existing extent start
+ if(item == _backend[i].Item1 - 1)
{
- // Already contained in an extent
- if(item >= _backend[i].Item1 &&
- item <= _backend[i].Item2)
- return;
-
- // Expands existing extent start
- if(item == _backend[i].Item1 - 1)
- {
- removeOne = _backend[i];
-
- if(i > 0 &&
- item == _backend[i - 1].Item2 + 1)
- {
- removeTwo = _backend[i - 1];
- itemToAdd = new Tuple(_backend[i - 1].Item1, _backend[i].Item2);
- }
- else
- itemToAdd = new Tuple(item, _backend[i].Item2);
-
- break;
- }
-
- // Expands existing extent end
- if(item != _backend[i].Item2 + 1)
- continue;
-
removeOne = _backend[i];
- if(i < _backend.Count - 1 &&
- item == _backend[i + 1].Item1 - 1)
+ if(i > 0 &&
+ item == _backend[i - 1].Item2 + 1)
{
- removeTwo = _backend[i + 1];
- itemToAdd = new Tuple(_backend[i].Item1, _backend[i + 1].Item2);
+ removeTwo = _backend[i - 1];
+ itemToAdd = new Tuple(_backend[i - 1].Item1, _backend[i].Item2);
}
else
- itemToAdd = new Tuple(_backend[i].Item1, item);
+ itemToAdd = new Tuple(item, _backend[i].Item2);
break;
}
- if(itemToAdd != null)
+ // Expands existing extent end
+ if(item != _backend[i].Item2 + 1)
+ continue;
+
+ removeOne = _backend[i];
+
+ if(i < _backend.Count - 1 &&
+ item == _backend[i + 1].Item1 - 1)
{
- _backend.Remove(removeOne);
- _backend.Remove(removeTwo);
- _backend.Add(itemToAdd);
+ removeTwo = _backend[i + 1];
+ itemToAdd = new Tuple(_backend[i].Item1, _backend[i + 1].Item2);
}
else
- _backend.Add(new Tuple(item, item));
+ itemToAdd = new Tuple(_backend[i].Item1, item);
- // Sort
- _backend = _backend.OrderBy(t => t.Item1).ToList();
+ break;
}
- /// Adds a new extent
- /// First element of the extent
- ///
- /// Last element of the extent or if is true how many elements the extent runs
- /// for
- ///
- /// If set to true, indicates how many elements the extent runs for
- public void Add(int start, int end, bool run = false)
+ if(itemToAdd != null)
{
- int realEnd;
-
- if(run)
- realEnd = start + end - 1;
- else
- realEnd = end;
-
- // TODO: Optimize this
- for(int t = start; t <= realEnd; t++)
- Add(t);
+ _backend.Remove(removeOne);
+ _backend.Remove(removeTwo);
+ _backend.Add(itemToAdd);
}
+ else
+ _backend.Add(new Tuple(item, item));
- /// Checks if the specified item is contained by an extent on this instance
- /// Item to search for
- /// true if any of the extents on this instance contains the item
- public bool Contains(int item) => _backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
+ // Sort
+ _backend = _backend.OrderBy(t => t.Item1).ToList();
+ }
- /// Removes all extents from this instance
- public void Clear() => _backend.Clear();
+ /// Adds a new extent
+ /// First element of the extent
+ ///
+ /// Last element of the extent or if is true how many elements the extent runs
+ /// for
+ ///
+ /// If set to true, indicates how many elements the extent runs for
+ public void Add(int start, int end, bool run = false)
+ {
+ int realEnd;
- /// Removes an item from the extents in this instance
- /// Item to remove
- /// true if the item was contained in a known extent and removed, false otherwise
- public bool Remove(int item)
+ if(run)
+ realEnd = start + end - 1;
+ else
+ realEnd = end;
+
+ // TODO: Optimize this
+ for(int t = start; t <= realEnd; t++)
+ Add(t);
+ }
+
+ /// Checks if the specified item is contained by an extent on this instance
+ /// Item to search for
+ /// true if any of the extents on this instance contains the item
+ public bool Contains(int item) => _backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
+
+ /// Removes all extents from this instance
+ public void Clear() => _backend.Clear();
+
+ /// Removes an item from the extents in this instance
+ /// Item to remove
+ /// true if the item was contained in a known extent and removed, false otherwise
+ public bool Remove(int item)
+ {
+ Tuple toRemove = null;
+ Tuple toAddOne = null;
+ Tuple toAddTwo = null;
+
+ foreach(Tuple extent in _backend)
{
- Tuple toRemove = null;
- Tuple toAddOne = null;
- Tuple toAddTwo = null;
-
- foreach(Tuple extent in _backend)
+ // Extent is contained and not a border
+ if(item > extent.Item1 &&
+ item < extent.Item2)
{
- // Extent is contained and not a border
- if(item > extent.Item1 &&
- item < extent.Item2)
- {
- toRemove = extent;
- toAddOne = new Tuple(extent.Item1, item - 1);
- toAddTwo = new Tuple(item + 1, extent.Item2);
-
- break;
- }
-
- // Extent is left border, but not only element
- if(item == extent.Item1 &&
- item != extent.Item2)
- {
- toRemove = extent;
- toAddOne = new Tuple(item + 1, extent.Item2);
-
- break;
- }
-
- // Extent is right border, but not only element
- if(item != extent.Item1 &&
- item == extent.Item2)
- {
- toRemove = extent;
- toAddOne = new Tuple(extent.Item1, item - 1);
-
- break;
- }
-
- // Extent is only element
- if(item != extent.Item1 ||
- item != extent.Item2)
- continue;
-
toRemove = extent;
+ toAddOne = new Tuple(extent.Item1, item - 1);
+ toAddTwo = new Tuple(item + 1, extent.Item2);
break;
}
- // Item not found
- if(toRemove == null)
- return false;
+ // Extent is left border, but not only element
+ if(item == extent.Item1 &&
+ item != extent.Item2)
+ {
+ toRemove = extent;
+ toAddOne = new Tuple(item + 1, extent.Item2);
- _backend.Remove(toRemove);
+ break;
+ }
- if(toAddOne != null)
- _backend.Add(toAddOne);
+ // Extent is right border, but not only element
+ if(item != extent.Item1 &&
+ item == extent.Item2)
+ {
+ toRemove = extent;
+ toAddOne = new Tuple(extent.Item1, item - 1);
- if(toAddTwo != null)
- _backend.Add(toAddTwo);
+ break;
+ }
- // Sort
- _backend = _backend.OrderBy(t => t.Item1).ToList();
+ // Extent is only element
+ if(item != extent.Item1 ||
+ item != extent.Item2)
+ continue;
+
+ toRemove = extent;
+
+ break;
+ }
+
+ // Item not found
+ if(toRemove == null)
+ return false;
+
+ _backend.Remove(toRemove);
+
+ if(toAddOne != null)
+ _backend.Add(toAddOne);
+
+ if(toAddTwo != null)
+ _backend.Add(toAddTwo);
+
+ // Sort
+ _backend = _backend.OrderBy(t => t.Item1).ToList();
+
+ return true;
+ }
+
+ ///
+ /// Converts the list of extents to an array of where T1 is first element of the extent and
+ /// T2 is last element
+ ///
+ /// Array of
+ public Tuple[] ToArray() => _backend.ToArray();
+
+ /// Gets the first element of the extent that contains the specified item
+ /// Item
+ /// First element of extent
+ /// true if item was found in an extent, false otherwise
+ public bool GetStart(int item, out int start)
+ {
+ start = 0;
+
+ foreach(Tuple extent in _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
+ {
+ start = extent.Item1;
return true;
}
- ///
- /// Converts the list of extents to an array of where T1 is first element of the extent and
- /// T2 is last element
- ///
- /// Array of
- public Tuple[] ToArray() => _backend.ToArray();
-
- /// Gets the first element of the extent that contains the specified item
- /// Item
- /// First element of extent
- /// true if item was found in an extent, false otherwise
- public bool GetStart(int item, out int start)
- {
- start = 0;
-
- foreach(Tuple extent in _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
- {
- start = extent.Item1;
-
- return true;
- }
-
- return false;
- }
+ return false;
}
}
\ No newline at end of file
diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs
index ec64998ab..0b8be7298 100644
--- a/Extents/ExtentsLong.cs
+++ b/Extents/ExtentsLong.cs
@@ -40,215 +40,214 @@ using System;
using System.Collections.Generic;
using System.Linq;
-namespace Aaru.CommonTypes.Extents
+namespace Aaru.CommonTypes.Extents;
+
+/// Implements extents for
+public class ExtentsLong
{
- /// Implements extents for
- public class ExtentsLong
+ List> _backend;
+
+ /// Initialize an empty list of extents
+ public ExtentsLong() => _backend = new List>();
+
+ /// Initializes extents with an specific list
+ /// List of extents as tuples "start, end"
+ public ExtentsLong(IEnumerable> list)
{
- List> _backend;
+ _backend = new List>();
- /// Initialize an empty list of extents
- public ExtentsLong() => _backend = new List>();
+ // This ensure no overlapping extents are added on creation
+ foreach(Tuple t in list)
+ Add(t.Item1, t.Item2);
+ }
- /// Initializes extents with an specific list
- /// List of extents as tuples "start, end"
- public ExtentsLong(IEnumerable> list)
+ /// Gets a count of how many extents are stored
+ public int Count => _backend.Count;
+
+ /// Adds the specified number to the corresponding extent, or creates a new one
+ ///
+ public void Add(long item)
+ {
+ Tuple removeOne = null;
+ Tuple removeTwo = null;
+ Tuple itemToAdd = null;
+
+ for(int i = 0; i < _backend.Count; i++)
{
- _backend = new List>();
+ // Already contained in an extent
+ if(item >= _backend[i].Item1 &&
+ item <= _backend[i].Item2)
+ return;
- // 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;
-
- /// Adds the specified number to the corresponding extent, or creates a new one
- ///
- public void Add(long item)
- {
- Tuple removeOne = null;
- Tuple removeTwo = null;
- Tuple itemToAdd = null;
-
- for(int i = 0; i < _backend.Count; i++)
+ // Expands existing extent start
+ if(item == _backend[i].Item1 - 1)
{
- // Already contained in an extent
- if(item >= _backend[i].Item1 &&
- item <= _backend[i].Item2)
- return;
-
- // Expands existing extent start
- if(item == _backend[i].Item1 - 1)
- {
- removeOne = _backend[i];
-
- if(i > 0 &&
- item == _backend[i - 1].Item2 + 1)
- {
- removeTwo = _backend[i - 1];
- itemToAdd = new Tuple(_backend[i - 1].Item1, _backend[i].Item2);
- }
- else
- itemToAdd = new Tuple(item, _backend[i].Item2);
-
- break;
- }
-
- // Expands existing extent end
- if(item != _backend[i].Item2 + 1)
- continue;
-
removeOne = _backend[i];
- if(i < _backend.Count - 1 &&
- item == _backend[i + 1].Item1 - 1)
+ if(i > 0 &&
+ item == _backend[i - 1].Item2 + 1)
{
- removeTwo = _backend[i + 1];
- itemToAdd = new Tuple(_backend[i].Item1, _backend[i + 1].Item2);
+ removeTwo = _backend[i - 1];
+ itemToAdd = new Tuple(_backend[i - 1].Item1, _backend[i].Item2);
}
else
- itemToAdd = new Tuple(_backend[i].Item1, item);
+ itemToAdd = new Tuple(item, _backend[i].Item2);
break;
}
- if(itemToAdd != null)
+ // Expands existing extent end
+ if(item != _backend[i].Item2 + 1)
+ continue;
+
+ removeOne = _backend[i];
+
+ if(i < _backend.Count - 1 &&
+ item == _backend[i + 1].Item1 - 1)
{
- _backend.Remove(removeOne);
- _backend.Remove(removeTwo);
- _backend.Add(itemToAdd);
+ removeTwo = _backend[i + 1];
+ itemToAdd = new Tuple(_backend[i].Item1, _backend[i + 1].Item2);
}
else
- _backend.Add(new Tuple(item, item));
+ itemToAdd = new Tuple(_backend[i].Item1, item);
- // Sort
- _backend = _backend.OrderBy(t => t.Item1).ToList();
+ break;
}
- /// Adds a new extent
- /// First element of the extent
- ///
- /// Last element of the extent or if is true how many elements the extent runs
- /// for
- ///
- /// If set to true, indicates how many elements the extent runs for
- public void Add(long start, long end, bool run = false)
+ if(itemToAdd != null)
{
- long realEnd;
-
- if(run)
- realEnd = start + end - 1;
- else
- realEnd = end;
-
- // TODO: Optimize this
- for(long t = start; t <= realEnd; t++)
- Add(t);
+ _backend.Remove(removeOne);
+ _backend.Remove(removeTwo);
+ _backend.Add(itemToAdd);
}
+ else
+ _backend.Add(new Tuple(item, item));
- /// Checks if the specified item is contained by an extent on this instance
- /// Item to search for
- /// true if any of the extents on this instance contains the item
- public bool Contains(long item) => _backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
+ // Sort
+ _backend = _backend.OrderBy(t => t.Item1).ToList();
+ }
- /// Removes all extents from this instance
- public void Clear() => _backend.Clear();
+ /// Adds a new extent
+ /// First element of the extent
+ ///
+ /// Last element of the extent or if is true how many elements the extent runs
+ /// for
+ ///
+ /// If set to true, indicates how many elements the extent runs for
+ public void Add(long start, long end, bool run = false)
+ {
+ long realEnd;
- /// Removes an item from the extents in this instance
- /// Item to remove
- /// true if the item was contained in a known extent and removed, false otherwise
- public bool Remove(long item)
+ if(run)
+ realEnd = start + end - 1;
+ else
+ realEnd = end;
+
+ // TODO: Optimize this
+ for(long t = start; t <= realEnd; t++)
+ Add(t);
+ }
+
+ /// Checks if the specified item is contained by an extent on this instance
+ /// Item to search for
+ /// true if any of the extents on this instance contains the item
+ public bool Contains(long item) => _backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
+
+ /// Removes all extents from this instance
+ public void Clear() => _backend.Clear();
+
+ /// Removes an item from the extents in this instance
+ /// Item to remove
+ /// true if the item was contained in a known extent and removed, false otherwise
+ public bool Remove(long item)
+ {
+ Tuple toRemove = null;
+ Tuple toAddOne = null;
+ Tuple toAddTwo = null;
+
+ foreach(Tuple extent in _backend)
{
- Tuple toRemove = null;
- Tuple toAddOne = null;
- Tuple toAddTwo = null;
-
- foreach(Tuple extent in _backend)
+ // Extent is contained and not a border
+ if(item > extent.Item1 &&
+ item < extent.Item2)
{
- // Extent is contained and not a border
- if(item > extent.Item1 &&
- item < extent.Item2)
- {
- toRemove = extent;
- toAddOne = new Tuple(extent.Item1, item - 1);
- toAddTwo = new Tuple(item + 1, extent.Item2);
-
- break;
- }
-
- // Extent is left border, but not only element
- if(item == extent.Item1 &&
- item != extent.Item2)
- {
- toRemove = extent;
- toAddOne = new Tuple(item + 1, extent.Item2);
-
- break;
- }
-
- // Extent is right border, but not only element
- if(item != extent.Item1 &&
- item == extent.Item2)
- {
- toRemove = extent;
- toAddOne = new Tuple(extent.Item1, item - 1);
-
- break;
- }
-
- // Extent is only element
- if(item != extent.Item1 ||
- item != extent.Item2)
- continue;
-
toRemove = extent;
+ toAddOne = new Tuple(extent.Item1, item - 1);
+ toAddTwo = new Tuple(item + 1, extent.Item2);
break;
}
- // Item not found
- if(toRemove == null)
- return false;
+ // Extent is left border, but not only element
+ if(item == extent.Item1 &&
+ item != extent.Item2)
+ {
+ toRemove = extent;
+ toAddOne = new Tuple(item + 1, extent.Item2);
- _backend.Remove(toRemove);
+ break;
+ }
- if(toAddOne != null)
- _backend.Add(toAddOne);
+ // Extent is right border, but not only element
+ if(item != extent.Item1 &&
+ item == extent.Item2)
+ {
+ toRemove = extent;
+ toAddOne = new Tuple(extent.Item1, item - 1);
- if(toAddTwo != null)
- _backend.Add(toAddTwo);
+ break;
+ }
- // Sort
- _backend = _backend.OrderBy(t => t.Item1).ToList();
+ // Extent is only element
+ if(item != extent.Item1 ||
+ item != extent.Item2)
+ continue;
+
+ toRemove = extent;
+
+ break;
+ }
+
+ // Item not found
+ if(toRemove == null)
+ return false;
+
+ _backend.Remove(toRemove);
+
+ if(toAddOne != null)
+ _backend.Add(toAddOne);
+
+ if(toAddTwo != null)
+ _backend.Add(toAddTwo);
+
+ // Sort
+ _backend = _backend.OrderBy(t => t.Item1).ToList();
+
+ return true;
+ }
+
+ ///
+ /// Converts the list of extents to an array of where T1 is first element of the extent and
+ /// T2 is last element
+ ///
+ /// Array of
+ public Tuple[] ToArray() => _backend.ToArray();
+
+ /// Gets the first element of the extent that contains the specified item
+ /// Item
+ /// First element of extent
+ /// true if item was found in an extent, false otherwise
+ public bool GetStart(long item, out long start)
+ {
+ start = 0;
+
+ foreach(Tuple extent in _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
+ {
+ start = extent.Item1;
return true;
}
- ///
- /// Converts the list of extents to an array of where T1 is first element of the extent and
- /// T2 is last element
- ///
- /// Array of
- public Tuple[] ToArray() => _backend.ToArray();
-
- /// Gets the first element of the extent that contains the specified item
- /// Item
- /// First element of extent
- /// true if item was found in an extent, false otherwise
- public bool GetStart(long item, out long start)
- {
- start = 0;
-
- foreach(Tuple extent in _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
- {
- start = extent.Item1;
-
- return true;
- }
-
- return false;
- }
+ return false;
}
}
\ No newline at end of file
diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs
index dd9a4cb53..9bf246eff 100644
--- a/Extents/ExtentsSByte.cs
+++ b/Extents/ExtentsSByte.cs
@@ -40,216 +40,215 @@ using System;
using System.Collections.Generic;
using System.Linq;
-namespace Aaru.CommonTypes.Extents
+namespace Aaru.CommonTypes.Extents;
+
+/// Implements extents for
+public class ExtentsSByte
{
- /// Implements extents for
- public class ExtentsSByte
+ List> _backend;
+
+ /// Initialize an empty list of extents
+ public ExtentsSByte() => _backend = new List>();
+
+ /// Initializes extents with an specific list
+ /// List of extents as tuples "start, end"
+ public ExtentsSByte(IEnumerable> list)
{
- List> _backend;
+ _backend = new List>();
- /// Initialize an empty list of extents
- public ExtentsSByte() => _backend = new List>();
+ // This ensure no overlapping extents are added on creation
+ foreach(Tuple t in list)
+ Add(t.Item1, t.Item2);
+ }
- /// Initializes extents with an specific list
- /// List of extents as tuples "start, end"
- public ExtentsSByte(IEnumerable> list)
+ /// Gets a count of how many extents are stored
+ public int Count => _backend.Count;
+
+ /// Adds the specified number to the corresponding extent, or creates a new one
+ ///
+ public void Add(sbyte item)
+ {
+ Tuple removeOne = null;
+ Tuple removeTwo = null;
+ Tuple itemToAdd = null;
+
+ for(int i = 0; i < _backend.Count; i++)
{
- _backend = new List>();
+ // Already contained in an extent
+ if(item >= _backend[i].Item1 &&
+ item <= _backend[i].Item2)
+ return;
- // 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;
-
- /// Adds the specified number to the corresponding extent, or creates a new one
- ///
- public void Add(sbyte item)
- {
- Tuple removeOne = null;
- Tuple removeTwo = null;
- Tuple itemToAdd = null;
-
- for(int i = 0; i < _backend.Count; i++)
+ // Expands existing extent start
+ if(item == _backend[i].Item1 - 1)
{
- // Already contained in an extent
- if(item >= _backend[i].Item1 &&
- item <= _backend[i].Item2)
- return;
-
- // Expands existing extent start
- if(item == _backend[i].Item1 - 1)
- {
- removeOne = _backend[i];
-
- if(i > 0 &&
- item == _backend[i - 1].Item2 + 1)
- {
- removeTwo = _backend[i - 1];
- itemToAdd = new Tuple(_backend[i - 1].Item1, _backend[i].Item2);
- }
- else
- itemToAdd = new Tuple(item, _backend[i].Item2);
-
- break;
- }
-
- // Expands existing extent end
- if(item != _backend[i].Item2 + 1)
- continue;
-
removeOne = _backend[i];
- if(i < _backend.Count - 1 &&
- item == _backend[i + 1].Item1 - 1)
+ if(i > 0 &&
+ item == _backend[i - 1].Item2 + 1)
{
- removeTwo = _backend[i + 1];
- itemToAdd = new Tuple(_backend[i].Item1, _backend[i + 1].Item2);
+ removeTwo = _backend[i - 1];
+ itemToAdd = new Tuple(_backend[i - 1].Item1, _backend[i].Item2);
}
else
- itemToAdd = new Tuple(_backend[i].Item1, item);
+ itemToAdd = new Tuple(item, _backend[i].Item2);
break;
}
- if(itemToAdd != null)
+ // Expands existing extent end
+ if(item != _backend[i].Item2 + 1)
+ continue;
+
+ removeOne = _backend[i];
+
+ if(i < _backend.Count - 1 &&
+ item == _backend[i + 1].Item1 - 1)
{
- _backend.Remove(removeOne);
- _backend.Remove(removeTwo);
- _backend.Add(itemToAdd);
+ removeTwo = _backend[i + 1];
+ itemToAdd = new Tuple(_backend[i].Item1, _backend[i + 1].Item2);
}
else
- _backend.Add(new Tuple(item, item));
+ itemToAdd = new Tuple(_backend[i].Item1, item);
- // Sort
- _backend = _backend.OrderBy(t => t.Item1).ToList();
+ break;
}
- /// Adds a new extent
- /// First element of the extent
- ///
- /// Last element of the extent or if is true how many elements the extent runs
- /// for
- ///
- /// If set to true, indicates how many elements the extent runs for
- public void Add(sbyte start, sbyte end, bool run = false)
+ if(itemToAdd != null)
{
- sbyte realEnd;
-
- if(run)
- realEnd = (sbyte)(start + end - 1);
- else
- realEnd = end;
-
- // TODO: Optimize this
- for(sbyte t = start; t <= realEnd; t++)
- Add(t);
+ _backend.Remove(removeOne);
+ _backend.Remove(removeTwo);
+ _backend.Add(itemToAdd);
}
+ else
+ _backend.Add(new Tuple(item, item));
- /// Checks if the specified item is contained by an extent on this instance
- /// Item to search for
- /// true if any of the extents on this instance contains the item
- public bool Contains(sbyte item) => _backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
+ // Sort
+ _backend = _backend.OrderBy(t => t.Item1).ToList();
+ }
- /// Removes all extents from this instance
- public void Clear() => _backend.Clear();
+ /// Adds a new extent
+ /// First element of the extent
+ ///
+ /// Last element of the extent or if is true how many elements the extent runs
+ /// for
+ ///
+ /// If set to true, indicates how many elements the extent runs for
+ public void Add(sbyte start, sbyte end, bool run = false)
+ {
+ sbyte realEnd;
- /// Removes an item from the extents in this instance
- /// Item to remove
- /// true if the item was contained in a known extent and removed, false otherwise
- public bool Remove(sbyte item)
+ if(run)
+ realEnd = (sbyte)(start + end - 1);
+ else
+ realEnd = end;
+
+ // TODO: Optimize this
+ for(sbyte t = start; t <= realEnd; t++)
+ Add(t);
+ }
+
+ /// Checks if the specified item is contained by an extent on this instance
+ /// Item to search for
+ /// true if any of the extents on this instance contains the item
+ public bool Contains(sbyte item) => _backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
+
+ /// Removes all extents from this instance
+ public void Clear() => _backend.Clear();
+
+ /// Removes an item from the extents in this instance
+ /// Item to remove
+ /// true if the item was contained in a known extent and removed, false otherwise
+ public bool Remove(sbyte item)
+ {
+ Tuple toRemove = null;
+ Tuple toAddOne = null;
+ Tuple toAddTwo = null;
+
+ foreach(Tuple extent in _backend)
{
- Tuple toRemove = null;
- Tuple toAddOne = null;
- Tuple toAddTwo = null;
-
- foreach(Tuple extent in _backend)
+ // Extent is contained and not a border
+ if(item > extent.Item1 &&
+ item < extent.Item2)
{
- // Extent is contained and not a border
- if(item > extent.Item1 &&
- item < extent.Item2)
- {
- toRemove = extent;
- toAddOne = new Tuple(extent.Item1, (sbyte)(item - 1));
- toAddTwo = new Tuple((sbyte)(item + 1), extent.Item2);
-
- break;
- }
-
- // Extent is left border, but not only element
- if(item == extent.Item1 &&
- item != extent.Item2)
- {
- toRemove = extent;
- toAddOne = new Tuple((sbyte)(item + 1), extent.Item2);
-
- break;
- }
-
- // Extent is right border, but not only element
- if(item != extent.Item1 &&
- item == extent.Item2)
- {
- toRemove = extent;
- toAddOne = new Tuple(extent.Item1, (sbyte)(item - 1));
-
- break;
- }
-
- // Extent is only element
- if(item != extent.Item1 ||
- item != extent.Item2)
- continue;
-
toRemove = extent;
+ toAddOne = new Tuple(extent.Item1, (sbyte)(item - 1));
+ toAddTwo = new Tuple((sbyte)(item + 1), extent.Item2);
break;
}
- // Item not found
- if(toRemove == null)
- return false;
+ // Extent is left border, but not only element
+ if(item == extent.Item1 &&
+ item != extent.Item2)
+ {
+ toRemove = extent;
+ toAddOne = new Tuple((sbyte)(item + 1), extent.Item2);
- _backend.Remove(toRemove);
+ break;
+ }
- if(toAddOne != null)
- _backend.Add(toAddOne);
+ // Extent is right border, but not only element
+ if(item != extent.Item1 &&
+ item == extent.Item2)
+ {
+ toRemove = extent;
+ toAddOne = new Tuple(extent.Item1, (sbyte)(item - 1));
- if(toAddTwo != null)
- _backend.Add(toAddTwo);
+ break;
+ }
- // Sort
- _backend = _backend.OrderBy(t => t.Item1).ToList();
+ // Extent is only element
+ if(item != extent.Item1 ||
+ item != extent.Item2)
+ continue;
+
+ toRemove = extent;
+
+ break;
+ }
+
+ // Item not found
+ if(toRemove == null)
+ return false;
+
+ _backend.Remove(toRemove);
+
+ if(toAddOne != null)
+ _backend.Add(toAddOne);
+
+ if(toAddTwo != null)
+ _backend.Add(toAddTwo);
+
+ // Sort
+ _backend = _backend.OrderBy(t => t.Item1).ToList();
+
+ return true;
+ }
+
+ ///
+ /// Converts the list of extents to an array of where T1 is first element of the extent and
+ /// T2 is last element
+ ///
+ /// Array of
+ public Tuple[] ToArray() => _backend.ToArray();
+
+ /// Gets the first element of the extent that contains the specified item
+ /// Item
+ /// First element of extent
+ /// true if item was found in an extent, false otherwise
+ public bool GetStart(sbyte item, out sbyte start)
+ {
+ start = 0;
+
+ foreach(Tuple extent in
+ _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
+ {
+ start = extent.Item1;
return true;
}
- ///
- /// Converts the list of extents to an array of where T1 is first element of the extent and
- /// T2 is last element
- ///
- /// Array of
- public Tuple[] ToArray() => _backend.ToArray();
-
- /// Gets the first element of the extent that contains the specified item
- /// Item
- /// First element of extent
- /// true if item was found in an extent, false otherwise
- public bool GetStart(sbyte item, out sbyte start)
- {
- start = 0;
-
- foreach(Tuple extent in
- _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
- {
- start = extent.Item1;
-
- return true;
- }
-
- return false;
- }
+ return false;
}
}
\ No newline at end of file
diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs
index acbd5d62f..086d7e47c 100644
--- a/Extents/ExtentsShort.cs
+++ b/Extents/ExtentsShort.cs
@@ -40,216 +40,215 @@ using System;
using System.Collections.Generic;
using System.Linq;
-namespace Aaru.CommonTypes.Extents
+namespace Aaru.CommonTypes.Extents;
+
+/// Implements extents for
+public class ExtentsShort
{
- /// Implements extents for
- public class ExtentsShort
+ List> _backend;
+
+ /// Initialize an empty list of extents
+ public ExtentsShort() => _backend = new List>();
+
+ /// Initializes extents with an specific list
+ /// List of extents as tuples "start, end"
+ public ExtentsShort(IEnumerable> list)
{
- List> _backend;
+ _backend = new List>();
- /// Initialize an empty list of extents
- public ExtentsShort() => _backend = new List>();
+ // This ensure no overlapping extents are added on creation
+ foreach(Tuple t in list)
+ Add(t.Item1, t.Item2);
+ }
- /// Initializes extents with an specific list
- /// List of extents as tuples "start, end"
- public ExtentsShort(IEnumerable> list)
+ /// Gets a count of how many extents are stored
+ public int Count => _backend.Count;
+
+ /// Adds the specified number to the corresponding extent, or creates a new one
+ ///
+ public void Add(short item)
+ {
+ Tuple removeOne = null;
+ Tuple removeTwo = null;
+ Tuple itemToAdd = null;
+
+ for(int i = 0; i < _backend.Count; i++)
{
- _backend = new List>();
+ // Already contained in an extent
+ if(item >= _backend[i].Item1 &&
+ item <= _backend[i].Item2)
+ return;
- // 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;
-
- /// Adds the specified number to the corresponding extent, or creates a new one
- ///
- public void Add(short item)
- {
- Tuple removeOne = null;
- Tuple removeTwo = null;
- Tuple itemToAdd = null;
-
- for(int i = 0; i < _backend.Count; i++)
+ // Expands existing extent start
+ if(item == _backend[i].Item1 - 1)
{
- // Already contained in an extent
- if(item >= _backend[i].Item1 &&
- item <= _backend[i].Item2)
- return;
-
- // Expands existing extent start
- if(item == _backend[i].Item1 - 1)
- {
- removeOne = _backend[i];
-
- if(i > 0 &&
- item == _backend[i - 1].Item2 + 1)
- {
- removeTwo = _backend[i - 1];
- itemToAdd = new Tuple(_backend[i - 1].Item1, _backend[i].Item2);
- }
- else
- itemToAdd = new Tuple(item, _backend[i].Item2);
-
- break;
- }
-
- // Expands existing extent end
- if(item != _backend[i].Item2 + 1)
- continue;
-
removeOne = _backend[i];
- if(i < _backend.Count - 1 &&
- item == _backend[i + 1].Item1 - 1)
+ if(i > 0 &&
+ item == _backend[i - 1].Item2 + 1)
{
- removeTwo = _backend[i + 1];
- itemToAdd = new Tuple(_backend[i].Item1, _backend[i + 1].Item2);
+ removeTwo = _backend[i - 1];
+ itemToAdd = new Tuple(_backend[i - 1].Item1, _backend[i].Item2);
}
else
- itemToAdd = new Tuple(_backend[i].Item1, item);
+ itemToAdd = new Tuple(item, _backend[i].Item2);
break;
}
- if(itemToAdd != null)
+ // Expands existing extent end
+ if(item != _backend[i].Item2 + 1)
+ continue;
+
+ removeOne = _backend[i];
+
+ if(i < _backend.Count - 1 &&
+ item == _backend[i + 1].Item1 - 1)
{
- _backend.Remove(removeOne);
- _backend.Remove(removeTwo);
- _backend.Add(itemToAdd);
+ removeTwo = _backend[i + 1];
+ itemToAdd = new Tuple(_backend[i].Item1, _backend[i + 1].Item2);
}
else
- _backend.Add(new Tuple(item, item));
+ itemToAdd = new Tuple(_backend[i].Item1, item);
- // Sort
- _backend = _backend.OrderBy(t => t.Item1).ToList();
+ break;
}
- /// Adds a new extent
- /// First element of the extent
- ///
- /// Last element of the extent or if is true how many elements the extent runs
- /// for
- ///
- /// If set to true, indicates how many elements the extent runs for
- public void Add(short start, short end, bool run = false)
+ if(itemToAdd != null)
{
- short realEnd;
-
- if(run)
- realEnd = (short)(start + end - 1);
- else
- realEnd = end;
-
- // TODO: Optimize this
- for(short t = start; t <= realEnd; t++)
- Add(t);
+ _backend.Remove(removeOne);
+ _backend.Remove(removeTwo);
+ _backend.Add(itemToAdd);
}
+ else
+ _backend.Add(new Tuple(item, item));
- /// Checks if the specified item is contained by an extent on this instance
- /// Item to search for
- /// true if any of the extents on this instance contains the item
- public bool Contains(short item) => _backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
+ // Sort
+ _backend = _backend.OrderBy(t => t.Item1).ToList();
+ }
- /// Removes all extents from this instance
- public void Clear() => _backend.Clear();
+ /// Adds a new extent
+ /// First element of the extent
+ ///
+ /// Last element of the extent or if is true how many elements the extent runs
+ /// for
+ ///
+ /// If set to true, indicates how many elements the extent runs for
+ public void Add(short start, short end, bool run = false)
+ {
+ short realEnd;
- /// Removes an item from the extents in this instance
- /// Item to remove
- /// true if the item was contained in a known extent and removed, false otherwise
- public bool Remove(short item)
+ if(run)
+ realEnd = (short)(start + end - 1);
+ else
+ realEnd = end;
+
+ // TODO: Optimize this
+ for(short t = start; t <= realEnd; t++)
+ Add(t);
+ }
+
+ /// Checks if the specified item is contained by an extent on this instance
+ /// Item to search for
+ /// true if any of the extents on this instance contains the item
+ public bool Contains(short item) => _backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
+
+ /// Removes all extents from this instance
+ public void Clear() => _backend.Clear();
+
+ /// Removes an item from the extents in this instance
+ /// Item to remove
+ /// true if the item was contained in a known extent and removed, false otherwise
+ public bool Remove(short item)
+ {
+ Tuple toRemove = null;
+ Tuple toAddOne = null;
+ Tuple toAddTwo = null;
+
+ foreach(Tuple extent in _backend)
{
- Tuple toRemove = null;
- Tuple toAddOne = null;
- Tuple toAddTwo = null;
-
- foreach(Tuple extent in _backend)
+ // Extent is contained and not a border
+ if(item > extent.Item1 &&
+ item < extent.Item2)
{
- // Extent is contained and not a border
- if(item > extent.Item1 &&
- item < extent.Item2)
- {
- toRemove = extent;
- toAddOne = new Tuple(extent.Item1, (short)(item - 1));
- toAddTwo = new Tuple((short)(item + 1), extent.Item2);
-
- break;
- }
-
- // Extent is left border, but not only element
- if(item == extent.Item1 &&
- item != extent.Item2)
- {
- toRemove = extent;
- toAddOne = new Tuple((short)(item + 1), extent.Item2);
-
- break;
- }
-
- // Extent is right border, but not only element
- if(item != extent.Item1 &&
- item == extent.Item2)
- {
- toRemove = extent;
- toAddOne = new Tuple(extent.Item1, (short)(item - 1));
-
- break;
- }
-
- // Extent is only element
- if(item != extent.Item1 ||
- item != extent.Item2)
- continue;
-
toRemove = extent;
+ toAddOne = new Tuple(extent.Item1, (short)(item - 1));
+ toAddTwo = new Tuple((short)(item + 1), extent.Item2);
break;
}
- // Item not found
- if(toRemove == null)
- return false;
+ // Extent is left border, but not only element
+ if(item == extent.Item1 &&
+ item != extent.Item2)
+ {
+ toRemove = extent;
+ toAddOne = new Tuple((short)(item + 1), extent.Item2);
- _backend.Remove(toRemove);
+ break;
+ }
- if(toAddOne != null)
- _backend.Add(toAddOne);
+ // Extent is right border, but not only element
+ if(item != extent.Item1 &&
+ item == extent.Item2)
+ {
+ toRemove = extent;
+ toAddOne = new Tuple(extent.Item1, (short)(item - 1));
- if(toAddTwo != null)
- _backend.Add(toAddTwo);
+ break;
+ }
- // Sort
- _backend = _backend.OrderBy(t => t.Item1).ToList();
+ // Extent is only element
+ if(item != extent.Item1 ||
+ item != extent.Item2)
+ continue;
+
+ toRemove = extent;
+
+ break;
+ }
+
+ // Item not found
+ if(toRemove == null)
+ return false;
+
+ _backend.Remove(toRemove);
+
+ if(toAddOne != null)
+ _backend.Add(toAddOne);
+
+ if(toAddTwo != null)
+ _backend.Add(toAddTwo);
+
+ // Sort
+ _backend = _backend.OrderBy(t => t.Item1).ToList();
+
+ return true;
+ }
+
+ ///
+ /// Converts the list of extents to an array of where T1 is first element of the extent and
+ /// T2 is last element
+ ///
+ /// Array of
+ public Tuple[] ToArray() => _backend.ToArray();
+
+ /// Gets the first element of the extent that contains the specified item
+ /// Item
+ /// First element of extent
+ /// true if item was found in an extent, false otherwise
+ public bool GetStart(short item, out short start)
+ {
+ start = 0;
+
+ foreach(Tuple extent in
+ _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
+ {
+ start = extent.Item1;
return true;
}
- ///
- /// Converts the list of extents to an array of where T1 is first element of the extent and
- /// T2 is last element
- ///
- /// Array of
- public Tuple[] ToArray() => _backend.ToArray();
-
- /// Gets the first element of the extent that contains the specified item
- /// Item
- /// First element of extent
- /// true if item was found in an extent, false otherwise
- public bool GetStart(short item, out short start)
- {
- start = 0;
-
- foreach(Tuple extent in
- _backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
- {
- start = extent.Item1;
-
- return true;
- }
-
- return false;
- }
+ return false;
}
}
\ No newline at end of file
diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs
index 4b72dfb17..0f8c80005 100644
--- a/Extents/ExtentsUInt.cs
+++ b/Extents/ExtentsUInt.cs
@@ -40,215 +40,214 @@ using System;
using System.Collections.Generic;
using System.Linq;
-namespace Aaru.CommonTypes.Extents
+namespace Aaru.CommonTypes.Extents;
+
+/// Implements extents for
+public class ExtentsUInt
{
- /// Implements extents for
- public class ExtentsUInt
+ List> _backend;
+
+ /// Initialize an empty list of extents
+ public ExtentsUInt() => _backend = new List>();
+
+ /// Initializes extents with an specific list
+ /// List of extents as tuples "start, end"
+ public ExtentsUInt(IEnumerable> list)
{
- List> _backend;
+ _backend = new List>();
- /// Initialize an empty list of extents
- public ExtentsUInt() => _backend = new List>();
+ // This ensure no overlapping extents are added on creation
+ foreach(Tuple t in list)
+ Add(t.Item1, t.Item2);
+ }
- /// Initializes extents with an specific list
- /// List of extents as tuples "start, end"
- public ExtentsUInt(IEnumerable> list)
+ /// Gets a count of how many extents are stored
+ public int Count => _backend.Count;
+
+ /// Adds the specified number to the corresponding extent, or creates a new one
+ ///
+ public void Add(uint item)
+ {
+ Tuple removeOne = null;
+ Tuple removeTwo = null;
+ Tuple itemToAdd = null;
+
+ for(int i = 0; i < _backend.Count; i++)
{
- _backend = new List>();
+ // Already contained in an extent
+ if(item >= _backend[i].Item1 &&
+ item <= _backend[i].Item2)
+ return;
- // 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;
-
- /// Adds the specified number to the corresponding extent, or creates a new one
- ///
- public void Add(uint item)
- {
- Tuple removeOne = null;
- Tuple removeTwo = null;
- Tuple itemToAdd = null;
-
- for(int i = 0; i < _backend.Count; i++)
+ // Expands existing extent start
+ if(item == _backend[i].Item1 - 1)
{
- // Already contained in an extent
- if(item >= _backend[i].Item1 &&
- item <= _backend[i].Item2)
- return;
-
- // Expands existing extent start
- if(item == _backend[i].Item1 - 1)
- {
- removeOne = _backend[i];
-
- if(i > 0 &&
- item == _backend[i - 1].Item2 + 1)
- {
- removeTwo = _backend[i - 1];
- itemToAdd = new Tuple(_backend[i - 1].Item1, _backend[i].Item2);
- }
- else
- itemToAdd = new Tuple(item, _backend[i].Item2);
-
- break;
- }
-
- // Expands existing extent end
- if(item != _backend[i].Item2 + 1)
- continue;
-
removeOne = _backend[i];
- if(i < _backend.Count - 1 &&
- item == _backend[i + 1].Item1 - 1)
+ if(i > 0 &&
+ item == _backend[i - 1].Item2 + 1)
{
- removeTwo = _backend[i + 1];
- itemToAdd = new Tuple