new manage of wraps
This commit is contained in:
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="CapacityFixedList.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="CapacityFixedList"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -40,44 +37,41 @@ namespace StgSharp.Commom.Collections
|
||||
public static class CapacityFixedListBuilder
|
||||
{
|
||||
|
||||
internal static CapacityFixedList<T> Create<T>( ReadOnlySpan<T> values )
|
||||
internal static CapacityFixedList<T> Create<T>(ReadOnlySpan<T> values)
|
||||
{
|
||||
return new CapacityFixedList<T>( values );
|
||||
return new CapacityFixedList<T>(values);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[CollectionBuilder(
|
||||
typeof( CapacityFixedListBuilder ),
|
||||
nameof( CapacityFixedListBuilder.Create ) )]
|
||||
[CollectionBuilder(typeof(CapacityFixedListBuilder), nameof(CapacityFixedListBuilder.Create))]
|
||||
public class CapacityFixedList<T> : IList<T>
|
||||
{
|
||||
|
||||
private T[] _values;
|
||||
private int capacity, _index;
|
||||
|
||||
public CapacityFixedList( int size )
|
||||
public CapacityFixedList(int size)
|
||||
{
|
||||
_values = new T[size];
|
||||
}
|
||||
|
||||
public CapacityFixedList( ReadOnlySpan<T> values )
|
||||
public CapacityFixedList(ReadOnlySpan<T> values)
|
||||
{
|
||||
_values = values.ToArray();
|
||||
}
|
||||
|
||||
public T this[ int index ]
|
||||
public T this[int index]
|
||||
{
|
||||
get => index < _index ?
|
||||
_values[ index ] : throw new ArgumentOutOfRangeException( nameof( index ) );
|
||||
get => index < _index ? _values[index] : throw new ArgumentOutOfRangeException(nameof(index));
|
||||
set
|
||||
{
|
||||
if( index < _index )
|
||||
if (index < _index)
|
||||
{
|
||||
_values[ index ] = value;
|
||||
_values[index] = value;
|
||||
} else
|
||||
{
|
||||
throw new ArgumentOutOfRangeException( nameof( index ) );
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,12 +80,12 @@ namespace StgSharp.Commom.Collections
|
||||
|
||||
public int Count => _index + 1;
|
||||
|
||||
public void Add( T item )
|
||||
public void Add(T item)
|
||||
{
|
||||
if( _index < capacity - 1 )
|
||||
if (_index < capacity - 1)
|
||||
{
|
||||
_index++;
|
||||
this[ _index ] = item;
|
||||
this[_index] = item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,49 +95,49 @@ namespace StgSharp.Commom.Collections
|
||||
_index = 0;
|
||||
}
|
||||
|
||||
public bool Contains( T item )
|
||||
public bool Contains(T item)
|
||||
{
|
||||
for( int i = 0; i <= _index; i++ )
|
||||
for (int i = 0; i <= _index; i++)
|
||||
{
|
||||
if( item.Equals( _values[ i ] ) ) {
|
||||
if (item.Equals(_values[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void CopyTo( T[] array, int arrayIndex )
|
||||
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 ];
|
||||
for (int i = 0; i <= _index; i++) {
|
||||
yield return _values[i];
|
||||
}
|
||||
}
|
||||
|
||||
public int IndexOf( T item )
|
||||
public int IndexOf(T item)
|
||||
{
|
||||
T v;
|
||||
for( int i = 0; i <= _index; i++ )
|
||||
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;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool Remove( T item )
|
||||
public bool Remove(T item)
|
||||
{
|
||||
T v;
|
||||
for( int i = 0; i <= _index; i++ )
|
||||
for (int i = 0; i <= _index; i++)
|
||||
{
|
||||
if( ( v = _values[ i ] ) != null && v.Equals( item ) )
|
||||
if ((v = _values[i]) != null && v.Equals(item))
|
||||
{
|
||||
_values[ i ] = _values[ _index ];
|
||||
_values[i] = _values[_index];
|
||||
_index--;
|
||||
return true;
|
||||
}
|
||||
@@ -151,30 +145,30 @@ namespace StgSharp.Commom.Collections
|
||||
return false;
|
||||
}
|
||||
|
||||
public void RemoveAll( Predicate<T> predicate )
|
||||
public void RemoveAll(Predicate<T> predicate)
|
||||
{
|
||||
for( int i = _index; i > 0; i-- )
|
||||
for (int i = _index; i > 0; i--)
|
||||
{
|
||||
if( predicate( _values[ i ] ) )
|
||||
if (predicate(_values[i]))
|
||||
{
|
||||
_values[ i ] = _values[ _index ];
|
||||
_values[i] = _values[_index];
|
||||
_index--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAt( int index )
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if( index <= _index )
|
||||
if (index <= _index)
|
||||
{
|
||||
_values[ index ] = _values[ _index ];
|
||||
_values[index] = _values[_index];
|
||||
_index--;
|
||||
}
|
||||
}
|
||||
|
||||
public void Resize( int newSize )
|
||||
public void Resize(int newSize)
|
||||
{
|
||||
Array.Resize( ref _values, newSize );
|
||||
Array.Resize(ref _values, newSize);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
@@ -182,7 +176,7 @@ namespace StgSharp.Commom.Collections
|
||||
yield return GetEnumerator();
|
||||
}
|
||||
|
||||
void IList<T>.Insert( int index, T item )
|
||||
void IList<T>.Insert(int index, T item)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="CapacityFixedStack"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Commom.Collections
|
||||
{
|
||||
[CollectionBuilder(typeof(CapacityFixedStackBuilder), nameof(CapacityFixedStackBuilder.Create))]
|
||||
public class CapacityFixedStack<T> : IEnumerable<T>
|
||||
{
|
||||
|
||||
private readonly T[] _values;
|
||||
private int _index;
|
||||
|
||||
public CapacityFixedStack(int size)
|
||||
{
|
||||
_values = new T[size];
|
||||
_index = -1;
|
||||
}
|
||||
|
||||
public bool IsEmpty => _index == -1;
|
||||
|
||||
public int Count => _index + 1;
|
||||
|
||||
public int Capacity => _values.Length;
|
||||
|
||||
public ReadOnlySpan<T> AsSpan()
|
||||
{
|
||||
return _values.AsSpan(0, _index + 1);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
Array.Clear(_values, 0, _values.Length);
|
||||
_index = -1;
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
for (int i = _index; i >= 0; i--) {
|
||||
yield return _values[i];
|
||||
}
|
||||
}
|
||||
|
||||
public T Peek()
|
||||
{
|
||||
if (_index >= 0)
|
||||
{
|
||||
return _values[_index];
|
||||
} else
|
||||
{
|
||||
throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
}
|
||||
|
||||
public T Pop()
|
||||
{
|
||||
if (_index >= 0)
|
||||
{
|
||||
T item = _values[_index];
|
||||
return item;
|
||||
} else
|
||||
{
|
||||
throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
}
|
||||
|
||||
public void Push(T item)
|
||||
{
|
||||
if (_index < _values.Length - 1)
|
||||
{
|
||||
_values[++_index] = item;
|
||||
} else
|
||||
{
|
||||
throw new InvalidOperationException("Stack is full.");
|
||||
}
|
||||
}
|
||||
|
||||
public void PushRange(ReadOnlySpan<T> span)
|
||||
{
|
||||
if (_index + span.Length >= _values.Length) {
|
||||
throw new InvalidOperationException("Not enough space in the stack to push the entire span.");
|
||||
}
|
||||
|
||||
Span<T> sp = _values.AsSpan(_index + 1, span.Length);
|
||||
span.CopyTo(sp);
|
||||
_index += span.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal Span<T> GetValueLayout()
|
||||
{
|
||||
return _values.AsSpan();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class CapacityFixedStackBuilder
|
||||
{
|
||||
|
||||
public static CapacityFixedStack<T> Create<T>(ReadOnlySpan<T> values)
|
||||
{
|
||||
CapacityFixedStack<T> stack = new(values.Length);
|
||||
Span<T> sp = stack.GetValueLayout();
|
||||
values.CopyTo(sp);
|
||||
return stack;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="PartialDictionaryValues.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PartialDictionaryValues"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -43,7 +40,7 @@ namespace StgSharp.Collections
|
||||
|
||||
private readonly PartialDictionary<TKey, TValue> _values;
|
||||
|
||||
public PartialDictionaryValues( PartialDictionary<TKey, TValue> value )
|
||||
public PartialDictionaryValues(PartialDictionary<TKey, TValue> value)
|
||||
{
|
||||
_values = value;
|
||||
}
|
||||
@@ -52,34 +49,34 @@ namespace StgSharp.Collections
|
||||
|
||||
public int Count => _values.Count;
|
||||
|
||||
public bool Contains( TValue item )
|
||||
public bool Contains(TValue item)
|
||||
{
|
||||
foreach( KeyValuePair<TKey, TValue> kvp in _values )
|
||||
foreach (KeyValuePair<TKey, TValue> kvp in _values)
|
||||
{
|
||||
if( kvp.Value != null && kvp.Value.Equals( item ) ) {
|
||||
if (kvp.Value != null && kvp.Value.Equals(item)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void CopyTo( TValue[] array, int arrayIndex )
|
||||
public void CopyTo(TValue[] array, int arrayIndex)
|
||||
{
|
||||
foreach( KeyValuePair<TKey, TValue> kvp in _values )
|
||||
foreach (KeyValuePair<TKey, TValue> kvp in _values)
|
||||
{
|
||||
array[ arrayIndex ] = kvp.Value;
|
||||
array[arrayIndex] = kvp.Value;
|
||||
arrayIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<TValue> GetEnumerator()
|
||||
{
|
||||
foreach( TKey key in _values._keys ) {
|
||||
yield return _values._source[ key ];
|
||||
foreach (TKey key in _values._keys) {
|
||||
yield return _values._source[key];
|
||||
}
|
||||
}
|
||||
|
||||
void ICollection<TValue>.Add( TValue item )
|
||||
void ICollection<TValue>.Add(TValue item)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -89,7 +86,7 @@ namespace StgSharp.Collections
|
||||
return;
|
||||
}
|
||||
|
||||
bool ICollection<TValue>.Remove( TValue item )
|
||||
bool ICollection<TValue>.Remove(TValue item)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
@@ -1,30 +1,27 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Vec4.cs"
|
||||
// file="Vec4"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
@@ -114,11 +111,13 @@ namespace StgSharp.Mathematics.Graphic
|
||||
|
||||
public static Vec4 One
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => new Vec4(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
public static Vec4 Zero
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => new Vec4(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@@ -130,7 +129,7 @@ namespace StgSharp.Mathematics.Graphic
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is Vec4 v ? v == this : false;
|
||||
return obj is Vec4 v && v == this;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="AssemblyInfo"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("StgSharpDebug")]
|
||||
@@ -1,33 +1,31 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixParallel.Publish.cs"
|
||||
// file="MatrixParallel.Publish"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Commom.Collections;
|
||||
using StgSharp.HighPerformance;
|
||||
|
||||
using System;
|
||||
@@ -822,11 +820,24 @@ namespace StgSharp.Mathematics.Numeric
|
||||
int tileWidth = (1024 / secCount) + 1;
|
||||
int tileCount = (primCount / tileWidth) + 1;
|
||||
|
||||
int tilePerThreadLess = tileCount / Wraps.Length;
|
||||
int tileToSlice = tileCount % Wraps.Length;
|
||||
CapacityFixedStack<MatrixParallelWrap> wraps = LeadParallel();
|
||||
|
||||
// TODO 这个方法依然是独占,需要一个新的缓存类型用来辅助复用空线程束
|
||||
for (int i = 0; i < Wraps.Length; i++) { }
|
||||
int tilePerThreadLess = tileCount / Wraps.Count;
|
||||
int tileToSlice = tileCount % Wraps.Count;
|
||||
int slicingPerWrap = tileToSlice / Wraps.Count;
|
||||
int extraTiles = tileToSlice % Wraps.Count;
|
||||
|
||||
int total = tileCount;
|
||||
List<MatrixParallelWrap> w = new List<MatrixParallelWrap>(Wraps.Count);
|
||||
|
||||
for (int i = 0; i < Wraps.Count; i++)
|
||||
{
|
||||
MatrixParallelWrap wrap = Wraps.Pop();
|
||||
wrap.WrapTask = (MatrixParallelTaskPackageNonGeneric*)package;
|
||||
wrap.WrapTaskCapacity = ;
|
||||
wrap.WrapTaskSliceCount = ;
|
||||
w.Add(wrap);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +1,31 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixParallel.cs"
|
||||
// file="MatrixParallel"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Commom.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -130,13 +128,13 @@ namespace StgSharp.Mathematics.Numeric
|
||||
{
|
||||
Wraps = [ new MatrixParallelWrap(0, count, true) ];
|
||||
(LargeWrapCount, SmallWrapCount) = (0, 1);
|
||||
LeaderHandle = new MatrixParallelWrap.Handle(0, Wraps[0]);
|
||||
LeaderHandle = new MatrixParallelWrap.Handle(0, Wraps.Peek());
|
||||
} else
|
||||
{
|
||||
count = 4;
|
||||
Wraps = [ new MatrixParallelWrap(0, count, true) ];
|
||||
(LargeWrapCount, SmallWrapCount) = (1, 0);
|
||||
LeaderHandle = new MatrixParallelWrap.Handle(0, Wraps[0]);
|
||||
LeaderHandle = new MatrixParallelWrap.Handle(0, Wraps.Peek());
|
||||
}
|
||||
} else if (count == 6)
|
||||
{
|
||||
@@ -145,19 +143,19 @@ namespace StgSharp.Mathematics.Numeric
|
||||
new MatrixParallelWrap(3, 3, false)
|
||||
];
|
||||
(LargeWrapCount, SmallWrapCount) = (0, 2);
|
||||
LeaderHandle = new MatrixParallelWrap.Handle(0, Wraps[0]);
|
||||
LeaderHandle = new MatrixParallelWrap.Handle(0, Wraps.Peek());
|
||||
} else
|
||||
{
|
||||
(int _3wrap, int _4wrap) = FastDecompose(count);
|
||||
Wraps = new MatrixParallelWrap[_4wrap + _3wrap];
|
||||
int id = 0,idx = 0;
|
||||
Wraps = new(_4wrap + _3wrap);
|
||||
int id = 0, idx = 0;
|
||||
for (; idx < _3wrap; idx++, id += 3) {
|
||||
Wraps[idx] = new MatrixParallelWrap(idx, 3, id == 0);
|
||||
Wraps.Push(new MatrixParallelWrap(idx, 3, id == 0));
|
||||
}
|
||||
for (; idx < _3wrap + _4wrap; idx++, id += 4) {
|
||||
Wraps[idx] = new MatrixParallelWrap(id, 4, id == 0);
|
||||
Wraps.Push(new MatrixParallelWrap(id, 4, id == 0));
|
||||
}
|
||||
LeaderHandle = new MatrixParallelWrap.Handle(0, Wraps[0]);
|
||||
LeaderHandle = new MatrixParallelWrap.Handle(0, Wraps.Peek());
|
||||
}
|
||||
LeaderTask = LeaderHandle.Wrap.GetWorkerTaskQueue(0);
|
||||
IsInitialized = true;
|
||||
@@ -170,12 +168,6 @@ namespace StgSharp.Mathematics.Numeric
|
||||
SetAllWrap(wraps);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void LeadParallel()
|
||||
{
|
||||
Monitor.Enter(_lock);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void MatrixParallelLeaderWork()
|
||||
{
|
||||
@@ -271,6 +263,17 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
public record class Handle(int InWrapIndex, MatrixParallelWrap Wrap);
|
||||
|
||||
#region wrap task
|
||||
|
||||
internal MatrixParallelTaskPackageNonGeneric* WrapTask { get; set; }
|
||||
|
||||
internal int WrapTaskSliceCount { get; set; }
|
||||
|
||||
internal int WrapTaskCapacity { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region ThreadOperation
|
||||
|
||||
private static unsafe void MatrixParallelWorker([AllowNull] object obj)
|
||||
@@ -342,21 +345,39 @@ namespace StgSharp.Mathematics.Numeric
|
||||
#endregion
|
||||
}
|
||||
|
||||
public enum SleepMode
|
||||
{
|
||||
|
||||
QuickWakeup = ThreadPriority.AboveNormal,
|
||||
NormalSleep = ThreadPriority.BelowNormal,
|
||||
DeepSleep = ThreadPriority.Lowest,
|
||||
|
||||
}
|
||||
|
||||
#region wrap field
|
||||
|
||||
private static MatrixParallelWrap[] Wraps;
|
||||
private static CapacityFixedStack<MatrixParallelWrap> Wraps;
|
||||
private static int LargeWrapCount;
|
||||
private static int SmallWrapCount;
|
||||
|
||||
#endregion
|
||||
}
|
||||
public static CapacityFixedStack<MatrixParallelWrap> LeadParallel()
|
||||
{
|
||||
#if NET9_0_OR_GREATER
|
||||
#else
|
||||
Monitor.Enter(_lock);
|
||||
#endif
|
||||
return Wraps;
|
||||
}
|
||||
|
||||
public enum SleepMode
|
||||
{
|
||||
|
||||
QuickWakeup = ThreadPriority.AboveNormal,
|
||||
NormalSleep = ThreadPriority.BelowNormal,
|
||||
DeepSleep = ThreadPriority.Lowest,
|
||||
public static void ReleaseParallelLeadership(ref CapacityFixedStack<MatrixParallelWrap> wraps)
|
||||
{
|
||||
#if NET9_0_OR_GREATER
|
||||
#else
|
||||
Monitor.Exit(_lock);
|
||||
#endif
|
||||
wraps = null!;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user