daily update on 20250210 by nitload youmu

This commit is contained in:
Nitload
2025-02-10 12:48:02 +08:00
parent ae94c265ae
commit c23b640cae
70 changed files with 2135 additions and 805 deletions
@@ -39,23 +39,23 @@ namespace StgSharp.Commom.Collections
internal class CapacityFixedList<T> : IList<T>
{
private T[] values;
private T[] _values;
private int capacity, _index;
public CapacityFixedList( int size )
{
values = new T[size];
_values = new T[size];
}
public T this[ int index ]
{
get => index < _index ?
values[ index ] : throw new ArgumentOutOfRangeException(
_values[ index ] : throw new ArgumentOutOfRangeException(
nameof( index ) );
set
{
if( index < _index ) {
values[ index ] = value;
_values[ index ] = value;
} else {
throw new ArgumentOutOfRangeException( nameof( index ) );
}
@@ -76,14 +76,14 @@ namespace StgSharp.Commom.Collections
public void Clear()
{
values = new T[capacity];
_values = new T[capacity];
_index = 0;
}
public bool Contains( T item )
{
for( int i = 0; i <= _index; i++ ) {
if( item.Equals( values[ i ] ) ) {
if( item.Equals( _values[ i ] ) ) {
return true;
}
}
@@ -92,13 +92,13 @@ namespace StgSharp.Commom.Collections
public void CopyTo( T[] array, int arrayIndex )
{
values.CopyTo( array, arrayIndex );
_values.CopyTo( array, arrayIndex );
}
public IEnumerator<T> GetEnumerator()
{
for( int i = 0; i <= _index; i++ ) {
yield return values[ i ];
yield return _values[ i ];
}
}
@@ -106,7 +106,7 @@ namespace StgSharp.Commom.Collections
{
T v;
for( int i = 0; i <= _index; i++ ) {
if( ( v = values[ i ] ) != null && v.Equals( item ) ) {
if( ( v = _values[ i ] ) != null && v.Equals( item ) ) {
return i;
}
}
@@ -117,8 +117,8 @@ namespace StgSharp.Commom.Collections
{
T v;
for( int i = 0; i <= _index; i++ ) {
if( ( v = values[ i ] ) != null && v.Equals( item ) ) {
values[ i ] = values[ _index ];
if( ( v = _values[ i ] ) != null && v.Equals( item ) ) {
_values[ i ] = _values[ _index ];
_index--;
return true;
}
@@ -129,8 +129,8 @@ namespace StgSharp.Commom.Collections
public void RemoveAll( Predicate<T> predicate )
{
for( int i = _index; i > 0; i-- ) {
if( predicate( values[ i ] ) ) {
values[ i ] = values[ _index ];
if( predicate( _values[ i ] ) ) {
_values[ i ] = _values[ _index ];
_index--;
}
}
@@ -139,14 +139,14 @@ namespace StgSharp.Commom.Collections
public void RemoveAt( int index )
{
if( index <= _index ) {
values[ index ] = values[ _index ];
_values[ index ] = _values[ _index ];
_index--;
}
}
public void Resize( int newSize )
{
Array.Resize( ref values, newSize );
Array.Resize( ref _values, newSize );
}
IEnumerator IEnumerable.GetEnumerator()
@@ -0,0 +1,78 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Collections
{
/// <summary>
/// Part of a collection. This contains a direct reference to origin collection,
/// so all change to origin collection will be reflected in this object.
/// </summary>
/// <typeparam name="T"></typeparam>
public class ReferencedSlicedCollection<T> : ICollection<T>
{
private ICollection<T> _collection;
private int _begin;
private int _length;
internal ReferencedSlicedCollection()
{
_collection = Array.Empty<T>();
_begin = 0;
_length = 0;
}
public ReferencedSlicedCollection(ICollection<T> collection, int begin, int length)
{
ArgumentNullException.ThrowIfNull(collection);
ArgumentOutOfRangeException.ThrowIfLessThan(begin, 0);
ArgumentOutOfRangeException.ThrowIfLessThan(length, 0);
ArgumentOutOfRangeException.ThrowIfLessThan(begin + length, collection.Count);
_collection = collection;
_begin = begin;
_length = length;
}
public int Count => _length;
public bool IsReadOnly => true;
void ICollection<T>.Add(T item)
{
throw new NotSupportedException();
}
public void Clear()
{
throw new NotImplementedException();
}
public bool Contains(T item)
{
throw new NotImplementedException();
}
public void CopyTo(T[] array, int arrayIndex)
{
throw new NotImplementedException();
}
public IEnumerator<T> GetEnumerator()
{
throw new NotImplementedException();
}
public bool Remove(T item)
{
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}
}
@@ -14,6 +14,16 @@ namespace StgSharp.Intrinsic
return InternalIO.Intrinsic.index_pair(source, pairValue, length);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe int CityHashSimplify(char* span, int length)
{
return InternalIO.Intrinsic.city_hash_simplify(span,length);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe int CityHashSimplify(char* span, int begin, int length)
{
return InternalIO.Intrinsic.city_hash_simplify(span + begin, length);
}
}
}
@@ -0,0 +1,153 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="CancellableTask.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.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Threading
{
public class CancellableTask:IDisposable
{
private protected Action<CancellationToken> _startup;
private protected Task _internalTask;
private CancellationTokenSource cts;
private bool disposedValue;
private protected CancellableTask()
{
cts = new CancellationTokenSource();
}
private protected CancellableTask( Action<CancellationToken> action )
{
_internalTask = new Task( InternalAction );
cts = new CancellationTokenSource();
}
public bool IsCompleted
{
get => _internalTask.IsCompleted;
}
public CancellationTokenSource Cts
{
get => cts;
}
public int Id
{
get => _internalTask.Id;
}
public void Cancel()
{
Cts.Cancel();
}
public void CancelAndWait()
{
Cts.Cancel();
_internalTask.Wait();
}
public static CancellableTask Run( Action<CancellationToken> startup )
{
CancellableTask ret = new CancellableTask { _startup = startup };
ret._internalTask = Task.Run( ret.InternalAction );
return ret;
}
public void Wait()
{
_internalTask.Wait();
}
public static void WaitAll( IEnumerable<CancellableTask> tasks )
{
IEnumerable<Task> convertedTasks = tasks.Select<CancellableTask, Task>(
ct => ct._internalTask );
Task.WaitAll( convertedTasks.ToArray() );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
internal void InternalAction()
{
//Console.WriteLine($"Task {Task.CurrentId} is running.");
_startup( Cts.Token );
}
public static implicit operator Task( CancellableTask task )
{
return task._internalTask;
}
~CancellableTask()
{
Cts.Dispose();
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
if (IsCompleted)
{
cts.Dispose();
_internalTask.Dispose();
}
else
{
throw new InvalidOperationException("Cannot dispose a cancellable task before completed");
}
}
disposedValue = true;
}
}
// ~CancellableTask()
// {
// Dispose(disposing: false);
// }
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
@@ -0,0 +1,62 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="EmptyThread.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;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Threading
{
public static partial class ThreadHelper
{
private static readonly Thread _emptyThreadCache = new Thread(
() => { } );
static ThreadHelper()
{
_emptyThreadCache.Start();
}
/// <summary>
/// An individual thread doing nothing, and its <see cref="Thread.IsAlive" /> <see
/// langword="property" /> always returns false.
/// </summary>
public static Thread EmptyThread
{
get => _emptyThreadCache;
}
}
}
@@ -0,0 +1,59 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="MainThreadAssert.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;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Threading
{
public static partial class ThreadHelper
{
private static readonly int mainThreadId = Environment.CurrentManagedThreadId;
private static readonly ThreadLocal<bool> isNotMainThread = new ThreadLocal<bool>(
() => Environment.CurrentManagedThreadId != mainThreadId );
[Conditional( "DEBUG" )]
internal static void MainThreadAssert()
{
if( isNotMainThread.Value ) {
throw new InvalidOperationException(
$"Attempt to call sensitive operation which can be only called from main thread "
+ $"from thread {Environment.CurrentManagedThreadId}." );
}
}
}
}
@@ -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+7d0470d50b970b6493b9fca12bce74b01444ca46")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ae94c265ae77870ea6498b624b6f71b78fb94e51")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Common")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Common")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/7d0470d50b970b6493b9fca12bce74b01444ca46/*"}}
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/ae94c265ae77870ea6498b624b6f71b78fb94e51/*"}}