daily update on 20240206 by nitload youmu, token parser change to use regex generator

This commit is contained in:
Nitload
2025-02-06 07:45:06 +08:00
parent 4e5a1b0dfb
commit 7d0470d50b
104 changed files with 2752 additions and 3134 deletions
@@ -49,55 +49,47 @@ namespace StgSharp.Commom.Collections
_reverse = new Dictionary<TSecond, TFirst>();
}
public TFirst this[TSecond key]
public TFirst this[ TSecond key ]
{
get
{
if (_reverse.TryGetValue(key, out TFirst value))
{
if( _reverse.TryGetValue( key, out TFirst value ) ) {
return value;
}
throw new ArgumentException(
$"Cannot find key {key!.ToString()} in dictionary.");
$"Cannot find key {key!.ToString()} in dictionary." );
}
set
{
if (_reverse.TryGetValue(key, out TFirst origin))
{
_reverse[key] = value;
_forward.Remove(origin);
if( _reverse.TryGetValue( key, out TFirst origin ) ) {
_reverse[ key ] = value;
_forward.Remove( origin );
} else {
_reverse.Add( key, value );
}
else
{
_reverse.Add(key, value);
}
_forward.Add(value, key);
_forward.Add( value, key );
}
}
public TSecond this[TFirst key]
public TSecond this[ TFirst key ]
{
get
{
if (_forward.TryGetValue(key, out TSecond value))
{
if( _forward.TryGetValue( key, out TSecond value ) ) {
return value;
}
throw new ArgumentException(
$"Cannot find key {key!.ToString()} in dictionary.");
$"Cannot find key {key!.ToString()} in dictionary." );
}
set
{
if (_forward.TryGetValue(key, out TSecond origin))
{
_forward[key] = value;
_reverse.Remove(origin);
if( _forward.TryGetValue( key, out TSecond origin ) ) {
_forward[ key ] = value;
_reverse.Remove( origin );
} else {
_forward.Add( key, value );
}
else
{
_forward.Add(key, value);
}
_reverse.Add(value, key);
_reverse.Add( value, key );
}
}
@@ -110,30 +102,28 @@ namespace StgSharp.Commom.Collections
public int Count => _forward.Count;
public IReadOnlyDictionary<TFirst, TSecond> Forward => new ReadOnlyDictionary<TFirst, TSecond>(
_forward);
_forward );
public IReadOnlyDictionary<TSecond, TFirst> Reverse => new ReadOnlyDictionary<TSecond, TFirst>(
_reverse);
_reverse );
public void Add(KeyValuePair<TFirst, TSecond> item)
public void Add( KeyValuePair<TFirst, TSecond> item )
{
if (_forward.ContainsKey(item.Key) || _reverse.ContainsKey(
item.Value))
{
throw new ArgumentException("Duplicate key or value.");
if( _forward.ContainsKey( item.Key ) || _reverse.ContainsKey(
item.Value ) ) {
throw new ArgumentException( "Duplicate key or value." );
}
_forward.Add(item.Key, item.Value);
_reverse.Add(item.Value, item.Key);
_forward.Add( item.Key, item.Value );
_reverse.Add( item.Value, item.Key );
}
public void Add(TFirst key, TSecond value)
public void Add( TFirst key, TSecond value )
{
if (_forward.ContainsKey(key) || _reverse.ContainsKey(value))
{
throw new ArgumentException("Duplicate key or value.");
if( _forward.ContainsKey( key ) || _reverse.ContainsKey( value ) ) {
throw new ArgumentException( "Duplicate key or value." );
}
_forward.Add(key, value);
_reverse.Add(value, key);
_forward.Add( key, value );
_reverse.Add( value, key );
}
public void Clear()
@@ -142,76 +132,70 @@ namespace StgSharp.Commom.Collections
_reverse.Clear();
}
public bool Contains(KeyValuePair<TFirst, TSecond> item)
public bool Contains( KeyValuePair<TFirst, TSecond> item )
{
return _forward.Contains(item) && _reverse.TryGetValue(
item.Value, out TFirst var) && var!.Equals(item.Key);
return _forward.Contains( item ) && _reverse.TryGetValue(
item.Value, out TFirst var ) && var!.Equals( item.Key );
}
public bool Contains(TSecond key)
public bool Contains( TSecond key )
{
return _reverse.ContainsKey(key);
return _reverse.ContainsKey( key );
}
public bool Contains(TFirst key)
public bool Contains( TFirst key )
{
return _forward.ContainsKey(key);
return _forward.ContainsKey( key );
}
public void CopyTo(
KeyValuePair<TFirst, TSecond>[] array,
int arrayIndex)
KeyValuePair<TFirst, TSecond>[] array,
int arrayIndex )
{
if (array == null)
{
throw new ArgumentNullException(nameof(array));
if( array == null ) {
throw new ArgumentNullException( nameof( array ) );
}
if (arrayIndex < 0 || arrayIndex > array.Length)
{
throw new ArgumentOutOfRangeException(nameof(arrayIndex));
if( arrayIndex < 0 || arrayIndex > array.Length ) {
throw new ArgumentOutOfRangeException( nameof( arrayIndex ) );
}
if (array.Length - arrayIndex < _forward.Count)
{
if( array.Length - arrayIndex < _forward.Count ) {
throw new ArgumentException(
"The array is too small to copy the elements.");
"The array is too small to copy the elements." );
}
foreach (KeyValuePair<TFirst, TSecond> pair in _forward)
{
array[arrayIndex++] = pair;
foreach( KeyValuePair<TFirst, TSecond> pair in _forward ) {
array[ arrayIndex++ ] = pair;
}
}
public IEnumerator<KeyValuePair<TFirst, TSecond>> GetEnumerator()
{
foreach (KeyValuePair<TFirst, TSecond> pair in _forward)
{
foreach( KeyValuePair<TFirst, TSecond> pair in _forward ) {
yield return pair;
}
}
public bool Remove(TFirst key)
public bool Remove( TFirst key )
{
throw new NotImplementedException();
}
public bool Remove(KeyValuePair<TFirst, TSecond> item)
public bool Remove( KeyValuePair<TFirst, TSecond> item )
{
if (_forward.Remove(item.Key))
{
return _reverse.Remove(item.Value);
if( _forward.Remove( item.Key ) ) {
return _reverse.Remove( item.Value );
}
return false;
}
public bool TryGetValue(TFirst key, out TSecond value)
public bool TryGetValue( TFirst key, out TSecond value )
{
return _forward.TryGetValue(key, out value);
return _forward.TryGetValue( key, out value );
}
public bool TryGetValue(TSecond key, out TFirst value)
public bool TryGetValue( TSecond key, out TFirst value )
{
return _reverse.TryGetValue(key, out value);
return _reverse.TryGetValue( key, out value );
}
IEnumerator IEnumerable.GetEnumerator()
@@ -1,4 +1,34 @@
using StgSharp.Graphics.OpenGL;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="CachePool.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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 StgSharp.Graphics.OpenGL;
using System;
using System.Collections;
@@ -10,34 +40,47 @@ namespace StgSharp.Commom.Collections
{
public interface IPoolable
{
public int ID { get; }
public int ID
{
get;
}
}
public class CacheIndexPool<T> : IEnumerable<T> where T : IPoolable
public class CacheIndexPool<T> : IEnumerable<T> where T: IPoolable
{
private ConcurrentDictionary<int, T> _cache;
private Func<T> _defaultCreater;
public CacheIndexPool(Func<T> defaultCreater)
public CacheIndexPool( Func<T> defaultCreater )
{
_cache = new ConcurrentDictionary<int, T>();
_defaultCreater = defaultCreater;
}
public T this[int index]
public T this[ int index ]
{
get
{
if (_cache.TryGetValue(index, out T value))
{
if( _cache.TryGetValue( index, out T value ) ) {
return value;
}
T newValue = _defaultCreater();
_cache.TryAdd(index, newValue);
_cache.TryAdd( index, newValue );
return newValue;
}
}
public T CreateObject()
{
T _new = _defaultCreater();
_cache.AddOrUpdate( 1, _new, static( _, origin ) => origin );
throw new NotImplementedException();
return _new;
}
public IEnumerator<T> GetEnumerator()
{
return _cache.Values.GetEnumerator();
@@ -48,12 +91,5 @@ namespace StgSharp.Commom.Collections
return GetEnumerator();
}
public T CreateObject()
{
T _new = _defaultCreater();
_cache.AddOrUpdate(1, _new,static (_,origin)=>origin);
throw new NotImplementedException();
return _new;
}
}
}
@@ -38,28 +38,26 @@ namespace StgSharp.Commom.Collections
{
internal 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 T this[int index]
public T this[ int index ]
{
get => index < _index ?
values[index] : throw new ArgumentOutOfRangeException(
nameof(index));
values[ index ] : throw new ArgumentOutOfRangeException(
nameof( index ) );
set
{
if (index < _index)
{
values[index] = value;
}
else
{
throw new ArgumentOutOfRangeException(nameof(index));
if( index < _index ) {
values[ index ] = value;
} else {
throw new ArgumentOutOfRangeException( nameof( index ) );
}
}
}
@@ -68,12 +66,11 @@ 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;
}
}
@@ -83,52 +80,45 @@ namespace StgSharp.Commom.Collections
_index = 0;
}
public bool Contains(T item)
public bool Contains( T item )
{
for (int i = 0; i <= _index; i++)
{
if (item.Equals(values[i]))
{
for( int i = 0; i <= _index; 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++)
{
if ((v = values[i]) != null && v.Equals(item))
{
for( int i = 0; i <= _index; i++ ) {
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++)
{
if ((v = values[i]) != null && v.Equals(item))
{
values[i] = values[_index];
for( int i = 0; i <= _index; i++ ) {
if( ( v = values[ i ] ) != null && v.Equals( item ) ) {
values[ i ] = values[ _index ];
_index--;
return true;
}
@@ -136,30 +126,27 @@ 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--)
{
if (predicate(values[i]))
{
values[i] = values[_index];
for( int i = _index; i > 0; i-- ) {
if( predicate( values[ i ] ) ) {
values[ i ] = values[ _index ];
_index--;
}
}
}
public void RemoveAt(int index)
public void RemoveAt( int index )
{
if (index <= _index)
{
values[index] = values[_index];
if( index <= _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()
@@ -167,7 +154,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();
}
@@ -38,7 +38,7 @@ namespace StgSharp.Commom.Collections
public interface IBidirectionalDictionary<TFirst, TSecond> : IDictionary<TFirst, TSecond>
{
public TFirst this[TSecond key]
public TFirst this[ TSecond key ]
{
get;
set;
@@ -73,7 +73,7 @@ namespace StgSharp.Commom.Collections
/// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains an element
/// with the specified key; otherwise, false.
/// </returns>
public bool Contains(TSecond key);
public bool Contains( TSecond key );
/// <summary>
/// Determines whether the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains
@@ -84,17 +84,17 @@ namespace StgSharp.Commom.Collections
/// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains an element
/// with the specified key; otherwise, false.
/// </returns>
public bool Contains(TFirst key);
public bool Contains( TFirst key );
public bool TryGetValue(TSecond key, out TFirst value);
public bool TryGetValue( TSecond key, out TFirst value );
#pragma warning disable CA1033
#pragma warning disable CA1033
ICollection<TFirst> IDictionary<TFirst, TSecond>.Keys => FirstIndex;
ICollection<TSecond> IDictionary<TFirst, TSecond>.Values => SecondIndex;
bool IDictionary<TFirst, TSecond>.ContainsKey(TFirst key) => Contains(
key);
bool IDictionary<TFirst, TSecond>.ContainsKey( TFirst key ) => Contains(
key );
#pragma warning restore CA1033
}
}
@@ -1,12 +1,51 @@
using System.Diagnostics.CodeAnalysis;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IStringHashMultiplexer.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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.Diagnostics.CodeAnalysis;
namespace StgSharp.Collections
{
public interface IStringHashMultiplexer
{
int RemainedMultiplexCount { get; set; }
void CacheHash(string obj, int count);
void ExtendCache(int count);
int ForceComputeHash([NotNull] string obj);
int RemainedMultiplexCount
{
get;
set;
}
void CacheHash( string obj, int count );
void ExtendCache( int count );
int ForceComputeHash( [NotNull] string obj );
}
}
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="KeyMultiplexer.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
@@ -8,10 +38,11 @@ using System.Threading;
namespace StgSharp.Collections
{
public class StringHashMultiplexer : IEqualityComparer<string>, IStringHashMultiplexer
public sealed class StringHashMultiplexer : IEqualityComparer<string>, IStringHashMultiplexer
{
private string _source, _sourceLast;
private int _initCount, _remainedCount, _hashCache, _hashLast;
private string _source, _sourceLast;
public int RemainedMultiplexCount
{
@@ -19,92 +50,116 @@ namespace StgSharp.Collections
set => _initCount = value;
}
public bool Equals(string x, string y)
public void CacheHash( string obj, int count )
{
return x == y;
}
public int GetHashCode(string obj)
{
if (_remainedCount > 0 && ReferenceEquals(_source, obj))
{
_remainedCount--;
return _hashCache;
}
if (ReferenceEquals(_sourceLast, obj))
{
return _hashLast;
}
_sourceLast = obj;
_hashLast = ForceComputeHash(obj);
return _hashLast;
}
public void CacheHash(string obj, int count)
{
_hashCache = ForceComputeHash(obj);
_hashCache = ForceComputeHash( obj );
_initCount = count;
_remainedCount = _initCount;
_source = obj;
}
public void ExtendCache(int count)
public bool Equals( string x, string y )
{
return x == y;
}
public void ExtendCache( int count )
{
_initCount += count;
_remainedCount += count;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe int ForceComputeHash([NotNull] string obj)
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe int ForceComputeHash( [NotNull] string obj )
{
int hash;
fixed (char* cPtr = obj.AsSpan())
{
hash = InternalIO.Intrinsic.cityhash_simplify(cPtr, obj.Length);
fixed( char* cPtr = obj.AsSpan() ) {
hash = InternalIO.Intrinsic
.city_hash_simplify( cPtr, obj.Length );
}
return hash;
}
}
public class ConcurrentStringHashMultiplexer : IEqualityComparer<string>, IStringHashMultiplexer
{
private readonly ThreadLocal<StringHashMultiplexer> multiplexers =
new (()=>new StringHashMultiplexer());
public int RemainedMultiplexCount
{
get => multiplexers.Value.RemainedMultiplexCount;
set => multiplexers.Value.RemainedMultiplexCount = value;
public int GetHashCode( string obj )
{
if( _remainedCount > 0 && ReferenceEquals( _source, obj ) ) {
_remainedCount--;
return _hashCache;
}
if( ReferenceEquals( _sourceLast, obj ) ) {
return _hashLast;
}
_sourceLast = obj;
_hashLast = ForceComputeHash( obj );
return _hashLast;
}
public void CacheHash(string obj, int count)
}
public sealed class ConcurrentStringHashMultiplexer : IEqualityComparer<string>, IStringHashMultiplexer, IDisposable
{
private bool disposedValue;
private readonly ThreadLocal<StringHashMultiplexer> _multiplexers =
new( () => new StringHashMultiplexer() );
public int RemainedMultiplexCount
{
get => _multiplexers.Value.RemainedMultiplexCount;
set => _multiplexers.Value.RemainedMultiplexCount = value;
}
public void CacheHash( string obj, int count )
{
throw new NotImplementedException();
}
public bool Equals(string x, string y)
// ~ConcurrentStringHashMultiplexer()
// {
// Dispose(disposing: false);
// }
public void Dispose()
{
Dispose( disposing: true );
GC.SuppressFinalize( this );
}
public bool Equals( string x, string y )
{
return x == y;
}
public void ExtendCache(int count)
public void ExtendCache( int count )
{
multiplexers.Value.ExtendCache(count);
_multiplexers.Value.ExtendCache( count );
}
public unsafe int ForceComputeHash([NotNull] string obj)
public unsafe int ForceComputeHash( [NotNull] string obj )
{
int hash;
fixed (char* cPtr = obj.AsSpan())
{
hash = InternalIO.Intrinsic.cityhash_simplify(cPtr, obj.Length);
fixed( char* cPtr = obj.AsSpan() ) {
hash = InternalIO.Intrinsic
.city_hash_simplify( cPtr, obj.Length );
}
return hash;
}
public int GetHashCode(string obj)
public int GetHashCode( string obj )
{
return multiplexers.Value.GetHashCode(obj);
return _multiplexers.Value.GetHashCode( obj );
}
private void Dispose( bool disposing )
{
if( !disposedValue ) {
if( disposing ) {
_multiplexers.Dispose();
}
disposedValue = true;
}
}
}
}
@@ -113,7 +113,8 @@ namespace StgSharp.Collections
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
foreach( TKey item in _keys ) {
yield return new KeyValuePair<TKey, TValue>(item, _source[item]);
yield return new KeyValuePair<TKey, TValue>(
item, _source[ item ] );
}
}
@@ -138,14 +139,14 @@ namespace StgSharp.Collections
throw new NotSupportedException();
}
bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly => true;
bool ICollection<KeyValuePair<TKey, TValue>>.Remove(
KeyValuePair<TKey, TValue> item )
{
throw new NotSupportedException();
}
bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly => true;
void IDictionary<TKey, TValue>.Add( TKey key, TValue value )
{
return;
@@ -53,22 +53,10 @@ namespace StgSharp.Collections
public int Count => _values.Count;
void ICollection<TValue>.Add( TValue item )
{
return;
}
void ICollection<TValue>.Clear()
{
return;
}
public bool Contains( TValue item )
{
foreach (var kvp in _values)
{
if (kvp.Value != null && kvp.Value.Equals(item))
{
foreach( KeyValuePair<TKey, TValue> kvp in _values ) {
if( kvp.Value != null && kvp.Value.Equals( item ) ) {
return true;
}
}
@@ -77,21 +65,29 @@ namespace StgSharp.Collections
public void CopyTo( TValue[] array, int arrayIndex )
{
foreach (var kvp in _values)
{
array[arrayIndex] = kvp.Value;
foreach( KeyValuePair<TKey, TValue> kvp in _values ) {
array[ arrayIndex ] = kvp.Value;
arrayIndex++;
}
}
public IEnumerator<TValue> GetEnumerator()
{
foreach (var 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 )
{
return;
}
void ICollection<TValue>.Clear()
{
return;
}
bool ICollection<TValue>.Remove( TValue item )
{
throw new NotSupportedException();
@@ -54,7 +54,7 @@ namespace StgSharp.Internal
ReadOnlySpan<char> nameSpan = _name.AsSpan();
fixed( char* cptr = nameSpan ) {
return InternalIO.Intrinsic
.cityhash_simplify( cptr, _name.Length );
.city_hash_simplify( cptr, _name.Length );
}
}
@@ -28,8 +28,8 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Common.Internal.Intrinsic;
using StgSharp.Internal.Intrinsic;
using StgSharp.Intrinsic;
using System;
using System.IO;
@@ -40,7 +40,7 @@ using System.Transactions;
using System.Xml;
using System.Xml.Serialization;
namespace StgSharp.Internal
namespace StgSharp.Data
{
public class RandomGenerator
{
@@ -28,7 +28,7 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Common.Internal.Intrinsic;
using StgSharp.Intrinsic;
using StgSharp.Internal.Intrinsic;
using System;
@@ -71,7 +71,7 @@ namespace StgSharp.Internal
public unsafe byte[] GetBytes()
{
byte[] ret = new byte[16];
fixed( Vector4* vptr = &data.vec ) {
fixed( Vector4* vptr = &data.Vec ) {
byte* bptr = ( byte* )vptr;
for( int i = 0; i < 15; i++ ) {
ret[ i ] = *bptr;
@@ -28,7 +28,7 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Common.Internal.Intrinsic;
using StgSharp.Intrinsic;
using StgSharp.Internal.Intrinsic;
using StgSharp.Math;
@@ -90,7 +90,7 @@ namespace StgSharp.Internal
return;
}
for( int i = begin; i < 255; i++ ) {
Data[ i ] = Scaler.Random<byte>(); //TODO: 使用STGSHARP内部随机数工具处理它
Data[ i ] = Scaler.Random<byte>();
}
}
@@ -136,7 +136,7 @@ namespace StgSharp.Internal
}
}
M128 m = new M128( v );
DataHash = m.vec.GetHashCode();
DataHash = m.Vec.GetHashCode();
return DataHash;
}
@@ -39,7 +39,7 @@ using System.Threading.Tasks;
namespace StgSharp.Graphics
{
/// <summary>
/// Interface of all kinds OpenGL buffer objects
/// Interface of all kinds OpenGL Buffer objects
/// </summary>
public abstract class BufferObjectBase : IDisposable
{
@@ -55,7 +55,7 @@ namespace StgSharp.Graphics
public GlHandle this[ int index ] => _bufferHandle[ index ];
/// <summary>
/// Bind a buffer instance to OpenGL
/// Bind a Buffer instance to OpenGL
/// </summary>
/// <param _name="index"> Index of handle of the object in this instance to be bind </param>
public abstract void Bind( int index );
@@ -43,7 +43,7 @@ namespace StgSharp.Graphics.OpenGL
{
/// <summary>
/// A collection of a sets of OpenGL textures. The collection can automatically select one of
/// the texture with minimum costs to upgrade pixels to buffer. Usually <see
/// the texture with minimum costs to upgrade pixels to Buffer. Usually <see
/// cref="AutoTextureGL" /> is used for <see cref="IImageProvider" /> loading, but not for
/// target of <see cref="OpenGLFunction.FrameBufferTexture2d(FrameBufferTarget, uint,
/// Texture2DTarget, GlHandle, int)" />.
@@ -35,6 +35,7 @@ using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
@@ -62,11 +63,11 @@ namespace StgSharp.Graphics.OpenGL
}
public void SetValue<T>( int index, T[] bufferArray, BufferUsage usage )
where T: struct, IConvertible
where T: struct, INumber<T>
{
GL.BindBuffer(
BufferType.ElementArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferData(
GL.SetBufferData<T>(
BufferType.ElementArrayBuffer, bufferArray, usage );
}
@@ -74,11 +75,11 @@ namespace StgSharp.Graphics.OpenGL
int index,
ReadOnlySpan<T> bufferSpan,
BufferUsage usage )
where T: struct, IConvertible
where T: struct, INumber<T>
{
GL.BindBuffer(
BufferType.ElementArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferData( BufferType.ElementArrayBuffer, bufferSpan,
GL.SetBufferData<T>( BufferType.ElementArrayBuffer, bufferSpan,
usage );
}
@@ -63,7 +63,7 @@ namespace StgSharp.Graphics.OpenGL
}
/// <summary>
/// Bind the frame buffer object with _name frame buffer to the frame buffer target specified
/// Bind the frame Buffer object with _name frame Buffer to the frame Buffer target specified
/// by target. <see langword="FrameBufferTarget.All" /> will be set as default target.
/// </summary>
/// <param _name="index"> Index of object to be binded in handle set </param>
@@ -74,10 +74,10 @@ namespace StgSharp.Graphics.OpenGL
}
/// <summary>
/// Bind the frame buffer object with _name frame buffer to the frame buffer target specified
/// by target. Target of this frame buffer should be set manually.
/// Bind the frame Buffer object with _name frame Buffer to the frame Buffer target specified
/// by target. Target of this frame Buffer should be set manually.
/// </summary>
/// <param _name="target"> The frame buffer target of the binding operation. </param>
/// <param _name="target"> The frame Buffer target of the binding operation. </param>
/// <param _name="index"> Index of object to be binded in handle set </param>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public unsafe void Bind( FrameBufferTarget target, int index )
@@ -28,7 +28,7 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Common.Internal.Intrinsic;
using StgSharp.Intrinsic;
using StgSharp.Internal.Intrinsic;
using StgSharp.Internal.OpenGL;
using StgSharp.Math;
@@ -33,6 +33,7 @@ using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Net.Security;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -64,7 +65,7 @@ namespace StgSharp.Graphics.OpenGL
}
/// <summary>
/// Set _data to current vertex buffer object
/// Set _data to current vertex Buffer object
/// </summary>
/// <typeparam _name="T"> Type of bufferData </typeparam>
/// <param _name="index"> Index to find certain VBO in this instance </param>
@@ -81,7 +82,7 @@ namespace StgSharp.Graphics.OpenGL
}
/// <summary>
/// Set _data to current vertex buffer object
/// Set _data to current vertex Buffer object
/// </summary>
/// <typeparam _name="T"> Type of bufferData </typeparam>
/// <param _name="index"> Index to find certain VBO in this instance </param>
@@ -91,19 +92,14 @@ namespace StgSharp.Graphics.OpenGL
int index,
T[] bufferArray,
BufferUsage usage )
where T: struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
where T: struct, INumber<T>
{
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferData( BufferType.ArrayBuffer, bufferArray, usage );
}
/// <summary>
/// Set _data to current vertex buffer object
/// Set _data to current vertex Buffer object
/// </summary>
/// <typeparam _name="T"> Type of bufferData </typeparam>
/// <param _name="index"> Index to find certain VBO in this instance </param>
@@ -113,19 +109,14 @@ namespace StgSharp.Graphics.OpenGL
int index,
ReadOnlySpan<T> scalerSpan,
BufferUsage usage )
where T: struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
where T: struct,INumber<T>
{
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
GL.SetBufferData( BufferType.ArrayBuffer, scalerSpan, usage );
}
/// <summary>
/// Set _data to current vertex buffer object
/// Set _data to current vertex Buffer object
/// </summary>
/// <typeparam _name="T"> Type of bufferData </typeparam>
/// <param _name="index"> Index to find certain VBO in this instance </param>
@@ -142,7 +133,7 @@ namespace StgSharp.Graphics.OpenGL
}
/// <summary>
/// Set _data to current vertex buffer object
/// Set _data to current vertex Buffer object
/// </summary>
/// <typeparam _name="T"> Type of bufferData </typeparam>
/// <param _name="index"> Index to find certain VBO in this instance </param>
@@ -28,7 +28,7 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Common.Internal.Intrinsic;
using StgSharp.Intrinsic;
using StgSharp.Math;
using StgSharp.MVVM;
using StgSharp.MVVM.View;
@@ -29,7 +29,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Common.Internal.Intrinsic;
using StgSharp.Intrinsic;
using StgSharp.Internal;
using StgSharp.Internal.Intrinsic;
@@ -36,6 +36,7 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
@@ -125,11 +126,11 @@ namespace StgSharp.Graphics.OpenGL
}
/// <summary>
/// Bind a frame buffer to a frame buffer target Same function as <see
/// Bind a frame Buffer to a frame Buffer target Same function as <see
/// href="https://docs._gl/gl3/glBindFramebuffer">glBindFramebuffer</see>.
/// </summary>
/// <param _name="target"> The frame buffer target of the binding operation. </param>
/// <param _name="handle"> The handle of the frame buffer object to bind. </param>
/// <param _name="target"> The frame Buffer target of the binding operation. </param>
/// <param _name="handle"> The handle of the frame Buffer object to bind. </param>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void BindFrameBuffer( FrameBufferTarget target, GlHandle handle )
{
@@ -274,11 +275,11 @@ namespace StgSharp.Graphics.OpenGL
}
/// <summary>
/// Delete a render buffer object Very simlilar function as <see
/// Delete a render Buffer object Very simlilar function as <see
/// href="https://docs.gl/gl3/glDeleteRenderbuffers">glDeleteRenderbuffers</see>. The only
/// deifference is that this mehtod can only delete one renderbuffer at the same time.
/// </summary>
/// <param _name="bufferHandle"> Handle to buffer to delete. </param>
/// <param _name="bufferHandle"> Handle to Buffer to delete. </param>
public unsafe void DeleteRenderBuffer( GlHandle bufferHandle )
{
Context.glDeleteRenderbuffers( 1, &bufferHandle.Value );
@@ -451,12 +452,7 @@ namespace StgSharp.Graphics.OpenGL
ImageChannel channel,
PixelChannelLayout channelLayout,
T[] dataStream )
where T: struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
where T: struct,INumber<T>
{
#pragma warning disable CS8500
fixed( T* tptr = dataStream ) {
@@ -578,12 +574,7 @@ namespace StgSharp.Graphics.OpenGL
BufferType bufferType,
T[] bufferArray,
BufferUsage usage )
where T: struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
where T: struct,INumber<T>
{
int size = bufferArray.Length * Marshal.SizeOf( typeof( T ) );
if( bufferArray == null ) {
@@ -591,8 +582,8 @@ namespace StgSharp.Graphics.OpenGL
}
#pragma warning disable CS8500
fixed( void* bufferPtr = bufferArray )
#pragma warning restore CS8500
{
#pragma warning restore CS8500
{
Context.glBufferData(
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr,
( uint )usage );
@@ -604,12 +595,7 @@ namespace StgSharp.Graphics.OpenGL
BufferType bufferType,
ReadOnlySpan<T> bufferArray,
BufferUsage usage )
where T: struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
where T: struct,INumber<T>
{
int size = bufferArray.Length * Marshal.SizeOf( typeof( T ) );
if( bufferArray == null ) {
@@ -630,12 +616,7 @@ namespace StgSharp.Graphics.OpenGL
BufferType bufferType,
Span<T> bufferArray,
BufferUsage usage )
where T: struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
where T: struct, INumber<T>
{
int size = bufferArray.Length * Marshal.SizeOf( typeof( T ) );
if( bufferArray == null ) {
@@ -740,12 +721,7 @@ namespace StgSharp.Graphics.OpenGL
ImageChannel targetChannel,
PixelChannelLayout type,
T[] pixels )
where T: struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
where T: struct, INumber<T>
{
#pragma warning disable CS8500
fixed( T* tptr = pixels ) {
@@ -768,20 +744,15 @@ namespace StgSharp.Graphics.OpenGL
ImageChannel targetChannel,
PixelChannelLayout type,
Span<T> pixelSpan )
where T: struct,
#if NET8_0_OR_GREATER
INumber
#else
IConvertible
#endif
where T: struct, INumber<T>
{
#pragma warning disable CS8500
#pragma warning disable CS8500
fixed( T* tptr = pixelSpan ) {
Context.glTexImage2D(
( uint )target, level, ( uint )sourceChannel, width, height,
0, ( uint )targetChannel, ( uint )type, tptr );
}
#pragma warning restore CS8500
#pragma warning restore CS8500
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
@@ -29,11 +29,12 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp;
using StgSharp.Common.Internal.Intrinsic;
using StgSharp.Intrinsic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
@@ -47,15 +48,16 @@ namespace StgSharp.Internal.Intrinsic
public delegate* unmanaged[Cdecl]<ColumnSet2*, ColumnSet2*, ColumnSet2*, void> add_mat_2;
public delegate* unmanaged[Cdecl]<ColumnSet3*, ColumnSet3*, ColumnSet3*, void> add_mat_3;
public delegate* unmanaged[Cdecl]<ColumnSet4*, ColumnSet4*, ColumnSet4*, void> add_mat_4;
public delegate* unmanaged[Cdecl]<char*, int, int> cityhash_simplify;
public delegate* unmanaged[Cdecl]<char*, int, int> city_hash_simplify;
public delegate* unmanaged[Cdecl]<ColumnSet3*, ColumnSet3*, float> det_mat_3;
public delegate* unmanaged[Cdecl]<ColumnSet4*, ColumnSet4*, float> det_mat_4;
public delegate* unmanaged[Cdecl]<char*, int, int, int> index_pair;
public delegate* unmanaged[Cdecl]<ColumnSet3*, Vector4*, Vector4*, void> dot_31;
public delegate* unmanaged[Cdecl]<ColumnSet3*, Vector4*, Vector4*, void> dot_32;
public delegate* unmanaged[Cdecl]<ColumnSet4*, Vector4*, Vector4*, void> dot_41;
public delegate* unmanaged[Cdecl]<ColumnSet4*, Vector4*, Vector4*, void> dot_42;
public delegate* unmanaged[Cdecl]<ColumnSet4*, Vector4*, Vector4*, void> dot_43;
public delegate* unmanaged[Cdecl]<M128*, M128*, void> normalize_v3;
public delegate* unmanaged[Cdecl]<Vector4*, Vector4*, void> normalize_v3;
public delegate* unmanaged[Cdecl]<ColumnSet2*, ColumnSet3*, void> transpose23;
public delegate* unmanaged[Cdecl]<ColumnSet2*, ColumnSet4*, void> transpose24;
public delegate* unmanaged[Cdecl]<ColumnSet3*, ColumnSet2*, void> transpose32;
@@ -0,0 +1,50 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IRegisterType.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Intrinsic
{
public interface IRegisterType
{
public ref T AsRef<T>() where T: struct, INumber<T>;
public T Read<T>( int index ) where T: struct, INumber<T>;
public void Write<T>( int index, T value ) where T: struct, INumber<T>;
}
}
@@ -0,0 +1,185 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="M128.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
#if NET5_0_OR_GREATER
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
#endif
using System.Text;
namespace StgSharp.Intrinsic
{
[StructLayout(LayoutKind.Explicit, Pack = 16)]
public unsafe struct M128 : IRegisterType
{
[FieldOffset(0)] internal Vector4 Vec;
[FieldOffset(0)] internal fixed byte Buffer[16];
public override bool Equals([NotNullWhen(true)] object obj)
{
if (obj is not M128 other)
{
return false;
}
return this == other;
}
public override int GetHashCode()
{
return Vec.GetHashCode();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Read<T>(int index)
where T : struct, INumber<T>
{
fixed (Vector4* p = &Vec)
{
#pragma warning disable CS8500
return *((T*)p + index);
#pragma warning restore CS8500
}
}
public ref T AsRef<T>() where T : struct, INumber<T>
{
return ref Unsafe.As<byte, T>(ref Buffer[0]);
}
public override string ToString()
{
return string.Empty;
}
public string ToString(int sample)
{
string str = string.Empty;
for (int i = 15; i >= 0; i--)
{
str += $"{Convert.ToString(Read<byte>(i), sample)} ";
}
return str;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Write<T>(int index, T value)
where T : struct, INumber<T>
{
fixed (byte* p = Buffer)
{
#pragma warning disable CS8500
*((T*)p + index) = value;
#pragma warning restore CS8500
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(M128 left, M128 right)
{
return left.Vec != right.Vec;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(M128 left, M128 right)
{
return left.Vec == right.Vec;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<byte>( M128 m )
{
return m.Vec.AsVector128().As<float, byte>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<sbyte>( M128 m )
{
return m.Vec.AsVector128().As<float, sbyte>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<short>( M128 m )
{
return m.Vec.AsVector128().As<float, short>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<ushort>( M128 m )
{
return m.Vec.AsVector128().As<float, ushort>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<int>( M128 m )
{
return m.Vec.AsVector128().As<float, int>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<uint>( M128 m )
{
return m.Vec.AsVector128().As<float, uint>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<long>( M128 m )
{
return m.Vec.AsVector128().As<float, long>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<ulong>( M128 m )
{
return m.Vec.AsVector128().As<float, ulong>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<float>( M128 m )
{
return m.Vec.AsVector128().As<float, float>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<double>( M128 m )
{
return m.Vec.AsVector128().As<float, double>();
}
}
}
@@ -0,0 +1,70 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="M256.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Intrinsic
{
[StructLayout(LayoutKind.Explicit,Pack = 16)]
public unsafe struct M256 : IRegisterType
{
[FieldOffset(0)] internal fixed byte Buffer[32];
public T Read<T>(int index)
where T : struct, INumber<T>
{
fixed (byte* mptr = Buffer)
{
return *((T*)mptr + index);
}
}
public void Write<T>(int index, T value)
where T : struct, INumber<T>
{
fixed (byte* mptr = Buffer)
{
*((T*)mptr + index) = value;
}
}
public ref T AsRef<T>() where T : struct, INumber<T>
{
return ref Unsafe.As<byte, T>(ref Buffer[0]);
}
}
}
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text;
namespace StgSharp.Intrinsic
{
public static class UnsafeCompute
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe int IndexOfCharPair(char* source, int pairValue, int length)
{
return InternalIO.Intrinsic.index_pair(source, pairValue, length);
}
}
}
@@ -28,8 +28,9 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Common.Internal.Intrinsic;
using StgSharp.Intrinsic;
using StgSharp.Internal.Intrinsic;
using System;
using System.Collections.Generic;
using System.Data.Common;
@@ -29,7 +29,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Common.Internal.Intrinsic;
using StgSharp.Intrinsic;
using StgSharp.Internal.Intrinsic;
using System;
using System.Numerics;
@@ -28,7 +28,7 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Common.Internal.Intrinsic;
using StgSharp.Intrinsic;
using StgSharp.Internal.Intrinsic;
using StgSharp.Math;
@@ -34,6 +34,7 @@ using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Data;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
@@ -86,10 +87,7 @@ namespace StgSharp.Math
/// </summary>
/// <returns></returns>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static T Random<T>() where T: struct, IConvertible
#if NET8_0_OR_GREATER
,INumber
#endif
public static T Random<T>() where T: struct, IConvertible, INumber<T>
{
if( randomSeed == null ) {
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<LangVersion>Preview</LangVersion>
<ProduceReferenceAssembly>True</ProduceReferenceAssembly>
@@ -71,11 +71,6 @@
<PropertyGroup Condition="'$(IsLinux)'=='true'">
<DefineConstants>LINUX</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Internal\glLoader\**" />
<EmbeddedResource Remove="Internal\glLoader\**" />
<None Remove="Internal\glLoader\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
@@ -88,10 +83,6 @@
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Data\Intrinsic\" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
</Target>
@@ -13,11 +13,16 @@
"packagesPath": "C:\\Users\\Youmu\\.nuget\\packages\\",
"outputPath": "D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\StgSharp.Common\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\Youmu\\AppData\\Roaming\\NuGet\\NuGet.Config"
"C:\\Users\\Youmu\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"netstandard2.1"
"net8.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
@@ -26,8 +31,8 @@
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netstandard2.1": {
"targetAlias": "netstandard2.1",
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
@@ -43,8 +48,8 @@
}
},
"frameworks": {
"netstandard2.1": {
"targetAlias": "netstandard2.1",
"net8.0": {
"targetAlias": "net8.0",
"dependencies": {
"Microsoft.CSharp": {
"target": "Package",
@@ -67,11 +72,11 @@
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"NETStandard.Library": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.400\\RuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.400/PortableRuntimeIdentifierGraph.json"
}
}
}
@@ -1,31 +1,26 @@
{
"version": 3,
"targets": {
".NETStandard,Version=v2.1": {
"net8.0": {
"Microsoft.CSharp/4.7.0": {
"type": "package",
"compile": {
"ref/netstandard2.0/Microsoft.CSharp.dll": {
"related": ".xml"
}
"ref/netcoreapp2.0/_._": {}
},
"runtime": {
"lib/netstandard2.0/Microsoft.CSharp.dll": {
"related": ".xml"
}
"lib/netcoreapp2.0/_._": {}
}
},
"System.Runtime.CompilerServices.Unsafe/6.1.0": {
"type": "package",
"compile": {
"lib/netstandard2.0/System.Runtime.CompilerServices.Unsafe.dll": {
"related": ".xml"
}
"lib/net7.0/_._": {}
},
"runtime": {
"lib/netstandard2.0/System.Runtime.CompilerServices.Unsafe.dll": {
"related": ".xml"
}
"lib/net7.0/_._": {}
},
"build": {
"buildTransitive/net6.0/_._": {}
}
}
}
@@ -124,13 +119,14 @@
}
},
"projectFileDependencyGroups": {
".NETStandard,Version=v2.1": [
"net8.0": [
"Microsoft.CSharp >= 4.7.0",
"System.Runtime.CompilerServices.Unsafe >= 6.1.0"
]
},
"packageFolders": {
"C:\\Users\\Youmu\\.nuget\\packages\\": {}
"C:\\Users\\Youmu\\.nuget\\packages\\": {},
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
},
"project": {
"version": "1.0.0",
@@ -141,11 +137,16 @@
"packagesPath": "C:\\Users\\Youmu\\.nuget\\packages\\",
"outputPath": "D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\StgSharp.Common\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\Youmu\\AppData\\Roaming\\NuGet\\NuGet.Config"
"C:\\Users\\Youmu\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"netstandard2.1"
"net8.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
@@ -154,8 +155,8 @@
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netstandard2.1": {
"targetAlias": "netstandard2.1",
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
@@ -171,8 +172,8 @@
}
},
"frameworks": {
"netstandard2.1": {
"targetAlias": "netstandard2.1",
"net8.0": {
"targetAlias": "net8.0",
"dependencies": {
"Microsoft.CSharp": {
"target": "Package",
@@ -195,11 +196,11 @@
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"NETStandard.Library": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.400\\RuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.400/PortableRuntimeIdentifierGraph.json"
}
}
}
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
@@ -0,0 +1,24 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Common")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4e5a1b0dfb69dd073410d254e2bab596629c4536")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Common")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Common")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyMetadataAttribute("RepositoryUrl", "https://github.com/Nitload-NSI/StgSharp.git")]
// 由 MSBuild WriteCodeFragment 类生成。
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Common")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4ee675669ffd20ba891984a7dcdc6e382d12143f")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4e5a1b0dfb69dd073410d254e2bab596629c4536")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Common")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Common")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1,15 +0,0 @@
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Common\bin\x64\Debug\netstandard2.1\StgSharp.Common.deps.json
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Common\bin\x64\Debug\netstandard2.1\StgSharp.Common.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Common\bin\x64\Debug\netstandard2.1\StgSharp.Common.pdb
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Common\bin\x64\Debug\netstandard2.1\StgSharp.Common.xml
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Common\obj\x64\Debug\netstandard2.1\StgSharp.Common.csproj.AssemblyReference.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Common\obj\x64\Debug\netstandard2.1\StgSharp.Common.GeneratedMSBuildEditorConfig.editorconfig
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Common\obj\x64\Debug\netstandard2.1\StgSharp.Common.AssemblyInfoInputs.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Common\obj\x64\Debug\netstandard2.1\StgSharp.Common.AssemblyInfo.cs
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Common\obj\x64\Debug\netstandard2.1\StgSharp.Common.csproj.CoreCompileInputs.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Common\obj\x64\Debug\netstandard2.1\StgSharp.Common.sourcelink.json
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Common\obj\x64\Debug\netstandard2.1\StgSharp.Common.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Common\obj\x64\Debug\netstandard2.1\refint\StgSharp.Common.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Common\obj\x64\Debug\netstandard2.1\StgSharp.Common.xml
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Common\obj\x64\Debug\netstandard2.1\StgSharp.Common.pdb
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Common\obj\x64\Debug\netstandard2.1\ref\StgSharp.Common.dll