mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Move IndexSet to OtterGui
This commit is contained in:
parent
e058b6e32b
commit
1e471551d4
2 changed files with 1 additions and 111 deletions
2
OtterGui
2
OtterGui
|
|
@ -1 +1 @@
|
|||
Subproject commit f033fc9c103b8a07398481cbff00b0ad3ea749e2
|
||||
Subproject commit ebaedd64ed28032e4c9bc34c0c1ec3488b2f0937
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Penumbra.Util;
|
||||
|
||||
public class IndexSet : IEnumerable<int>
|
||||
{
|
||||
private readonly BitArray _set;
|
||||
private int _count;
|
||||
|
||||
public int Capacity => _set.Count;
|
||||
|
||||
public int Count => _count;
|
||||
|
||||
public bool this[Index index]
|
||||
{
|
||||
get => _set[index];
|
||||
set
|
||||
{
|
||||
if( value )
|
||||
{
|
||||
Add( index );
|
||||
}
|
||||
else
|
||||
{
|
||||
Remove( index );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IndexSet( int capacity, bool initiallyFull )
|
||||
{
|
||||
_set = new BitArray( capacity, initiallyFull );
|
||||
_count = initiallyFull ? capacity : 0;
|
||||
}
|
||||
|
||||
public bool Add( Index index )
|
||||
{
|
||||
var ret = !_set[index];
|
||||
if( ret )
|
||||
{
|
||||
++_count;
|
||||
_set[index] = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public bool Remove( Index index )
|
||||
{
|
||||
var ret = _set[index];
|
||||
if( ret )
|
||||
{
|
||||
--_count;
|
||||
_set[index] = false;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int AddRange( int offset, int length )
|
||||
{
|
||||
var ret = 0;
|
||||
for( var idx = 0; idx < length; ++idx )
|
||||
{
|
||||
if( Add( offset + idx ) )
|
||||
{
|
||||
++ret;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int RemoveRange( int offset, int length )
|
||||
{
|
||||
var ret = 0;
|
||||
for( var idx = 0; idx < length; ++idx )
|
||||
{
|
||||
if( Remove( offset + idx ) )
|
||||
{
|
||||
++ret;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public IEnumerator<int> GetEnumerator()
|
||||
{
|
||||
if( _count > 0 )
|
||||
{
|
||||
var capacity = _set.Count;
|
||||
var remaining = _count;
|
||||
for( var i = 0; i < capacity; ++i )
|
||||
{
|
||||
if( _set[i] )
|
||||
{
|
||||
yield return i;
|
||||
if( --remaining == 0 )
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue