/// 缓存1,代表原始缓存
public List<List<int>> Cache = new List<List<int>>();
/// 缓存2:代表二分后的缓存。
List<List<int>> Cache2 = new List<List<int>>();
/// 原始列索引
private int OrgColumnIndex = -1;
/// 当前列的统计次数。
private int ColumnSum = 0;
/// 取得结果。
public List<List<int>> GetResultList()
{
for (int i = Cache2.Count; i > 0; i--)
{
List<int> listobj = Cache2[i - 1];
if (listobj.Count <= 1)
Cache2.RemoveAt(i - 1);
}
//Print(Cache2);
return Cache2;
}
/// 建立指定数量的数组
private List<List<int>> GetNewList(int count)
{
List<List<int>> TempCache = new List<List<int>>(count);
for (int i = 0; i < count; i++)
{
TempCache.Add(new List<int>());
}
return TempCache;
} private void Print(List<List<int>> list)
{
//System.Diagnostics.Debug.WriteLine("");
for (int i = 0; i < list.Count; i++)
{
List<int> listobj = list[i];
for (int i1 = 0; i1 < listobj.Count; i1++)
{
System.Diagnostics.Debug.Write(" " + listobj[i1]);
}
//System.Diagnostics.Debug.WriteLine("");
}
}
/// 通知系统更换了列。
public void Notify(int NewColumnIndex)
{
if (OrgColumnIndex != NewColumnIndex)
{
if (ColumnSum > 0)
{
if (Cache2.Count > 0)
{
// 清理单项行集索引。
for (int i = Cache2.Count; i > 0; i--)
{
List<int> listobj = Cache2[i - 1];
if (listobj.Count <= 1)
Cache2.RemoveAt(i - 1);
}
// 新旧数组转换。
Cache = Cache2;
// 生成新的目标缓存。
Cache2 = GetNewList(Cache.Count * 2);
}
else
{
Cache2 = GetNewList(Cache.Count * 2);
}
}
else
{
Cache = GetNewList(2);
} ColumnSum++;
OrgColumnIndex = NewColumnIndex;
}
} /// 通知按行,列索引数值及矩阵数值进行二分拆分。
public void Notify(int RowIndex, int value)
{
//System.Diagnostics.Debug.WriteLine("列索引:" + RowIndex + " value=" + value);
if (ColumnSum > 1)
{
for (int i = 0; i < Cache.Count; i++)
{
if (Cache[i].Contains(RowIndex))
{
// 在Cache2中,0为低位,1为高位。
int newindex = i * 2 + value;
Cache2[newindex].Add(RowIndex);
}
}
}
else
{
if (value == 0)
Cache[0].Add(RowIndex);
else
Cache[1].Add(RowIndex);
}
}
public void Run(List<List<int>> lt)
{
Cache = lt;
Notify(5);
Print(lt);
}
public List<List<int>> Cache = new List<List<int>>();
/// 缓存2:代表二分后的缓存。
List<List<int>> Cache2 = new List<List<int>>();
/// 原始列索引
private int OrgColumnIndex = -1;
/// 当前列的统计次数。
private int ColumnSum = 0;
/// 取得结果。
public List<List<int>> GetResultList()
{
for (int i = Cache2.Count; i > 0; i--)
{
List<int> listobj = Cache2[i - 1];
if (listobj.Count <= 1)
Cache2.RemoveAt(i - 1);
}
//Print(Cache2);
return Cache2;
}
/// 建立指定数量的数组
private List<List<int>> GetNewList(int count)
{
List<List<int>> TempCache = new List<List<int>>(count);
for (int i = 0; i < count; i++)
{
TempCache.Add(new List<int>());
}
return TempCache;
} private void Print(List<List<int>> list)
{
//System.Diagnostics.Debug.WriteLine("");
for (int i = 0; i < list.Count; i++)
{
List<int> listobj = list[i];
for (int i1 = 0; i1 < listobj.Count; i1++)
{
System.Diagnostics.Debug.Write(" " + listobj[i1]);
}
//System.Diagnostics.Debug.WriteLine("");
}
}
/// 通知系统更换了列。
public void Notify(int NewColumnIndex)
{
if (OrgColumnIndex != NewColumnIndex)
{
if (ColumnSum > 0)
{
if (Cache2.Count > 0)
{
// 清理单项行集索引。
for (int i = Cache2.Count; i > 0; i--)
{
List<int> listobj = Cache2[i - 1];
if (listobj.Count <= 1)
Cache2.RemoveAt(i - 1);
}
// 新旧数组转换。
Cache = Cache2;
// 生成新的目标缓存。
Cache2 = GetNewList(Cache.Count * 2);
}
else
{
Cache2 = GetNewList(Cache.Count * 2);
}
}
else
{
Cache = GetNewList(2);
} ColumnSum++;
OrgColumnIndex = NewColumnIndex;
}
} /// 通知按行,列索引数值及矩阵数值进行二分拆分。
public void Notify(int RowIndex, int value)
{
//System.Diagnostics.Debug.WriteLine("列索引:" + RowIndex + " value=" + value);
if (ColumnSum > 1)
{
for (int i = 0; i < Cache.Count; i++)
{
if (Cache[i].Contains(RowIndex))
{
// 在Cache2中,0为低位,1为高位。
int newindex = i * 2 + value;
Cache2[newindex].Add(RowIndex);
}
}
}
else
{
if (value == 0)
Cache[0].Add(RowIndex);
else
Cache[1].Add(RowIndex);
}
}
public void Run(List<List<int>> lt)
{
Cache = lt;
Notify(5);
Print(lt);
}
都是写基本的c#语法
高手 貌似是矩阵二分,矩阵二分是干什么的啊 急着要呢 解释下 谢谢