Added Remove Tests and Remove Methods

This commit is contained in:
MarcUs7i 2024-11-27 17:56:36 +01:00
parent 1fe40ef8ab
commit f54f8f397a
2 changed files with 209 additions and 0 deletions

View file

@ -55,6 +55,53 @@ public class FlexArrayString
return false;
}
public bool Remove(string value, bool firstOnly)
{
var removedAny = false;
for (var i = 0; i < Count; i++)
{
if (value != _data[i])
{
continue;
}
RemoveAt(i--);
removedAny = true;
if (firstOnly)
{
break;
}
}
return removedAny;
}
public bool RemoveAt(int index)
{
if (index < 0 || index >= Count)
{
return false;
}
if (index != Count - 1)
{
ShiftLeft(index);
}
Count--;
return true;
}
private void ShiftLeft(int fromIndex)
{
for (var i = fromIndex; i < Count; i++)
{
_data[i] = _data[i + 1];
}
}
private void Grow()
{