daily update on 20240104 by nitload youmu, double threading not work
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using StgSharp.Graphics;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -9,6 +10,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
{
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 8)]
|
||||
internal struct LogSeperator
|
||||
{
|
||||
@@ -28,6 +31,8 @@ namespace StgSharp.Logic
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A linear data structure with dynamic length.
|
||||
/// It contains a <see cref="List{T}"/> of <see cref="Array"/>,
|
||||
@@ -47,6 +52,7 @@ namespace StgSharp.Logic
|
||||
// sub index to the last used element
|
||||
private Queue<int> unusedMainIndex;
|
||||
private Queue<int> unusedSubIndex;
|
||||
|
||||
public DynamicArrayList()
|
||||
{
|
||||
arrayIndexList = [new T[1]];
|
||||
@@ -91,6 +97,43 @@ namespace StgSharp.Logic
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new instance of <see cref="DynamicArrayList{T}">,
|
||||
/// and fill the begining ones of elemtns as given instance.
|
||||
/// </summary>
|
||||
/// <param name="count">Amount of beginning elements to be filled</param>
|
||||
/// <param name="instace"></param>
|
||||
public DynamicArrayList(int count, T instace)
|
||||
{
|
||||
|
||||
arrayIndexList = new List<T[]>();
|
||||
length = count;
|
||||
unusedMainIndex = new();
|
||||
unusedSubIndex = new();
|
||||
|
||||
SeprateIndex(count);
|
||||
int subcount = 1;
|
||||
for (int i = 0; i < indexpair.high_s; i++)
|
||||
{
|
||||
arrayIndexList.Add(new T[count]);
|
||||
for (int j = 0; j < subcount; j++)
|
||||
{
|
||||
unusedMainIndex.Enqueue(i);
|
||||
unusedSubIndex.Enqueue(j);
|
||||
}
|
||||
count >>= 1;
|
||||
}
|
||||
if (indexpair.low_s != 0)
|
||||
{
|
||||
arrayIndexList.Add(new T[1 >> indexpair.high_s]);
|
||||
for (int j = 0; j < indexpair.high_s; j++)
|
||||
{
|
||||
unusedMainIndex.Enqueue(indexpair.high_s);
|
||||
unusedSubIndex.Enqueue(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal T this[long index]
|
||||
{
|
||||
get
|
||||
@@ -122,6 +165,25 @@ namespace StgSharp.Logic
|
||||
|
||||
}
|
||||
|
||||
public void CopyTo(DynamicArrayList<T> target)
|
||||
{
|
||||
target.arrayIndexList.Clear();
|
||||
int length = 1;
|
||||
foreach (T[] tList in target.arrayIndexList)
|
||||
{
|
||||
T[] newIndex = new T[length];
|
||||
Buffer.BlockCopy(tList, 0, newIndex, 0, length);
|
||||
target.arrayIndexList.Add(newIndex);
|
||||
length <<= 1;
|
||||
}
|
||||
|
||||
target.lastMain = lastMain;
|
||||
target.lastSub = lastSub;
|
||||
target.length = length;
|
||||
target.unusedMainIndex = new Queue<int>(unusedMainIndex.ToArray());
|
||||
target.unusedSubIndex = new Queue<int>(unusedSubIndex.ToArray());
|
||||
}
|
||||
|
||||
public T this[int index]
|
||||
{
|
||||
get
|
||||
@@ -192,6 +254,7 @@ namespace StgSharp.Logic
|
||||
arrayIndexList[lastMain][0] = item;
|
||||
|
||||
length++;
|
||||
subLength = 1;
|
||||
return length - 1;
|
||||
|
||||
}
|
||||
@@ -199,6 +262,7 @@ namespace StgSharp.Logic
|
||||
length++;
|
||||
lastSub++;
|
||||
arrayIndexList[lastMain][lastSub] = item;
|
||||
subLength = 1;
|
||||
return length - 1;
|
||||
}
|
||||
|
||||
@@ -207,15 +271,19 @@ namespace StgSharp.Logic
|
||||
int sub = unusedSubIndex.Dequeue();
|
||||
arrayIndexList[main][sub] = item;
|
||||
|
||||
subLength = 1;
|
||||
return sub + (1 << main);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
arrayIndexList.Clear();
|
||||
arrayIndexList.Add(new T[1]);
|
||||
unusedMainIndex.Clear();
|
||||
unusedSubIndex.Clear();
|
||||
length = 0;
|
||||
unusedMainIndex.Enqueue(0);
|
||||
unusedSubIndex.Enqueue(0);
|
||||
}
|
||||
|
||||
public bool Contains(T item)
|
||||
@@ -252,6 +320,7 @@ namespace StgSharp.Logic
|
||||
return -1;
|
||||
}
|
||||
|
||||
[Obsolete("This method is not same, you may read data form an empty index.", false)]
|
||||
public bool Remove(T item)
|
||||
{
|
||||
int index = 0;
|
||||
@@ -288,6 +357,9 @@ namespace StgSharp.Logic
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Obsolete("This method is not same, you may read data form an empty index.", false)]
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if (index > length || index < 0)
|
||||
@@ -295,7 +367,6 @@ namespace StgSharp.Logic
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
SeprateIndex(index);
|
||||
arrayIndexList[indexpair.high_s][indexpair.low] = default;
|
||||
|
||||
//the last element was removed.
|
||||
if (index + 1 == length)
|
||||
@@ -313,7 +384,6 @@ namespace StgSharp.Logic
|
||||
|
||||
unusedMainIndex.Enqueue(indexpair.high_s);
|
||||
unusedSubIndex.Enqueue(indexpair.low_s);
|
||||
|
||||
}
|
||||
|
||||
public void ShowStructure()
|
||||
|
||||
Reference in New Issue
Block a user