diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 07d0ea1ff..5bf150a71 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -12,7 +12,7 @@ false net461 true - 4.5.1.1692 + 4.5.99.1693 Claunia.com Copyright © 2011-2018 Natalia Portillo The Disc Image Chef @@ -55,14 +55,6 @@ - - - - - - - - @@ -77,9 +69,6 @@ LICENSE.LGPL - - - diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs deleted file mode 100644 index ba2b3c678..000000000 --- a/Extents/ExtentsByte.cs +++ /dev/null @@ -1,248 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsByte.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for byte types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// 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) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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++) - { - // 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) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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; - 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 seach for - /// true if any of the extents on this instance contains the item - public bool Contains(byte item) - { - return 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) - { - // 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; - 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() - { - return 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; - } - } -} \ No newline at end of file diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs deleted file mode 100644 index 39b8dbae6..000000000 --- a/Extents/ExtentsInt.cs +++ /dev/null @@ -1,248 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsInt.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for int types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License aint with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// 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) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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++) - { - // 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) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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; - 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 seach for - /// true if any of the extents on this instance contains the item - public bool Contains(int item) - { - return 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) - { - // 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; - 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() - { - return 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; - } - } -} \ No newline at end of file diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs deleted file mode 100644 index 5ccef4389..000000000 --- a/Extents/ExtentsLong.cs +++ /dev/null @@ -1,248 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsLong.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for long types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// 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) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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++) - { - // 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) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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; - 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 seach for - /// true if any of the extents on this instance contains the item - public bool Contains(long item) - { - return 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) - { - // 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; - 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() - { - return 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; - } - } -} \ No newline at end of file diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs deleted file mode 100644 index f77c2848e..000000000 --- a/Extents/ExtentsSByte.cs +++ /dev/null @@ -1,248 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsSByte.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for sbyte types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// 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) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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++) - { - // 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) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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; - 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 seach for - /// true if any of the extents on this instance contains the item - public bool Contains(sbyte item) - { - return 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) - { - // 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; - 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() - { - return 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; - } - } -} \ No newline at end of file diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs deleted file mode 100644 index ae92ee891..000000000 --- a/Extents/ExtentsShort.cs +++ /dev/null @@ -1,248 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsShort.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for short types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License ashort with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// 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) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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++) - { - // 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) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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; - 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 seach for - /// true if any of the extents on this instance contains the item - public bool Contains(short item) - { - return 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) - { - // 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; - 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() - { - return 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; - } - } -} \ No newline at end of file diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs deleted file mode 100644 index 6a917d69d..000000000 --- a/Extents/ExtentsUInt.cs +++ /dev/null @@ -1,248 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsUInt.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for uint types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License auint with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// 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) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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++) - { - // 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) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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(uint start, uint end, bool run = false) - { - uint realEnd; - if(run) realEnd = start + end - 1; - else realEnd = end; - - // TODO: Optimize this - for(uint t = start; t <= realEnd; t++) Add(t); - } - - /// - /// Checks if the specified item is contained by an extent on this instance - /// - /// Item to seach for - /// true if any of the extents on this instance contains the item - public bool Contains(uint item) - { - return 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(uint item) - { - 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) - { - 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; - 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() - { - return 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(uint item, out uint start) - { - start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) - { - start = extent.Item1; - return true; - } - - return false; - } - } -} \ No newline at end of file diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs deleted file mode 100644 index 09c76e8c8..000000000 --- a/Extents/ExtentsULong.cs +++ /dev/null @@ -1,248 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsULong.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for ulong types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License aulong with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// Implements extents for - /// - public class ExtentsULong - { - List> backend; - - /// - /// Initialize an empty list of extents - /// - public ExtentsULong() - { - backend = new List>(); - } - - /// - /// Initializes extents with an specific list - /// - /// List of extents as tuples "start, end" - public ExtentsULong(IEnumerable> list) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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(ulong item) - { - Tuple removeOne = null; - Tuple removeTwo = null; - Tuple itemToAdd = null; - - for(int i = 0; i < backend.Count; i++) - { - // 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) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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(ulong start, ulong end, bool run = false) - { - ulong realEnd; - if(run) realEnd = start + end - 1; - else realEnd = end; - - // TODO: Optimize this - for(ulong t = start; t <= realEnd; t++) Add(t); - } - - /// - /// Checks if the specified item is contained by an extent on this instance - /// - /// Item to seach for - /// true if any of the extents on this instance contains the item - public bool Contains(ulong item) - { - return 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(ulong item) - { - 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) - { - 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; - 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() - { - return 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(ulong item, out ulong start) - { - start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) - { - start = extent.Item1; - return true; - } - - return false; - } - } -} \ No newline at end of file diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs deleted file mode 100644 index 6a8689cf0..000000000 --- a/Extents/ExtentsUShort.cs +++ /dev/null @@ -1,249 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsUShort.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for ushort types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License aushort with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// Implements extents for - /// - public class ExtentsUShort - { - List> backend; - - /// - /// Initialize an empty list of extents - /// - public ExtentsUShort() - { - backend = new List>(); - } - - /// - /// Initializes extents with an specific list - /// - /// List of extents as tuples "start, end" - public ExtentsUShort(IEnumerable> list) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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(ushort item) - { - Tuple removeOne = null; - Tuple removeTwo = null; - Tuple itemToAdd = null; - - for(int i = 0; i < backend.Count; i++) - { - // 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) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// 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(ushort start, ushort end, bool run = false) - { - ushort realEnd; - if(run) realEnd = (ushort)(start + end - 1); - else realEnd = end; - - // TODO: Optimize this - for(ushort t = start; t <= realEnd; t++) Add(t); - } - - /// - /// Checks if the specified item is contained by an extent on this instance - /// - /// Item to seach for - /// true if any of the extents on this instance contains the item - public bool Contains(ushort item) - { - return 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(ushort item) - { - 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) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, (ushort)(item - 1)); - toAddTwo = new Tuple((ushort)(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((ushort)(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, (ushort)(item - 1)); - break; - } - - // 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() - { - return 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(ushort item, out ushort start) - { - start = 0; - foreach(Tuple extent in - backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) - { - start = extent.Item1; - return true; - } - - return false; - } - } -} \ No newline at end of file