daily update on 20250210 by nitload youmu
This commit is contained in:
@@ -39,23 +39,23 @@ namespace StgSharp.Commom.Collections
|
||||
internal class CapacityFixedList<T> : IList<T>
|
||||
{
|
||||
|
||||
private T[] values;
|
||||
private T[] _values;
|
||||
private int capacity, _index;
|
||||
|
||||
public CapacityFixedList( int size )
|
||||
{
|
||||
values = new T[size];
|
||||
_values = new T[size];
|
||||
}
|
||||
|
||||
public T this[ int index ]
|
||||
{
|
||||
get => index < _index ?
|
||||
values[ index ] : throw new ArgumentOutOfRangeException(
|
||||
_values[ index ] : throw new ArgumentOutOfRangeException(
|
||||
nameof( index ) );
|
||||
set
|
||||
{
|
||||
if( index < _index ) {
|
||||
values[ index ] = value;
|
||||
_values[ index ] = value;
|
||||
} else {
|
||||
throw new ArgumentOutOfRangeException( nameof( index ) );
|
||||
}
|
||||
@@ -76,14 +76,14 @@ namespace StgSharp.Commom.Collections
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
values = new T[capacity];
|
||||
_values = new T[capacity];
|
||||
_index = 0;
|
||||
}
|
||||
|
||||
public bool Contains( T item )
|
||||
{
|
||||
for( int i = 0; i <= _index; i++ ) {
|
||||
if( item.Equals( values[ i ] ) ) {
|
||||
if( item.Equals( _values[ i ] ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -92,13 +92,13 @@ namespace StgSharp.Commom.Collections
|
||||
|
||||
public void CopyTo( T[] array, int arrayIndex )
|
||||
{
|
||||
values.CopyTo( array, arrayIndex );
|
||||
_values.CopyTo( array, arrayIndex );
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
for( int i = 0; i <= _index; i++ ) {
|
||||
yield return values[ i ];
|
||||
yield return _values[ i ];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace StgSharp.Commom.Collections
|
||||
{
|
||||
T v;
|
||||
for( int i = 0; i <= _index; i++ ) {
|
||||
if( ( v = values[ i ] ) != null && v.Equals( item ) ) {
|
||||
if( ( v = _values[ i ] ) != null && v.Equals( item ) ) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -117,8 +117,8 @@ namespace StgSharp.Commom.Collections
|
||||
{
|
||||
T v;
|
||||
for( int i = 0; i <= _index; i++ ) {
|
||||
if( ( v = values[ i ] ) != null && v.Equals( item ) ) {
|
||||
values[ i ] = values[ _index ];
|
||||
if( ( v = _values[ i ] ) != null && v.Equals( item ) ) {
|
||||
_values[ i ] = _values[ _index ];
|
||||
_index--;
|
||||
return true;
|
||||
}
|
||||
@@ -129,8 +129,8 @@ namespace StgSharp.Commom.Collections
|
||||
public void RemoveAll( Predicate<T> predicate )
|
||||
{
|
||||
for( int i = _index; i > 0; i-- ) {
|
||||
if( predicate( values[ i ] ) ) {
|
||||
values[ i ] = values[ _index ];
|
||||
if( predicate( _values[ i ] ) ) {
|
||||
_values[ i ] = _values[ _index ];
|
||||
_index--;
|
||||
}
|
||||
}
|
||||
@@ -139,14 +139,14 @@ namespace StgSharp.Commom.Collections
|
||||
public void RemoveAt( int index )
|
||||
{
|
||||
if( index <= _index ) {
|
||||
values[ index ] = values[ _index ];
|
||||
_values[ index ] = _values[ _index ];
|
||||
_index--;
|
||||
}
|
||||
}
|
||||
|
||||
public void Resize( int newSize )
|
||||
{
|
||||
Array.Resize( ref values, newSize );
|
||||
Array.Resize( ref _values, newSize );
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Part of a collection. This contains a direct reference to origin collection,
|
||||
/// so all change to origin collection will be reflected in this object.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class ReferencedSlicedCollection<T> : ICollection<T>
|
||||
{
|
||||
private ICollection<T> _collection;
|
||||
private int _begin;
|
||||
private int _length;
|
||||
|
||||
internal ReferencedSlicedCollection()
|
||||
{
|
||||
_collection = Array.Empty<T>();
|
||||
_begin = 0;
|
||||
_length = 0;
|
||||
}
|
||||
|
||||
public ReferencedSlicedCollection(ICollection<T> collection, int begin, int length)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(collection);
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(begin, 0);
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(length, 0);
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(begin + length, collection.Count);
|
||||
_collection = collection;
|
||||
_begin = begin;
|
||||
_length = length;
|
||||
}
|
||||
|
||||
public int Count => _length;
|
||||
|
||||
public bool IsReadOnly => true;
|
||||
|
||||
void ICollection<T>.Add(T item)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Contains(T item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void CopyTo(T[] array, int arrayIndex)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Remove(T item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user