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()