Core/Refactor: Part 2
This commit is contained in:
@@ -29,13 +29,13 @@ namespace System.Collections
|
||||
}
|
||||
Contract.EndContractBlock();
|
||||
|
||||
m_array = new uint[GetArrayLength(length, BitsPerInt32)];
|
||||
m_length = length;
|
||||
_mArray = new uint[GetArrayLength(length, BitsPerInt32)];
|
||||
_mLength = length;
|
||||
|
||||
uint fillValue = defaultValue ? 0xffffffff : 0;
|
||||
for (int i = 0; i < m_array.Length; i++)
|
||||
for (int i = 0; i < _mArray.Length; i++)
|
||||
{
|
||||
m_array[i] = fillValue;
|
||||
_mArray[i] = fillValue;
|
||||
}
|
||||
|
||||
_version = 0;
|
||||
@@ -54,10 +54,10 @@ namespace System.Collections
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
m_array = new uint[values.Length];
|
||||
m_length = values.Length * BitsPerInt32;
|
||||
_mArray = new uint[values.Length];
|
||||
_mLength = values.Length * BitsPerInt32;
|
||||
|
||||
Array.Copy(values, m_array, values.Length);
|
||||
Array.Copy(values, _mArray, values.Length);
|
||||
|
||||
_version = 0;
|
||||
}
|
||||
@@ -70,11 +70,11 @@ namespace System.Collections
|
||||
}
|
||||
Contract.EndContractBlock();
|
||||
|
||||
int arrayLength = GetArrayLength(bits.m_length, BitsPerInt32);
|
||||
m_array = new uint[arrayLength];
|
||||
m_length = bits.m_length;
|
||||
int arrayLength = GetArrayLength(bits._mLength, BitsPerInt32);
|
||||
_mArray = new uint[arrayLength];
|
||||
_mLength = bits._mLength;
|
||||
|
||||
Array.Copy(bits.m_array, m_array, arrayLength);
|
||||
Array.Copy(bits._mArray, _mArray, arrayLength);
|
||||
|
||||
_version = bits._version;
|
||||
}
|
||||
@@ -99,7 +99,7 @@ namespace System.Collections
|
||||
}
|
||||
Contract.EndContractBlock();
|
||||
|
||||
return (Convert.ToInt64(m_array[index / 32]) & (1 << (index % 32))) != 0;
|
||||
return (Convert.ToInt64(_mArray[index / 32]) & (1 << (index % 32))) != 0;
|
||||
}
|
||||
|
||||
public void Set(int index, bool value)
|
||||
@@ -112,11 +112,11 @@ namespace System.Collections
|
||||
|
||||
if (value)
|
||||
{
|
||||
m_array[index / 32] |= (1u << (index % 32));
|
||||
_mArray[index / 32] |= (1u << (index % 32));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_array[index / 32] &= ~(1u << (index % 32));
|
||||
_mArray[index / 32] &= ~(1u << (index % 32));
|
||||
}
|
||||
|
||||
_version++;
|
||||
@@ -125,10 +125,10 @@ namespace System.Collections
|
||||
public void SetAll(bool value)
|
||||
{
|
||||
uint fillValue = value ? 0xffffffff : 0u;
|
||||
int ints = GetArrayLength(m_length, BitsPerInt32);
|
||||
int ints = GetArrayLength(_mLength, BitsPerInt32);
|
||||
for (int i = 0; i < ints; i++)
|
||||
{
|
||||
m_array[i] = fillValue;
|
||||
_mArray[i] = fillValue;
|
||||
}
|
||||
|
||||
_version++;
|
||||
@@ -142,10 +142,10 @@ namespace System.Collections
|
||||
throw new ArgumentException();
|
||||
Contract.EndContractBlock();
|
||||
|
||||
int ints = GetArrayLength(m_length, BitsPerInt32);
|
||||
int ints = GetArrayLength(_mLength, BitsPerInt32);
|
||||
for (int i = 0; i < ints; i++)
|
||||
{
|
||||
m_array[i] &= value.m_array[i];
|
||||
_mArray[i] &= value._mArray[i];
|
||||
}
|
||||
|
||||
_version++;
|
||||
@@ -160,10 +160,10 @@ namespace System.Collections
|
||||
throw new ArgumentException();
|
||||
Contract.EndContractBlock();
|
||||
|
||||
int ints = GetArrayLength(m_length, BitsPerInt32);
|
||||
int ints = GetArrayLength(_mLength, BitsPerInt32);
|
||||
for (int i = 0; i < ints; i++)
|
||||
{
|
||||
m_array[i] |= value.m_array[i];
|
||||
_mArray[i] |= value._mArray[i];
|
||||
}
|
||||
|
||||
_version++;
|
||||
@@ -178,10 +178,10 @@ namespace System.Collections
|
||||
throw new ArgumentException();
|
||||
Contract.EndContractBlock();
|
||||
|
||||
int ints = GetArrayLength(m_length, BitsPerInt32);
|
||||
int ints = GetArrayLength(_mLength, BitsPerInt32);
|
||||
for (int i = 0; i < ints; i++)
|
||||
{
|
||||
m_array[i] ^= value.m_array[i];
|
||||
_mArray[i] ^= value._mArray[i];
|
||||
}
|
||||
|
||||
_version++;
|
||||
@@ -190,10 +190,10 @@ namespace System.Collections
|
||||
|
||||
public BitSet Not()
|
||||
{
|
||||
int ints = GetArrayLength(m_length, BitsPerInt32);
|
||||
int ints = GetArrayLength(_mLength, BitsPerInt32);
|
||||
for (int i = 0; i < ints; i++)
|
||||
{
|
||||
m_array[i] = ~m_array[i];
|
||||
_mArray[i] = ~_mArray[i];
|
||||
}
|
||||
|
||||
_version++;
|
||||
@@ -205,7 +205,7 @@ namespace System.Collections
|
||||
get
|
||||
{
|
||||
Contract.Ensures(Contract.Result<int>() >= 0);
|
||||
return m_length;
|
||||
return _mLength;
|
||||
}
|
||||
set
|
||||
{
|
||||
@@ -216,29 +216,29 @@ namespace System.Collections
|
||||
Contract.EndContractBlock();
|
||||
|
||||
int newints = GetArrayLength(value, BitsPerInt32);
|
||||
if (newints > m_array.Length || newints + _ShrinkThreshold < m_array.Length)
|
||||
if (newints > _mArray.Length || newints + ShrinkThreshold < _mArray.Length)
|
||||
{
|
||||
// grow or shrink (if wasting more than _ShrinkThreshold ints)
|
||||
uint[] newarray = new uint[newints];
|
||||
Array.Copy(m_array, newarray, newints > m_array.Length ? m_array.Length : newints);
|
||||
m_array = newarray;
|
||||
Array.Copy(_mArray, newarray, newints > _mArray.Length ? _mArray.Length : newints);
|
||||
_mArray = newarray;
|
||||
}
|
||||
|
||||
if (value > m_length)
|
||||
if (value > _mLength)
|
||||
{
|
||||
// clear high bit values in the last int
|
||||
int last = GetArrayLength(m_length, BitsPerInt32) - 1;
|
||||
int bits = m_length % 32;
|
||||
int last = GetArrayLength(_mLength, BitsPerInt32) - 1;
|
||||
int bits = _mLength % 32;
|
||||
if (bits > 0)
|
||||
{
|
||||
m_array[last] &= (1u << bits) - 1;
|
||||
_mArray[last] &= (1u << bits) - 1;
|
||||
}
|
||||
|
||||
// clear remaining int values
|
||||
Array.Clear(m_array, last + 1, newints - last - 1);
|
||||
Array.Clear(_mArray, last + 1, newints - last - 1);
|
||||
}
|
||||
|
||||
m_length = value;
|
||||
_mLength = value;
|
||||
_version++;
|
||||
}
|
||||
}
|
||||
@@ -259,26 +259,26 @@ namespace System.Collections
|
||||
|
||||
if (array is uint[])
|
||||
{
|
||||
Array.Copy(m_array, 0, array, index, GetArrayLength(m_length, BitsPerInt32));
|
||||
Array.Copy(_mArray, 0, array, index, GetArrayLength(_mLength, BitsPerInt32));
|
||||
}
|
||||
else if (array is byte[])
|
||||
{
|
||||
int arrayLength = GetArrayLength(m_length, BitsPerByte);
|
||||
int arrayLength = GetArrayLength(_mLength, BitsPerByte);
|
||||
if ((array.Length - index) < arrayLength)
|
||||
throw new ArgumentException();
|
||||
|
||||
byte[] b = (byte[])array;
|
||||
for (int i = 0; i < arrayLength; i++)
|
||||
b[index + i] = (byte)((m_array[i / 4] >> ((i % 4) * 8)) & 0x000000FF); // Shift to bring the required byte to LSB, then mask
|
||||
b[index + i] = (byte)((_mArray[i / 4] >> ((i % 4) * 8)) & 0x000000FF); // Shift to bring the required byte to LSB, then mask
|
||||
}
|
||||
else if (array is bool[])
|
||||
{
|
||||
if (array.Length - index < m_length)
|
||||
if (array.Length - index < _mLength)
|
||||
throw new ArgumentException();
|
||||
|
||||
bool[] b = (bool[])array;
|
||||
for (int i = 0; i < m_length; i++)
|
||||
b[index + i] = ((m_array[i / 32] >> (i % 32)) & 0x00000001) != 0;
|
||||
for (int i = 0; i < _mLength; i++)
|
||||
b[index + i] = ((_mArray[i / 32] >> (i % 32)) & 0x00000001) != 0;
|
||||
}
|
||||
else
|
||||
throw new ArgumentException();
|
||||
@@ -290,7 +290,7 @@ namespace System.Collections
|
||||
{
|
||||
Contract.Ensures(Contract.Result<int>() >= 0);
|
||||
|
||||
return (int)m_length;
|
||||
return (int)_mLength;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,9 +299,9 @@ namespace System.Collections
|
||||
Contract.Ensures(Contract.Result<Object>() != null);
|
||||
Contract.Ensures(((BitArray)Contract.Result<Object>()).Length == this.Length);
|
||||
|
||||
BitSet bitArray = new BitSet(m_array);
|
||||
BitSet bitArray = new BitSet(_mArray);
|
||||
bitArray._version = _version;
|
||||
bitArray.m_length = m_length;
|
||||
bitArray._mLength = _mLength;
|
||||
return bitArray;
|
||||
}
|
||||
|
||||
@@ -352,16 +352,16 @@ namespace System.Collections
|
||||
[Serializable]
|
||||
private class BitArrayEnumeratorSimple : IEnumerator, ICloneable
|
||||
{
|
||||
private BitSet bitarray;
|
||||
private int index;
|
||||
private int version;
|
||||
private bool currentElement;
|
||||
private BitSet _bitarray;
|
||||
private int _index;
|
||||
private int _version;
|
||||
private bool _currentElement;
|
||||
|
||||
internal BitArrayEnumeratorSimple(BitSet bitarray)
|
||||
{
|
||||
this.bitarray = bitarray;
|
||||
this.index = -1;
|
||||
version = bitarray._version;
|
||||
this._bitarray = bitarray;
|
||||
_index = -1;
|
||||
_version = bitarray._version;
|
||||
}
|
||||
|
||||
public Object Clone()
|
||||
@@ -372,14 +372,14 @@ namespace System.Collections
|
||||
public bool MoveNext()
|
||||
{
|
||||
//if (version != bitarray._version) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumFailedVersion));
|
||||
if (index < (bitarray.Count - 1))
|
||||
if (_index < (_bitarray.Count - 1))
|
||||
{
|
||||
index++;
|
||||
currentElement = bitarray.Get(index);
|
||||
_index++;
|
||||
_currentElement = _bitarray.Get(_index);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
index = bitarray.Count;
|
||||
_index = _bitarray.Count;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -388,27 +388,27 @@ namespace System.Collections
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index == -1)
|
||||
if (_index == -1)
|
||||
throw new InvalidOperationException();
|
||||
if (index >= bitarray.Count)
|
||||
if (_index >= _bitarray.Count)
|
||||
throw new InvalidOperationException();
|
||||
return currentElement;
|
||||
return _currentElement;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
//if (version != bitarray._version) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumFailedVersion));
|
||||
index = -1;
|
||||
_index = -1;
|
||||
}
|
||||
}
|
||||
|
||||
private uint[] m_array;
|
||||
private int m_length;
|
||||
private uint[] _mArray;
|
||||
private int _mLength;
|
||||
private int _version;
|
||||
[NonSerialized]
|
||||
private Object _syncRoot;
|
||||
|
||||
private const int _ShrinkThreshold = 256;
|
||||
private const int ShrinkThreshold = 256;
|
||||
}
|
||||
}
|
||||
@@ -19,84 +19,84 @@ namespace Framework.Collections
|
||||
{
|
||||
public class LinkedListElement
|
||||
{
|
||||
internal LinkedListElement iNext;
|
||||
internal LinkedListElement iPrev;
|
||||
internal LinkedListElement INext;
|
||||
internal LinkedListElement IPrev;
|
||||
|
||||
public LinkedListElement()
|
||||
{
|
||||
iNext = iPrev = null;
|
||||
INext = IPrev = null;
|
||||
}
|
||||
|
||||
~LinkedListElement() { delink(); }
|
||||
~LinkedListElement() { Delink(); }
|
||||
|
||||
bool hasNext() { return (iNext != null && iNext.iNext != null); }
|
||||
bool hasPrev() { return (iPrev != null && iPrev.iPrev != null); }
|
||||
public bool isInList() { return (iNext != null && iPrev != null); }
|
||||
bool HasNext() { return (INext != null && INext.INext != null); }
|
||||
bool HasPrev() { return (IPrev != null && IPrev.IPrev != null); }
|
||||
public bool IsInList() { return (INext != null && IPrev != null); }
|
||||
|
||||
public LinkedListElement GetNextElement() { return hasNext() ? iNext : null; }
|
||||
public LinkedListElement GetPrevElement() { return hasPrev() ? iPrev : null; }
|
||||
public LinkedListElement GetNextElement() { return HasNext() ? INext : null; }
|
||||
public LinkedListElement GetPrevElement() { return HasPrev() ? IPrev : null; }
|
||||
|
||||
public void delink()
|
||||
public void Delink()
|
||||
{
|
||||
if (!isInList())
|
||||
if (!IsInList())
|
||||
return;
|
||||
|
||||
iNext.iPrev = iPrev;
|
||||
iPrev.iNext = iNext;
|
||||
iNext = null;
|
||||
iPrev = null;
|
||||
INext.IPrev = IPrev;
|
||||
IPrev.INext = INext;
|
||||
INext = null;
|
||||
IPrev = null;
|
||||
}
|
||||
|
||||
public void insertBefore(LinkedListElement pElem)
|
||||
public void InsertBefore(LinkedListElement pElem)
|
||||
{
|
||||
pElem.iNext = this;
|
||||
pElem.iPrev = iPrev;
|
||||
iPrev.iNext = pElem;
|
||||
iPrev = pElem;
|
||||
pElem.INext = this;
|
||||
pElem.IPrev = IPrev;
|
||||
IPrev.INext = pElem;
|
||||
IPrev = pElem;
|
||||
}
|
||||
|
||||
public void insertAfter(LinkedListElement pElem)
|
||||
public void InsertAfter(LinkedListElement pElem)
|
||||
{
|
||||
pElem.iPrev = this;
|
||||
pElem.iNext = iNext;
|
||||
iNext.iPrev = pElem;
|
||||
iNext = pElem;
|
||||
pElem.IPrev = this;
|
||||
pElem.INext = INext;
|
||||
INext.IPrev = pElem;
|
||||
INext = pElem;
|
||||
}
|
||||
}
|
||||
|
||||
public class LinkedListHead
|
||||
{
|
||||
LinkedListElement iFirst = new LinkedListElement();
|
||||
LinkedListElement iLast = new LinkedListElement();
|
||||
uint iSize;
|
||||
LinkedListElement _iFirst = new LinkedListElement();
|
||||
LinkedListElement _iLast = new LinkedListElement();
|
||||
uint _iSize;
|
||||
|
||||
public LinkedListHead()
|
||||
{
|
||||
iSize = 0;
|
||||
_iSize = 0;
|
||||
// create empty list
|
||||
|
||||
iFirst.iNext = iLast;
|
||||
iLast.iPrev = iFirst;
|
||||
_iFirst.INext = _iLast;
|
||||
_iLast.IPrev = _iFirst;
|
||||
}
|
||||
|
||||
public bool isEmpty() { return (!iFirst.iNext.isInList()); }
|
||||
public bool IsEmpty() { return (!_iFirst.INext.IsInList()); }
|
||||
|
||||
public LinkedListElement GetFirstElement() { return (isEmpty() ? null : iFirst.iNext); }
|
||||
public LinkedListElement GetLastElement() { return (isEmpty() ? null : iLast.iPrev); }
|
||||
public LinkedListElement GetFirstElement() { return (IsEmpty() ? null : _iFirst.INext); }
|
||||
public LinkedListElement GetLastElement() { return (IsEmpty() ? null : _iLast.IPrev); }
|
||||
|
||||
public void insertFirst(LinkedListElement pElem)
|
||||
public void InsertFirst(LinkedListElement pElem)
|
||||
{
|
||||
iFirst.insertAfter(pElem);
|
||||
_iFirst.InsertAfter(pElem);
|
||||
}
|
||||
|
||||
public void insertLast(LinkedListElement pElem)
|
||||
public void InsertLast(LinkedListElement pElem)
|
||||
{
|
||||
iLast.insertBefore(pElem);
|
||||
_iLast.InsertBefore(pElem);
|
||||
}
|
||||
|
||||
public uint getSize()
|
||||
public uint GetSize()
|
||||
{
|
||||
if (iSize == 0)
|
||||
if (_iSize == 0)
|
||||
{
|
||||
uint result = 0;
|
||||
LinkedListElement e = GetFirstElement();
|
||||
@@ -108,10 +108,10 @@ namespace Framework.Collections
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return iSize;
|
||||
return _iSize;
|
||||
}
|
||||
|
||||
public void incSize() { ++iSize; }
|
||||
public void decSize() { --iSize; }
|
||||
public void IncSize() { ++_iSize; }
|
||||
public void DecSize() { --_iSize; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user