📄 partitionasforest.cs
字号:
namespace Opus6
{
using System;
using System.Collections;
[Version("$Id: PartitionAsForest.cs,v 1.4 2001/10/28 19:50:09 brpreiss Exp $"), Copyright("Copyright (c) 2001 by Bruno R. Preiss, P.Eng.")]
public class PartitionAsForest : AbstractSet, Partition, Set, SearchableContainer, Container, IComparable, IEnumerable
{
public PartitionAsForest(int n) : base(n)
{
this.array = new PartitionTree[base.universeSize];
for (int num1 = 0; num1 < base.universeSize; num1++)
{
this.array[num1] = new PartitionTree(this, num1);
}
base.count = base.universeSize;
}
public override void Accept(Visitor visitor)
{
for (int num1 = 0; num1 < base.universeSize; num1++)
{
visitor.Visit(this.array[num1]);
if (visitor.IsDone)
{
return;
}
}
}
protected virtual void CheckArguments(PartitionTree s, PartitionTree t)
{
if ((!this.IsMember(s) || (s.parent != null)) || ((!this.IsMember(t) || (t.parent != null)) || (s == t)))
{
throw new ArgumentException("incompatible sets");
}
}
public override int CompareTo(object arg)
{
throw new MethodNotImplementedException();
}
public Set Difference(Set set)
{
throw new InvalidOperationException();
}
public bool Equals(Set set)
{
throw new MethodNotImplementedException();
}
public override ComparableObject Find(ComparableObject obj)
{
return (ComparableObject) this.Find((int) obj);
}
public virtual Set Find(int item)
{
PartitionTree tree1 = this.array[item];
while (tree1.parent != null)
{
tree1 = tree1.parent;
}
return tree1;
}
public override IEnumerator GetEnumerator()
{
throw new MethodNotImplementedException();
}
public override void Insert(int i)
{
throw new InvalidOperationException();
}
public Set Intersection(Set set)
{
throw new InvalidOperationException();
}
public override bool IsMember(ComparableObject obj)
{
PartitionTree tree1 = (PartitionTree) obj;
return tree1.IsMemberOf(this);
}
public override bool IsMember(int i)
{
throw new InvalidOperationException();
}
public bool IsSubset(Set set)
{
throw new MethodNotImplementedException();
}
public virtual void Join(Set s, Set t)
{
PartitionTree tree1 = (PartitionTree) s;
PartitionTree tree2 = (PartitionTree) t;
this.CheckArguments(tree1, tree2);
tree2.parent = tree1;
base.count--;
}
public static void Main()
{
PartitionAsForest.TestPartition(new PartitionAsForest(5));
}
public override void Purge()
{
for (int num1 = 0; num1 < base.universeSize; num1++)
{
this.array[num1].Purge();
}
}
public static void TestPartition(Partition p)
{
Opus6.Console.WriteLine(p);
Set set1 = p.Find(2);
Set set2 = p.Find(4);
p.Join(set1, set2);
Set set3 = p.Find(3);
Set set4 = p.Find(4);
p.Join(set3, set4);
Opus6.Console.WriteLine(p);
}
public Set Union(Set set)
{
throw new InvalidOperationException();
}
public override void Withdraw(int i)
{
throw new InvalidOperationException();
}
protected PartitionTree[] array;
protected class PartitionTree : AbstractSet, Set, SearchableContainer, Tree, Container, IComparable, IEnumerable
{
public PartitionTree(PartitionAsForest partition, int item) : base(partition.UniverseSize)
{
this.partition = partition;
this.item = item;
this.parent = null;
this.rank = 0;
base.count = 1;
}
public virtual void BreadthFirstTraversal(Visitor visitor)
{
throw new MethodNotImplementedException();
}
public override int CompareTo(object obj)
{
PartitionAsForest.PartitionTree tree1 = (PartitionAsForest.PartitionTree) obj;
return (this.item - tree1.item);
}
public virtual void DepthFirstTraversal(PrePostVisitor visitor)
{
throw new MethodNotImplementedException();
}
public virtual Set Difference(Set set)
{
throw new MethodNotImplementedException();
}
public virtual bool Equals(Set set)
{
throw new MethodNotImplementedException();
}
public override IEnumerator GetEnumerator()
{
throw new MethodNotImplementedException();
}
public override int GetHashCode()
{
return this.item;
}
public virtual Tree GetSubtree(int i)
{
throw new MethodNotImplementedException();
}
public override void Insert(int i)
{
throw new InvalidOperationException();
}
public virtual Set Intersection(Set set)
{
throw new MethodNotImplementedException();
}
public override bool IsMember(int i)
{
throw new MethodNotImplementedException();
}
internal virtual bool IsMemberOf(PartitionAsForest partition)
{
return (this.partition == partition);
}
public virtual bool IsSubset(Set set)
{
throw new MethodNotImplementedException();
}
public override void Purge()
{
this.parent = null;
this.rank = 0;
base.count = 1;
}
public override string ToString()
{
string text1 = "PartitionTree {" + this.item;
if (this.parent != null)
{
text1 = text1 + ", " + this.parent;
}
return (text1 + "}");
}
public virtual Set Union(Set set)
{
throw new MethodNotImplementedException();
}
public override void Withdraw(int i)
{
throw new InvalidOperationException();
}
public virtual int Count
{
get
{
return base.count;
}
set
{
base.count = value;
}
}
public virtual int Degree
{
get
{
throw new MethodNotImplementedException();
}
}
public virtual int Height
{
get
{
return this.rank;
}
}
public override bool IsEmpty
{
get
{
return false;
}
}
public virtual bool IsLeaf
{
get
{
throw new MethodNotImplementedException();
}
}
public virtual object Key
{
get
{
return this.item;
}
}
internal int item;
internal PartitionAsForest.PartitionTree parent;
protected PartitionAsForest partition;
internal int rank;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -