1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-20 08:58:00 +02:00

Added concept of strict equality

This commit is contained in:
Brian Fiete 2020-06-17 05:13:53 -07:00
parent 308605a7dd
commit abeda6909b
13 changed files with 249 additions and 79 deletions

View file

@ -420,14 +420,6 @@ namespace System.Collections
return -1;
}
public int LastIndexOf(T item)
{
for (int i = mSize - 1; i >= 0; i--)
if (mItems[i] == item)
return i;
return -1;
}
public int IndexOf(T item, int index)
{
for (int i = index; i < mSize; i++)
@ -444,6 +436,46 @@ namespace System.Collections
return -1;
}
public int IndexOfStrict(T item)
{
for (int i = 0; i < mSize; i++)
if (mItems[i] === item)
return i;
return -1;
}
public int IndexOfStrict(T item, int index)
{
for (int i = index; i < mSize; i++)
if (mItems[i] === item)
return i;
return -1;
}
public int IndexOfStrict(T item, int index, int count)
{
for (int i = index; i < index + count; i++)
if (mItems[i] === item)
return i;
return -1;
}
public int LastIndexOf(T item)
{
for (int i = mSize - 1; i >= 0; i--)
if (mItems[i] == item)
return i;
return -1;
}
public int LastIndexOfStrict(T item)
{
for (int i = mSize - 1; i >= 0; i--)
if (mItems[i] === item)
return i;
return -1;
}
public void Insert(int index, T item)
{
var item; // This creates a copy - required if item is a ref to an element
@ -577,6 +609,31 @@ namespace System.Collections
return false;
}
public bool RemoveStrict(T item)
{
int index = IndexOfStrict(item);
if (index >= 0)
{
RemoveAt(index);
return true;
}
return false;
}
public Result<T> GetAndRemove(T item)
{
int index = IndexOf(item);
if (index >= 0)
{
T val = mItems[index];
RemoveAt(index);
return val;
}
return .Err;
}
/// The method returns the index of the given value in the list. If the
/// list does not contain the given value, the method returns a negative
/// integer. The bitwise complement operator (~) can be applied to a