From 1e471551d43ed70c0273f0d445a8c87384c51c27 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Thu, 23 Feb 2023 14:44:37 +0100 Subject: [PATCH] Move IndexSet to OtterGui --- OtterGui | 2 +- Penumbra/Util/IndexSet.cs | 110 -------------------------------------- 2 files changed, 1 insertion(+), 111 deletions(-) delete mode 100644 Penumbra/Util/IndexSet.cs diff --git a/OtterGui b/OtterGui index f033fc9c..ebaedd64 160000 --- a/OtterGui +++ b/OtterGui @@ -1 +1 @@ -Subproject commit f033fc9c103b8a07398481cbff00b0ad3ea749e2 +Subproject commit ebaedd64ed28032e4c9bc34c0c1ec3488b2f0937 diff --git a/Penumbra/Util/IndexSet.cs b/Penumbra/Util/IndexSet.cs deleted file mode 100644 index e0ed7921..00000000 --- a/Penumbra/Util/IndexSet.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace Penumbra.Util; - -public class IndexSet : IEnumerable -{ - 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 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(); - } -}