daily update on 20241002 by nitload youmu, intrinsic function rebuild, syntax style arrange

This commit is contained in:
Nitload
2024-10-03 04:03:06 +08:00
parent 0979123ac0
commit 6e2f93b053
265 changed files with 26732 additions and 19058 deletions
+4 -7
View File
@@ -39,12 +39,9 @@ using System.Threading.Tasks;
namespace StgSharp.Data
{
/// <summary>
/// An independent storage area, used as the only folder type in root folder.
/// Contains several <see cref="SSD"/> files reference as virtual disc.
/// Data is actually stored in <see cref="SSD"/>s in certain RAID mode.
/// An independent storage area, used as the only folder type in root folder. Contains several
/// <see cref="SSD" /> files reference as virtual disc. Data is actually stored in <see
/// cref="SSD" />s in certain RAID mode.
/// </summary>
public partial class Area
{
}
public partial class Area { }
}
+18 -24
View File
@@ -28,6 +28,8 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Data.Intrinsic;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -38,52 +40,44 @@ using System.Text;
namespace StgSharp.Data
{
[StructLayout(LayoutKind.Explicit, Size = 16)]
[StructLayout( LayoutKind.Explicit, Size = 16 )]
public struct SSDSegmentHead
{
[FieldOffset( 12 )] internal byte size;
[FieldOffset(12)] internal byte size;
[FieldOffset(0)] internal M128 data;
[FieldOffset(13)] public byte selfDefine_1;
[FieldOffset(14)] public byte selfDefine_2;
[FieldOffset(15)] public byte selfDefine_3;
[FieldOffset(0)] public int globalID;
[FieldOffset(4)] public int nextID;
[FieldOffset(8)] public int previousHash;
[FieldOffset( 0 )] internal M128 data;
[FieldOffset( 13 )] public byte selfDefine_1;
[FieldOffset( 14 )] public byte selfDefine_2;
[FieldOffset( 15 )] public byte selfDefine_3;
[FieldOffset( 0 )] public int globalID;
[FieldOffset( 4 )] public int nextID;
[FieldOffset( 8 )] public int previousHash;
public int Size
{
get => ((int)size) + 1;
get => ( ( int )size ) + 1;
set
{
if ((value > 256) || (value < 0))
{
if( ( value > 256 ) || ( value < 0 ) ) {
throw new ArgumentOutOfRangeException();
}
size = (byte)(value - 1);
size = ( byte )( value - 1 );
}
}
public unsafe byte[] GetBytes()
{
byte[] ret = new byte[16];
fixed (Vector4* vptr = &data.vec)
{
byte* bptr = (byte*)vptr;
for (int i = 0; i < 15; i++)
{
ret[i] = *bptr;
fixed( Vector4* vptr = &data.vec ) {
byte* bptr = ( byte* )vptr;
for( int i = 0; i < 15; i++ ) {
ret[ i ] = *bptr;
}
}
return ret;
}
}
}
+51 -65
View File
@@ -28,6 +28,7 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Data.Intrinsic;
using StgSharp.Math;
using System;
@@ -40,38 +41,37 @@ using System.Threading.Tasks;
namespace StgSharp.Data
{
[StructLayout(LayoutKind.Explicit, Size = StgSharp.ssdSegmentLength * 16)]
[StructLayout( LayoutKind.Explicit, Size = StgSharp.ssdSegmentLength * 16 )]
public unsafe struct SSDSegment : IComparable<int>, IComparable<SSDSegment>
{
[FieldOffset(16)] public fixed byte Data[16 * (StgSharp.ssdSegmentLength - 1)];
[FieldOffset(12)] public int DataHash;
[FieldOffset(8)] public int PreviousHash;
[FieldOffset(0 * 16)] public SSDSegmentHead Head;
[FieldOffset( 16 )] public fixed byte Data[
16 * ( StgSharp.ssdSegmentLength - 1 ) ];
[FieldOffset( 12 )] public int DataHash;
[FieldOffset( 8 )] public int PreviousHash;
[FieldOffset( 0 * 16 )] public SSDSegmentHead Head;
public SSDSegment(int previousHash)
public SSDSegment( int previousHash )
{
this.PreviousHash = previousHash;
}
public byte this[int index]
public byte this[ int index ]
{
get
{
if (index > (16 * (StgSharp.ssdSegmentLength - 1)) - 1)
{
if( index > ( 16 * ( StgSharp.ssdSegmentLength - 1 ) ) - 1 ) {
throw new IndexOutOfRangeException();
}
return Data[index];
return Data[ index ];
}
set
{
if (index > (16 * (StgSharp.ssdSegmentLength - 1)) - 1)
{
if( index > ( 16 * ( StgSharp.ssdSegmentLength - 1 ) ) - 1 ) {
throw new IndexOutOfRangeException();
}
Data[index] = value;
Data[ index ] = value;
}
}
@@ -83,31 +83,27 @@ namespace StgSharp.Data
public short Size => Head.size;
public void FillRandomBytes(int begin)
public void FillRandomBytes( int begin )
{
if (begin > 255)
{
if( begin > 255 ) {
return;
}
for (int i = begin; i < 255; i++)
{
Data[i] = Scaler.Random<byte>(); //TODO: 使用STGSHARP内部随机数工具处理它
for( int i = begin; i < 255; i++ ) {
Data[ i ] = Scaler.Random<byte>(); //TODO: 使用STGSHARP内部随机数工具处理它
}
}
public static SSDSegment FromStream(byte[] stream)
public static SSDSegment FromStream( byte[] stream )
{
if (stream.Length != 16 * StgSharp.ssdSegmentLength)
{
if( stream.Length != 16 * StgSharp.ssdSegmentLength ) {
throw new ArgumentException();
}
SSDSegment ret = new SSDSegment();
fixed (byte* bptr = stream)
{
ret.Head.data = *(M128*)bptr;
for (int i = 1; i < StgSharp.ssdSegmentLength; i++)
{
ret.WriteData<M128>(i - 1, *(M128*)(bptr + (16 * i)));
fixed( byte* bptr = stream ) {
ret.Head.data = *( M128* )bptr;
for( int i = 1; i < StgSharp.ssdSegmentLength; i++ ) {
ret.WriteData<M128>(
i - 1, *( M128* )( bptr + ( 16 * i ) ) );
}
}
return ret;
@@ -116,15 +112,12 @@ namespace StgSharp.Data
public byte[] GetBytes()
{
byte[] ret = new byte[16 * StgSharp.ssdSegmentLength];
fixed (M128* mptr = &Head.data)
{
fixed (byte* aptr = ret)
{
Vector4* vsptr = (Vector4*)mptr;
Vector4* vtptr = (Vector4*)aptr;
for (int i = 0; i < 18; i++)
{
*(vtptr + i) = *(vsptr + i);
fixed( M128* mptr = &Head.data ) {
fixed( byte* aptr = ret ) {
Vector4* vsptr = ( Vector4* )mptr;
Vector4* vtptr = ( Vector4* )aptr;
for( int i = 0; i < 18; i++ ) {
*( vtptr + i ) = *( vsptr + i );
}
}
}
@@ -135,15 +128,13 @@ namespace StgSharp.Data
public int GetDataHash()
{
Vector4 v = Vector4.One;
fixed (M128* mptr = &Head.data)
{
Vector4* vptr = (Vector4*)mptr;
for (int i = 0; i < StgSharp.ssdSegmentLength - 1; i += 1)
{
v += (*vptr) * 31;
fixed( M128* mptr = &Head.data ) {
Vector4* vptr = ( Vector4* )mptr;
for( int i = 0; i < StgSharp.ssdSegmentLength - 1; i += 1 ) {
v += ( *vptr ) * 31;
}
}
M128 m = new M128(v);
M128 m = new M128( v );
DataHash = m.vec.GetHashCode();
return DataHash;
}
@@ -151,45 +142,40 @@ namespace StgSharp.Data
public override int GetHashCode()
{
int ret = 17;
fixed (M128* mptr = &Head.data)
{
Vector4* vptr = (Vector4*)mptr;
for (int i = 0; i < StgSharp.ssdSegmentLength; i++)
{
ret = (ret + (*vptr).GetHashCode()) * 31;
fixed( M128* mptr = &Head.data ) {
Vector4* vptr = ( Vector4* )mptr;
for( int i = 0; i < StgSharp.ssdSegmentLength; i++ ) {
ret = ( ret + ( *vptr ).GetHashCode() ) * 31;
}
}
return ret;
}
public unsafe T ReadData<T>(int index) where T : struct
public unsafe T ReadData<T>( int index ) where T: struct
{
fixed (byte* bptr = Data)
{
T* tptr = (T*)bptr;
return *(tptr + index);
fixed( byte* bptr = Data ) {
T* tptr = ( T* )bptr;
return *( tptr + index );
}
}
public unsafe void WriteData<T>(int index, T value) where T : struct
public unsafe void WriteData<T>( int index, T value ) where T: struct
{
fixed (byte* bptr = Data)
{
T* tptr = (T*)bptr;
*(tptr + index) = value;
fixed( byte* bptr = Data ) {
T* tptr = ( T* )bptr;
*( tptr + index ) = value;
}
}
int IComparable<int>.CompareTo(int other)
int IComparable<int>.CompareTo( int other )
{
return ID.CompareTo(other);
return ID.CompareTo( other );
}
int IComparable<SSDSegment>.CompareTo(SSDSegment other)
int IComparable<SSDSegment>.CompareTo( SSDSegment other )
{
return ID.CompareTo(other.ID);
return ID.CompareTo( other.ID );
}
}
}
+6 -4
View File
@@ -50,17 +50,19 @@ namespace StgSharp.Data
fileList = new Dictionary<string, SSDraw>();
}
public SSD(FileStream fileStream)
public SSD( FileStream fileStream )
{
fileList = new Dictionary<string, SSDraw>();
file = fileStream;
}
public static SSD FromFile(string fileRoute)
public static SSD FromFile( string fileRoute )
{
return new SSD(new FileStream(fileRoute, FileMode.Open, FileAccess.Read)) { };
return new SSD(
new FileStream( fileRoute, FileMode.Open, FileAccess.Read ) )
{
};
}
}
}
@@ -49,19 +49,15 @@ namespace StgSharp.Data
folders = new Dictionary<string, SSDFolder>();
}
internal SSDFolder(string name)
internal SSDFolder( string name )
{
if (name == "root")
{
if( name == "root" ) {
throw new ArgumentException(
"Name cannot be root," +
"it is preserved for root file indexer.");
"Name cannot be root," + "it is preserved for root file indexer." );
}
if (name == "default")
{
if( name == "default" ) {
throw new ArgumentException(
"Name cannot be default," +
"it is preserved for default file id provider.");
"Name cannot be default," + "it is preserved for default file id provider." );
}
_name = name;
folders = new Dictionary<string, SSDFolder>();
@@ -69,12 +65,11 @@ namespace StgSharp.Data
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.VirtualFolder;
public void FromBytes(byte[] stream)
public void FromBytes( byte[] stream )
{
throw new NotImplementedException();
}
//TODO 虚拟文件夹的GetBytes好难写
public byte[] GetBytes()
{
+17 -15
View File
@@ -50,28 +50,30 @@ namespace StgSharp.Data.FileIO
private byte[] data;
public SSDraw(string name, Stream streamSource)
public SSDraw( string name, Stream streamSource )
{
if ((streamSource == null) || (streamSource.Length == 0))
{
throw new ArgumentNullException(nameof(streamSource));
if( ( streamSource == null ) || ( streamSource.Length == 0 ) ) {
throw new ArgumentNullException( nameof( streamSource ) );
}
Name = name;
data = new byte[streamSource.Length];
streamSource.Read(data.AsSpan());
streamSource.Read( data.AsSpan() );
}
public SSDrawHead Head { get; set; }
public string Name { get; set; }
public SSDrawHead Head
{
get;
set;
}
public string Name
{
get;
set;
}
}
[StructLayout(LayoutKind.Explicit, Size = 32 * 16)]
public unsafe struct SSDrawHead
{
}
[StructLayout( LayoutKind.Explicit, Size = 32 * 16 )]
public unsafe struct SSDrawHead { }
}