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
@@ -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;
}
}
}
}