/PowerLib/PowerLib.System/Collections/Extensions/BitsListExtension.cs
C# | 2260 lines | 2080 code | 94 blank | 86 comment | 939 complexity | 5000a3e8c3bee9b63a4a518e2c58e875 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
Large files files are truncated, but you can click here to view the full file
- using System;
- using System.Collections.Generic;
-
-
- namespace PowerLib.System.Collections.Extensions
- {
- /// <summary>
- /// Extension methods to operate with bits packed in interger type collections.
- /// </summary>
- public static class BitsListExtension
- {
- #region Factor constants
-
- private const int byteFactor = sizeof(byte) * 8;
- private const int ushortFactor = sizeof(ushort) * 8;
- private const int uintFactor = sizeof(uint) * 8;
- private const int ulongFactor = sizeof(ulong) * 8;
- private const int sbyteFactor = sizeof(sbyte) * 8;
- private const int shortFactor = sizeof(short) * 8;
- private const int intFactor = sizeof(int) * 8;
- private const int longFactor = sizeof(long) * 8;
-
- #endregion
- #region Get operations
-
- public static bool GetBit(this IList<byte> list, int index)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * byteFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- return (list[index / byteFactor] & (1 << (index % byteFactor))) != 0;
- }
-
- public static bool GetBit(this IList<ushort> list, int index)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * ushortFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- return (list[index / ushortFactor] & (1 << (index % ushortFactor))) != 0;
- }
-
- public static bool GetBit(this IList<uint> list, int index)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * uintFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- return (list[index / uintFactor] & (1 << (index % uintFactor))) != 0;
- }
-
- public static bool GetBit(this IList<ulong> list, int index)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * ulongFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- return (list[index / ulongFactor] & (1UL << (index % ulongFactor))) != 0;
- }
-
- public static bool GetBit(this IList<sbyte> list, int index)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * sbyteFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- return (list[index / sbyteFactor] & (1 << (index % sbyteFactor))) != 0;
- }
-
- public static bool GetBit(this IList<short> list, int index)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * shortFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- return (list[index / shortFactor] & (1 << (index % shortFactor))) != 0;
- }
-
- public static bool GetBit(this IList<int> list, int index)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * intFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- return (list[index / intFactor] & (1 << (index % intFactor))) != 0;
- }
-
- public static bool GetBit(this IList<long> list, int index)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * longFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- return (list[index / longFactor] & (1L << (index % longFactor))) != 0;
- }
-
- public static IEnumerable<bool> GetBits(this IList<byte> list, int index, int count)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * byteFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * byteFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / byteFactor;
- int j = index % byteFactor;
- while (count-- > 0)
- {
- yield return (list[i] & (byte)(1 << j)) != 0;
- if (++j >= byteFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- public static IEnumerable<bool> GetBits(this IList<ushort> list, int index, int count)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * ushortFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * ushortFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / ushortFactor;
- int j = index % ushortFactor;
- while (count-- > 0)
- {
- yield return (list[i] & (ushort)(1 << j)) != 0;
- if (++j >= ushortFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- public static IEnumerable<bool> GetBits(this IList<uint> list, int index, int count)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * uintFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * uintFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / uintFactor;
- int j = index % uintFactor;
- while (count-- > 0)
- {
- yield return (list[i] & (1U << j)) != 0;
- if (++j >= uintFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- public static IEnumerable<bool> GetBits(this IList<ulong> list, int index, int count)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * ulongFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * ulongFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / ulongFactor;
- int j = index % ulongFactor;
- while (count-- > 0)
- {
- yield return (list[i] & (1UL << j)) != 0;
- if (++j >= ulongFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- public static IEnumerable<bool> GetBits(this IList<sbyte> list, int index, int count)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * sbyteFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * sbyteFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / sbyteFactor;
- int j = index % sbyteFactor;
- while (count-- > 0)
- {
- yield return (list[i] & (sbyte)(1 << j)) != 0;
- if (++j >= sbyteFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- public static IEnumerable<bool> GetBits(this IList<short> list, int index, int count)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * shortFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * shortFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / shortFactor;
- int j = index % shortFactor;
- while (count-- > 0)
- {
- yield return (list[i] & (short)(1 << j)) != 0;
- if (++j >= shortFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- public static IEnumerable<bool> GetBits(this IList<int> list, int index, int count)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * intFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * intFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / intFactor;
- int j = index % intFactor;
- while (count-- > 0)
- {
- yield return (list[i] & (1 << j)) != 0;
- if (++j >= intFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- public static IEnumerable<bool> GetBits(this IList<long> list, int index, int count)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * longFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * longFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / longFactor;
- int j = index % longFactor;
- while (count-- > 0)
- {
- yield return (list[i] & (1L << j)) != 0;
- if (++j >= longFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- #endregion
- #region Set operations
-
- public static void SetBit(this IList<byte> list, int index, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * byteFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- if (value)
- list[index / byteFactor] |= (byte)(1 << (index % byteFactor));
- else
- list[index / byteFactor] &= (byte)~(1 << (index % byteFactor));
- }
-
- public static void SetBit(this IList<ushort> list, int index, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * ushortFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- if (value)
- list[index / ushortFactor] |= (ushort)(1 << (index % ushortFactor));
- else
- list[index / ushortFactor] &= (ushort)~(1 << (index % ushortFactor));
- }
-
- public static void SetBit(this IList<uint> list, int index, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * uintFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- if (value)
- list[index / uintFactor] |= (1U << (index % uintFactor));
- else
- list[index / uintFactor] &= ~(1U << (index % uintFactor));
- }
-
- public static void SetBit(this IList<ulong> list, int index, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * ulongFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- if (value)
- list[index / ulongFactor] |= (1UL << (index % ulongFactor));
- else
- list[index / ulongFactor] &= ~(1UL << (index % ulongFactor));
- }
-
- public static void SetBit(this IList<sbyte> list, int index, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * sbyteFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- if (value)
- list[index / sbyteFactor] |= (sbyte)(1 << (index % sbyteFactor));
- else
- list[index / sbyteFactor] &= (sbyte)~(1 << (index % sbyteFactor));
- }
-
- public static void SetBit(this IList<short> list, int index, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * shortFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- if (value)
- list[index / shortFactor] |= (short)(1 << (index % shortFactor));
- else
- list[index / shortFactor] &= (short)~(1 << (index % shortFactor));
- }
-
- public static void SetBit(this IList<int> list, int index, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * intFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- if (value)
- list[index / intFactor] |= (1 << (index % intFactor));
- else
- list[index / intFactor] &= ~(1 << (index % intFactor));
- }
-
- public static void SetBit(this IList<long> list, int index, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index >= list.Count * longFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- if (value)
- list[index / longFactor] |= (1L << (index % longFactor));
- else
- list[index / longFactor] &= ~(1L << (index % longFactor));
- }
-
- public static void SetBits(this IList<byte> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * byteFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * byteFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / byteFactor;
- int j = index % byteFactor;
- while (count-- > 0)
- {
- if (value)
- list[i] |= (byte)(1 << j);
- else
- list[i] &= (byte)~(1 << j);
- if (++j >= byteFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- public static void SetBits(this IList<ushort> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * ushortFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * ushortFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / ushortFactor;
- int j = index % ushortFactor;
- while (count-- > 0)
- {
- if (value)
- list[i] |= (ushort)(1 << j);
- else
- list[i] &= (ushort)~(1 << j);
- if (++j >= ushortFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- public static void SetBits(this IList<uint> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * uintFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * uintFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / uintFactor;
- int j = index % uintFactor;
- while (count-- > 0)
- {
- if (value)
- list[i] |= (1U << j);
- else
- list[i] &= ~(1U << j);
- if (++j >= uintFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- public static void SetBits(this IList<ulong> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * ulongFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * ulongFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / ulongFactor;
- int j = index % ulongFactor;
- while (count-- > 0)
- {
- if (value)
- list[i] |= (1UL << j);
- else
- list[i] &= ~(1UL << j);
- if (++j >= ulongFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- public static void SetBits(this IList<sbyte> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * sbyteFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * sbyteFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / sbyteFactor;
- int j = index % sbyteFactor;
- while (count-- > 0)
- {
- if (value)
- list[i] |= (sbyte)(1 << j);
- else
- list[i] &= (sbyte)~(1 << j);
- if (++j >= sbyteFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- public static void SetBits(this IList<short> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * shortFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * shortFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / shortFactor;
- int j = index % shortFactor;
- while (count-- > 0)
- {
- if (value)
- list[i] |= (short)(1 << j);
- else
- list[i] &= (short)~(1 << j);
- if (++j >= shortFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- public static void SetBits(this IList<int> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * intFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * intFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / intFactor;
- int j = index % intFactor;
- while (count-- > 0)
- {
- if (value)
- list[i] |= (1 << j);
- else
- list[i] &= ~(1 << j);
- if (++j >= intFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- public static void SetBits(this IList<long> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * longFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * longFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / longFactor;
- int j = index % longFactor;
- while (count-- > 0)
- {
- if (value)
- list[i] |= (1L << j);
- else
- list[i] &= ~(1L << j);
- if (++j >= longFactor)
- {
- j = 0;
- i++;
- }
- }
- }
-
- public static void SetBits(this IList<byte> list, int index, IEnumerable<bool> coll)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (coll == null)
- throw new ArgumentNullException("coll");
- if (index < 0 || index >= list.Count * byteFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- using (IEnumerator<bool> e = coll.GetEnumerator())
- {
- int i = index / byteFactor;
- int j = index % byteFactor;
- while (i < list.Count && e.MoveNext())
- {
- if (e.Current)
- list[i] |= (byte)(1 << j);
- else
- list[i] &= (byte)~(1 << j);
- if (++j >= byteFactor)
- {
- j = 0;
- i++;
- }
- }
- }
- }
-
- public static void SetBits(this IList<ushort> list, int index, IEnumerable<bool> coll)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (coll == null)
- throw new ArgumentNullException("coll");
- if (index < 0 || index >= list.Count * ushortFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- using (IEnumerator<bool> e = coll.GetEnumerator())
- {
- int i = index / ushortFactor;
- int j = index % ushortFactor;
- while (i < list.Count && e.MoveNext())
- {
- if (e.Current)
- list[i] |= (ushort)(1 << j);
- else
- list[i] &= (ushort)~(1 << j);
- if (++j >= ushortFactor)
- {
- j = 0;
- i++;
- }
- }
- }
- }
-
- public static void SetBits(this IList<uint> list, int index, IEnumerable<bool> coll)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (coll == null)
- throw new ArgumentNullException("coll");
- if (index < 0 || index >= list.Count * uintFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- using (IEnumerator<bool> e = coll.GetEnumerator())
- {
- int i = index / uintFactor;
- int j = index % uintFactor;
- while (i < list.Count && e.MoveNext())
- {
- if (e.Current)
- list[i] |= (1U << j);
- else
- list[i] &= ~(1U << j);
- if (++j >= uintFactor)
- {
- j = 0;
- i++;
- }
- }
- }
- }
-
- public static void SetBits(this IList<ulong> list, int index, IEnumerable<bool> coll)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (coll == null)
- throw new ArgumentNullException("coll");
- if (index < 0 || index >= list.Count * ulongFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- using (IEnumerator<bool> e = coll.GetEnumerator())
- {
- int i = index / ulongFactor;
- int j = index % ulongFactor;
- while (i < list.Count && e.MoveNext())
- {
- if (e.Current)
- list[i] |= (1UL << j);
- else
- list[i] &= ~(1UL << j);
- if (++j >= ulongFactor)
- {
- j = 0;
- i++;
- }
- }
- }
- }
-
- public static void SetBits(this IList<sbyte> list, int index, IEnumerable<bool> coll)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (coll == null)
- throw new ArgumentNullException("coll");
- if (index < 0 || index >= list.Count * sbyteFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- using (IEnumerator<bool> e = coll.GetEnumerator())
- {
- int i = index / sbyteFactor;
- int j = index % sbyteFactor;
- while (i < list.Count && e.MoveNext())
- {
- if (e.Current)
- list[i] |= (sbyte)(1 << j);
- else
- list[i] &= (sbyte)~(1 << j);
- if (++j >= sbyteFactor)
- {
- j = 0;
- i++;
- }
- }
- }
- }
-
- public static void SetBits(this IList<short> list, int index, IEnumerable<bool> coll)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (coll == null)
- throw new ArgumentNullException("coll");
- if (index < 0 || index >= list.Count * shortFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- using (IEnumerator<bool> e = coll.GetEnumerator())
- {
- int i = index / shortFactor;
- int j = index % shortFactor;
- while (i < list.Count && e.MoveNext())
- {
- if (e.Current)
- list[i] |= (short)(1 << j);
- else
- list[i] &= (short)~(1 << j);
- if (++j >= shortFactor)
- {
- j = 0;
- i++;
- }
- }
- }
- }
-
- public static void SetBits(this IList<int> list, int index, IEnumerable<bool> coll)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (coll == null)
- throw new ArgumentNullException("coll");
- if (index < 0 || index >= list.Count * intFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- using (IEnumerator<bool> e = coll.GetEnumerator())
- {
- int i = index / intFactor;
- int j = index % intFactor;
- while (i < list.Count && e.MoveNext())
- {
- if (e.Current)
- list[i] |= (1 << j);
- else
- list[i] &= ~(1 << j);
- if (++j >= intFactor)
- {
- j = 0;
- i++;
- }
- }
- }
- }
-
- public static void SetBits(this IList<long> list, int index, IEnumerable<bool> coll)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (coll == null)
- throw new ArgumentNullException("coll");
- if (index < 0 || index >= list.Count * longFactor)
- throw new ArgumentOutOfRangeException("index");
- //
- using (IEnumerator<bool> e = coll.GetEnumerator())
- {
- int i = index / longFactor;
- int j = index % longFactor;
- while (i < list.Count && e.MoveNext())
- {
- if (e.Current)
- list[i] |= (1L << j);
- else
- list[i] &= ~(1L << j);
- if (++j >= longFactor)
- {
- j = 0;
- i++;
- }
- }
- }
- }
-
- #endregion
- #region Retrieval operations
-
- public static int IndexOf(this IList<byte> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * byteFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * byteFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / byteFactor;
- int j = index % byteFactor;
- while (count-- > 0)
- {
- if (((list[i] & (byte)(1 << j)) != 0) == value)
- return i * byteFactor + j;
- if (++j >= byteFactor)
- {
- j = 0;
- i++;
- }
- }
- return -1;
- }
-
- public static int IndexOf(this IList<ushort> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * ushortFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * ushortFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / ushortFactor;
- int j = index % ushortFactor;
- while (count-- > 0)
- {
- if (((list[i] & (ushort)(1 << j)) != 0) == value)
- return i * ushortFactor + j;
- if (++j >= ushortFactor)
- {
- j = 0;
- i++;
- }
- }
- return -1;
- }
-
- public static int IndexOf(this IList<uint> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * uintFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * uintFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / uintFactor;
- int j = index % uintFactor;
- while (count-- > 0)
- {
- if (((list[i] & (1U << j)) != 0) == value)
- return i * uintFactor + j;
- if (++j >= uintFactor)
- {
- j = 0;
- i++;
- }
- }
- return -1;
- }
-
- public static int IndexOf(this IList<ulong> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * ulongFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * ulongFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / ulongFactor;
- int j = index % ulongFactor;
- while (count-- > 0)
- {
- if (((list[i] & (1UL << j)) != 0) == value)
- return i * ulongFactor + j;
- if (++j >= ulongFactor)
- {
- j = 0;
- i++;
- }
- }
- return -1;
- }
-
- public static int IndexOf(this IList<sbyte> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * sbyteFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * sbyteFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / sbyteFactor;
- int j = index % sbyteFactor;
- while (count-- > 0)
- {
- if (((list[i] & (sbyte)(1 << j)) != 0) == value)
- return i * sbyteFactor + j;
- if (++j >= sbyteFactor)
- {
- j = 0;
- i++;
- }
- }
- return -1;
- }
-
- public static int IndexOf(this IList<short> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * shortFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * shortFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / shortFactor;
- int j = index % shortFactor;
- while (count-- > 0)
- {
- if (((list[i] & (short)(1 << j)) != 0) == value)
- return i * shortFactor + j;
- if (++j >= shortFactor)
- {
- j = 0;
- i++;
- }
- }
- return -1;
- }
-
- public static int IndexOf(this IList<int> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * intFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * intFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / intFactor;
- int j = index % intFactor;
- while (count-- > 0)
- {
- if (((list[i] & (1 << j)) != 0) == value)
- return i * intFactor + j;
- if (++j >= intFactor)
- {
- j = 0;
- i++;
- }
- }
- return -1;
- }
-
- public static int IndexOf(this IList<long> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < 0 || index > list.Count * longFactor)
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > list.Count * longFactor - index)
- throw new ArgumentOutOfRangeException("count");
- //
- int i = index / longFactor;
- int j = index % longFactor;
- while (count-- > 0)
- {
- if (((list[i] & (1L << j)) != 0) == value)
- return i * longFactor + j;
- if (++j >= longFactor)
- {
- j = 0;
- i++;
- }
- }
- return -1;
- }
-
- public static int LastIndexOf(this IList<byte> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < -1 || index >= list.Count * byteFactor + (list.Count == 0 ? 1 : 0))
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > index + 1)
- throw new ArgumentOutOfRangeException("count");
- //
- int total = list.Count * byteFactor;
- int i = (total - 1) / byteFactor;
- int j = (total - 1) % byteFactor;
- while (count-- > 0)
- {
- if (((list[i] & (byte)(1 << j)) != 0) == value)
- return i * byteFactor + j;
- if (--j < 0)
- {
- j = byteFactor - 1;
- i--;
- }
- }
- return -1;
- }
-
- public static int LastIndexOf(this IList<ushort> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < -1 || index >= list.Count * ushortFactor + (list.Count == 0 ? 1 : 0))
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > index + 1)
- throw new ArgumentOutOfRangeException("count");
- //
- int total = list.Count * ushortFactor;
- int i = (total - 1) / ushortFactor;
- int j = (total - 1) % ushortFactor;
- while (count-- > 0)
- {
- if (((list[i] & (ushort)(1 << j)) != 0) == value)
- return i * ushortFactor + j;
- if (--j < 0)
- {
- j = ushortFactor - 1;
- i--;
- }
- }
- return -1;
- }
-
- public static int LastIndexOf(this IList<uint> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < -1 || index >= list.Count * uintFactor + (list.Count == 0 ? 1 : 0))
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > index + 1)
- throw new ArgumentOutOfRangeException("count");
- //
- int total = list.Count * uintFactor;
- int i = (total - 1) / uintFactor;
- int j = (total - 1) % uintFactor;
- while (count-- > 0)
- {
- if (((list[i] & (1U << j)) != 0) == value)
- return i * uintFactor + j;
- if (--j < 0)
- {
- j = uintFactor - 1;
- i--;
- }
- }
- return -1;
- }
-
- public static int LastIndexOf(this IList<ulong> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < -1 || index >= list.Count * ulongFactor + (list.Count == 0 ? 1 : 0))
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > index + 1)
- throw new ArgumentOutOfRangeException("count");
- //
- int total = list.Count * ulongFactor;
- int i = (total - 1) / ulongFactor;
- int j = (total - 1) % ulongFactor;
- while (count-- > 0)
- {
- if (((list[i] & (1UL << j)) != 0) == value)
- return i * ulongFactor + j;
- if (--j < 0)
- {
- j = ulongFactor - 1;
- i--;
- }
- }
- return -1;
- }
-
- public static int LastIndexOf(this IList<sbyte> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < -1 || index >= list.Count * sbyteFactor + (list.Count == 0 ? 1 : 0))
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > index + 1)
- throw new ArgumentOutOfRangeException("count");
- //
- int total = list.Count * sbyteFactor;
- int i = (total - 1) / sbyteFactor;
- int j = (total - 1) % sbyteFactor;
- while (count-- > 0)
- {
- if (((list[i] & (sbyte)(1 << j)) != 0) == value)
- return i * sbyteFactor + j;
- if (--j < 0)
- {
- j = sbyteFactor - 1;
- i--;
- }
- }
- return -1;
- }
-
- public static int LastIndexOf(this IList<short> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < -1 || index >= list.Count * shortFactor + (list.Count == 0 ? 1 : 0))
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > index + 1)
- throw new ArgumentOutOfRangeException("count");
- //
- int total = list.Count * shortFactor;
- int i = (total - 1) / shortFactor;
- int j = (total - 1) % shortFactor;
- while (count-- > 0)
- {
- if (((list[i] & (short)(1 << j)) != 0) == value)
- return i * shortFactor + j;
- if (--j < 0)
- {
- j = shortFactor - 1;
- i--;
- }
- }
- return -1;
- }
-
- public static int LastIndexOf(this IList<int> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < -1 || index >= list.Count * intFactor + (list.Count == 0 ? 1 : 0))
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > index + 1)
- throw new ArgumentOutOfRangeException("count");
- //
- int total = list.Count * intFactor;
- int i = (total - 1) / intFactor;
- int j = (total - 1) % intFactor;
- while (count-- > 0)
- {
- if (((list[i] & (1 << j)) != 0) == value)
- return i * intFactor + j;
- if (--j < 0)
- {
- j = intFactor - 1;
- i--;
- }
- }
- return -1;
- }
-
- public static int LastIndexOf(this IList<long> list, int index, int count, bool value)
- {
- if (list == null)
- throw new ArgumentNullException("list");
- if (index < -1 || index >= list.Count * longFactor + (list.Count == 0 ? 1 : 0))
- throw new ArgumentOutOfRangeException("index");
- if (count < 0 || count > index + 1)
- throw new ArgumentOutOfRangeException("count");
- //
- int total = list.Count * longFactor;
- int i = (total - 1) / longFactor;
- int j = (total - 1) % longFactor;
- while (count-- > 0)
- {
- if (((list[i] & (1L << j)) != 0) == value)
- return i * longFactor + j;
- if (--j < 0)
- {
- j = longFactor - 1;
- i--;
- }
- }
- return -1;
- }
-
- #endregion
- #region Copy operation
-
- public static void CopyBitsTo(this IList<byte> sourceList, int sourceIndex, IList<byte> targetList, int targetIndex, int count)
- {
- if (sourceList == null)
- throw new ArgumentNullException("sourceList");
- if (targetList == null)
- throw new ArgumentNullException("targetList");
- int sourceTotal = sourceList.Count * byteFactor;
- int targetTotal = targetList.Count * byteFactor;
- if (sourceIndex < 0 || sourceIndex > sourceTotal)
- throw new ArgumentOutOfRangeException("sourceIndex");
- if (targetIndex < 0 || targetIndex > targetTotal)
- throw new ArgumentOutOfRangeException("targetIndex");
- if (count < 0 || count > sourceTotal - sourceIndex || count > targetTotal - targetIndex)
- throw new ArgumentOutOfRangeException("count");
- //
- bool reverse = sourceList == targetList && targetIndex > sourceIndex;
- int sw = ((reverse) ? sourceIndex + count - 1 : sourceIndex) / byteFactor;
- int sb = ((reverse) ? sourceIndex + count - 1 : sourceIndex) % byteFactor;
- int tw = ((reverse) ? targetIndex + count - 1 : targetIndex) / byteFactor;
- int tb = ((reverse) ? targetIndex + count - 1 : targetIndex) % byteFactor;
- while (count-- > 0)
- {
- if ((sourceList[sw] & (byte)(1 << sb)) != 0)
- targetList[tw] |= (byte)(1 << tb);
- else
- targetList[tw] &= (byte)~(1 << tb);
- if (reverse)
- {
- if (--sb < 0)
- {
- sb = byteFactor - 1;
- sw--;
- }
- if (--tb < 0)
- {
- tb = byteFactor - 1;
- tw-- ;
- }
- }
- else
- {
- if (++sb >= byteFactor)
- {
- sb = 0;
- sw++;
- }
- if (++tb >= byteFactor)
- {
- tb = 0;
- tw++;
- }
- }
- }
- }
-
- public static void CopyBitsTo(this IList<ushort> sourceList, int sourceIndex, IList<ushort> targetList, int targetIndex, int count)
- {
- if (sourceList == null)
- throw new ArgumentNullException("sourceList");
- if (targetList == null)
- throw new ArgumentNullException("targetList");
- int sourceTotal = sourceList.Count * ushortFactor;
- int targetTotal = targetList.Count * ushortFactor;
- if (sourceIndex < 0 || sourceIndex > sourceTotal)
- throw new ArgumentOutOfRangeException("sourceIndex");
- if (targetIndex < 0 || targetIndex > targetTotal)
- throw new ArgumentOutOfRangeException("targetIndex");
- if (count < 0 || count > sourceTotal - sourceIndex || count > targetTotal - targetIndex)
- throw new ArgumentOutOfRangeException("count");
- //
- bool reverse = sourceList == targetList && targetIndex > sourceIndex;
- int sw = ((reverse) ? sourceIndex + count - 1 : sourceIndex) / ushortFactor;
- int sb = ((reverse) ? sourceIndex + count - 1 : sourceIndex) % ushortFactor;
- int tw = ((reverse) ? targetIndex + count - 1 : targetIndex) / ushortFactor;
- int tb = ((reverse) ? targetIndex + count - 1 : targetIndex) % ushortFactor;
- while (count-- > 0)
- {
- if ((sourceList[sw] & (ushort)(1 << sb)) != 0)
- targetList[tw] |= (ushort)(1 << tb);
- else
- targetList[tw] &= (ushort)~(1 << tb);
- if (reverse)
- {
- if (--sb < 0)
- {
- sb = ushortFactor - 1;
- sw--;
- }
- if (--tb < 0)
- {
- tb = ushortFactor - 1;
- tw--;
- }
- }
- else
- {
- if (++sb >= ushortFactor)
- {
- sb = 0;
- sw++;
- }
- if (++tb >= ushortFactor)
- {
- tb = 0;
- tw++;
- }
- }
- }
- }
-
- public static void CopyBitsTo(this IList<uint> sourceList, int sourceIndex, IList<uint> targetList, int targetIndex, int count)
- {
- if (sourceList == null)
- throw new ArgumentNullException("sourceList");
- if (targetList == null)
- throw new ArgumentNullException("targetList");
- int sourceTotal = sourceList.Count * uintFactor;
- int targetTotal = targetList.Count * uintFactor;
- if (sourceIndex < 0 || sourceIndex > sourceTotal)
- throw new ArgumentOutOfRangeException("sourceIndex");
- if (targetIndex < 0 || targetIndex > targetTotal)
- throw new ArgumentOutOfRangeException("targetIndex");
- if (count < 0 || count > sourceTotal - sourceIndex || count > targetTotal - targetIndex)
- throw new ArgumentOutOfRangeException("count");
- //
- bool reverse = sourceList == targetList && targetIndex > sourceIndex;
- int sw = ((reverse) ? sourceIndex + count - 1 : sourceIndex) / uintFactor;
- int sb = ((reverse) ? sourceIndex + count - 1 : sourceIndex) % uintFactor;
- int tw = ((reverse) ? targetIndex + count - 1 : targetIndex) / uintFactor;
- int tb = ((reverse) ? targetIndex + count - 1 : targetIndex) % uintFactor;
- while (count-- > 0)
- {
- if ((sourceList[sw] & (1U << sb)) != 0)
- targetList[tw] |= (1U << tb);
- else
- targetList[tw] &= ~(1U << tb);
- if (reverse)
- {
- if (--sb < 0)
- {
- sb = uintFactor - 1;
- sw--;
- }
- if (--tb < 0)
- {
- tb = uintFactor - 1;
- tw--;
- }
- }
- else
- {
- if (++sb >= uintFactor)
- {
- sb = 0;
- sw++;
- }
- if (++tb >= uintFactor)
- {
- tb = 0;
- tw++;
- }
- }
- }
- }
-
- public static void CopyBitsTo(this IList<ulong> sourceList, int sourceIndex, IList<ulong> targetList, int targetIndex, int count)
- {
- if (sourceList == null)
- throw new ArgumentNullException("sourceList");
- if (targetList == null)
- throw new ArgumentNullException("targetList");
- int sourceTotal = sourceList.Count * ulongFactor;
- int targetTotal = targetList.Count * ulongFactor;
- if (sourceIndex < 0 || sourceIndex > sourceTotal)
- throw new ArgumentOutOfRangeException("sourceIndex");
- if (targetIndex < 0 || targetIndex > targetTotal)
- throw new ArgumentOutOfRangeException("targetIndex");
- if (count < 0 || count > sourceTotal - sourceIndex || count > targetTotal - targetIndex)
- throw new ArgumentOutOfRangeException("count");
- //
- bool reverse = sourceList == targetList && targetIndex > sourceIndex;
- int sw = ((reverse) ? sourceIndex + count - 1 : sourceIndex) / ulongFactor;
- int sb = ((reverse) ? sourceIndex + count - 1 : sourceIndex) % ulongFactor;
- int tw = ((reverse) ? targetIndex + count - 1 : targetIndex) / ulongFactor;
- int tb = ((reverse) ? targetIndex + count - 1 : targetIndex) % ulongFactor;
- while (count-- > 0)
- {
- if ((sourceList[sw] & (1UL << sb)) != 0)
- targetList[tw] |= (1UL << tb);
- else
- targetList[tw] &= ~(1UL << tb);
- if (reverse)
- {
- if (--sb < 0)
- {
- sb = ulongFactor - 1;
- sw--;
- }
- if (--tb < 0)
- {
- tb = ulongFactor - 1;
- tw--;
- }
- }
- else
- {
- if (++sb >= ulongFactor)
- {
- sb = 0;
- sw++;
- }
- if (++tb >= ulongFactor)
- {
- tb = 0;
- tw++;
- }
- }
- }
- }
-
- public static void CopyBitsTo(this IList<sbyte> sourceList, int sourceIndex, IList<sbyte> targetList, int targetIndex, int count)
- {
- if (sourceList == null)
- throw new ArgumentNullException("sourceList");
- if (targetList == null)
- throw new ArgumentNullException("targetList");
- int sourceTotal = sourceList.Count * sbyteFactor;
- int targetTotal = targetList.Count * sbyteFactor;
- if (sourceIndex < 0 || sourceIndex > sourceTotal)
- throw new ArgumentOutOfRangeException("sourceIndex");
- if (targetIndex < 0 || targetIndex > targetTotal)
- throw new ArgumentOutOfRangeException("targetIndex");
- if (count < 0 || count > sourceTotal - sourceIndex || count > targetTotal - targetIndex)
- throw new ArgumentOutOfRangeException("count");
- //
- bool reverse = sourceList == targetList && targetIndex > sourceIndex;
- int sw = ((reverse) ? sourceIndex + count - 1 : sourceIndex) / sbyteFactor;
- int sb = ((reverse) ? sourceIndex + count - 1 : sourceIndex) % sbyteFactor;
- int tw = ((reverse) ? targetIndex + count - 1 : targetIndex) / sbyteFactor;
- int tb = ((reverse) ? targetIndex + count - 1 : targetIndex) % sbyteFactor;
- while (count-- > 0)
- {
- if ((sourceList[sw] & (sbyte)(1 << sb)) != 0)
- targetList[tw] |= (sbyte)(1 << tb);
- else
- targetList[tw] &= (sbyte)~(1 << tb);
- if (reverse)
- {
- if (--sb < 0)
- {
- sb = sbyteFactor - 1;
- sw--;
- }
- if (--tb < 0)
- {
- tb = sbyteFactor - 1;
- tw--;
- }
- }
- else
- {
- if (++sb >= sbyteFactor)
- {
- sb = 0;
- sw++;
- }
- if (++tb >= sbyteFactor)
- {
- tb = 0;
- tw++;
- }
- }
- }
- }
-
- public static void CopyBitsTo(this IList<short> sourceList, int sourceIndex, IList<short> targetList, int targetIndex, int count)
- {
- if (sourceList == null)
- throw new ArgumentNullException("sourceList");
- if (targetList == null)
- throw new ArgumentNullException("targetList");
- int sourceTotal = sourceList.Count * shortFactor;
- int targetTotal = targetList.Count * shortFactor;
- if (sourceIndex < 0 || sourceIndex > sourceTotal)
- throw new ArgumentOutOfRangeException("sourceIndex");
- if (targetIndex < 0 || targetIndex > targetTotal)
- throw new ArgumentOutOfRangeException("targetIndex");
- if (count < 0 || count > sourceTotal - sourceIndex || count > targetTotal - targetIndex)
- throw new ArgumentOutOfRangeException("count");
- //
- bool reverse = sourceList == targetList && targetIndex > sourceIndex;
- int sw = ((reverse) ? sourceIndex + count - 1 : sourceIndex) / shortFactor;
- int sb = ((reverse) ? sourceIndex + count - 1 : sourceIndex) % shortFactor;
- int tw = ((reverse) ? targetIndex + count - 1 : targetIndex) / shortFactor;
- int tb = ((reverse) ? targetIndex + count - 1 : targetIndex) % shortFactor;
- while (count-- > 0)
- {
- if ((sourceList[sw] & (short)(1 << sb)) != 0)
- targetList[tw] |= (short)(1 << tb);
- else
- targetList[tw] &= (short)~(1 << tb);
- if (reverse)
- {
- if (--sb < 0)
- {
- sb = shortFactor - 1;
- sw--;
- }
- if (--tb < 0)
- {
- tb = shortFactor - 1;
- tw--;
- }
- }
- else
- {
- if (++sb >= shortFactor)
- {
- sb = 0;
- sw++;
- }
- if (++tb >= shortFactor)
- {
- tb = 0;
- tw++;
- }
- }
- }
- }
-
- public static void CopyBitsTo(this IList<int> sourceList, int sourceIndex, IList<int> targetList, int targetIndex, int count)
- {
- if (sourceList == null)
- throw new ArgumentNullException("sourceList");
- if (targetList == null)
- throw new ArgumentNullException("targetList");
- int sourceTotal = sourceList.Count * intFactor;
- int targetTotal = targetList.Count * intFactor;
- if (sourceIndex < 0 || sourceIndex > sourceTotal)
- throw new ArgumentOutOfRangeException("sourceIndex");
- if (targetIndex < 0 || targetIndex > targetTotal)
- throw new ArgumentOutOfRangeException("targetIndex");
- if (count < 0 || count > sourceTotal - sourceIndex || count > targetTotal - targetIndex)
- throw new ArgumentOutOfRangeException("count");
- //
- bool reverse = sourceList == targetList && targetIndex > sourceIndex;
- int sw = ((reverse) ? sourceIndex + count - 1 : sourceIndex) / intFactor;
- int sb = ((reverse) ? sourceIndex + count - 1 : sourceIndex) % intFactor;
- int tw = ((reverse) ? targetIndex + count - 1 : targetIndex) / intFactor;
- int tb = ((reverse) ? targetIndex + count - 1 : targetIndex) % intFactor;
- while (count-- > 0)
- {
- if ((sourceList[sw] & (1 << sb)) != 0)
- targetList[tw] |= (1 << tb);
- else
- targetList[tw] &= ~(1 << tb);
- if (reverse)
- {
- if (--sb < 0)
- {
- sb = intFactor - 1;
- sw--;
- }
- if (--tb < 0)
- {
- tb = intFactor - 1;
- tw--;
- }
- }
- else
- {
- if (++sb >= intFactor)
- {
- sb = 0;
- sw++;
- }
- if (++tb >= intFactor)
- {
- tb = 0;
- tw++;
- }
- }
- }
- }
-
- public static void CopyBitsTo(this IList<long> sourceList, int sourceIndex, IList<long> targetList, int targetIndex, int count)
- {
- if (sourceList == null)
- throw new ArgumentNullException("sourceList");
- if (targetList == null)
- throw new ArgumentNullException("targetList");
- int sourceTotal = sourceList.Count * longFactor;
- int targetTotal = targetList.Count * longFactor;
- if (sourceIndex < 0 || sourceIndex > sourceTotal)
- throw new ArgumentOutOfRangeException("sourceIndex");
- if (targetIndex < 0 || targetIndex > targetTotal)
- throw new ArgumentOutOfRangeException("targetIndex");
- if (count < 0 || count > sourceTotal - sourceIndex || count > targetTotal - targetIndex)
- throw new ArgumentOutOfRangeException("count");
- //
- bool reverse = sourceList == targetList && targetIndex > sourceIndex;
- int sw = ((reverse) ? sourceIndex + count - 1 : sourceIndex) / longFactor;
- int sb = ((reverse) ? sourceIndex + count - 1 : sourceIndex) % longFactor;
- int tw = ((reverse) ? targetIndex + count - 1 : targetIndex) / longFactor;
- int tb = ((reverse) ? targetIndex + count - 1 : targetIndex) % longFactor;
- while (count-- > 0)
- {
- if ((sourceList[sw] & (1L << sb)) != 0)
- targetList[tw] |= (1L << tb);
- else
- targetList[tw] &= ~(1L << tb);
- if (reverse)
- {
- if (--sb < 0)
- {
- sb = longFactor - 1;
- sw--;
- }
- if (--tb < 0)
- {
- tb = longFactor - 1;
- tw--;
- }
- }
- else
- {
- if (++sb >= longFactor)
- {
- sb = 0;
- sw++;
- }
- if (++tb >= longFactor)
- {
- tb = 0;
- tw++;
- }
- }
- }
- }
-
- #endregion
- #region Equals operation
-
- public static bool EqualsBits(this IList<byte> xList, int xIndex, IList<byte> yList, int yIndex, int count)
- {
- if (xList == null)
- throw new ArgumentNullException("xList");
- if (yList == null)
- throw new ArgumentNullException("yList");
- int xTotal = xList.Count * byteFactor;
- int yTotal = yList.Count * byteFactor;
- if (xIndex < 0 || xIndex > xTotal)
- throw new ArgumentOutOfRangeException("xIndex");
- if (yIndex < 0 || yIndex > yTotal)
- throw new ArgumentOutOfRangeException("yIndex");
- if (count < 0 || count > xTotal - xIndex || count > yTotal - yIndex)
- throw new ArgumentOutOfRangeException("count");
- if (xList == yList && count > global::System.Math.Abs(yIndex - xIndex))
- throw new ArgumentException("Ranges intersected");
- //
- int xw = xIndex / byteFactor;
- int xb = xIndex % byteFactor;
- int yw = yIndex / byteFactor;
- int yb = yIndex % byteFactor;
- while (count-- > 0)
- {
- if (((xList[xw] & (byte)(1 << xb)) != 0) != ((yList[yw] & (byte)(1 << yb)) != 0))
- return false;
- if (++xb >= byteFactor)
- {
- xb = 0;
- xw++;
- }
- if (++yb >= byteFactor)
- {
- yb = 0;
- yw++;
- }
- }
- return true;
- }
-
- public static bool EqualsBits(this IList<ushort> xList, int xIndex, IList<ushort> yList, int yIndex, int count)
- {
- if (xList == null)
- throw new ArgumentNullException("xList");
- if (yList == null)
- throw new ArgumentNullException("yList");
- int xTotal = xList.Count * ushortFactor;
- int yTotal = yList.Count * ushortFactor;
- if (xIndex < 0 || xIndex > xTotal)
- throw new ArgumentOutOfRangeException("xIndex");
- if (yIndex < 0 || yIndex > yTotal)
- throw new ArgumentOutOfRangeException("yIndex");
- if (count < 0 || count > xTotal - xIndex || count > yTotal - yIndex)
- throw new ArgumentOutOfRangeException("count");
- if (xList == yList && count > global::System.Math.Abs(yIndex - xIndex))
- throw new ArgumentException("Ranges intersected");
- //
- int xw = xIndex / ushortFactor;
- int xb = xIndex % ushortFactor;
- int yw = yIndex / ushortFactor;
- int yb = yIndex % ushortFactor;
- while (count-- > 0)
- {
- …
Large files files are truncated, but you can click here to view the full file