本文整理汇总了C#中System.Collections.Set类的典型用法代码示例。如果您正苦于以下问题:C# Set类的具体用法?C# Set怎么用?C# Set使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Set类属于System.Collections命名空间,在下文中一共展示了Set类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SynchronizedSet
/// <summary>
/// Constructs a thread-safe <c>Set</c> wrapper.
/// </summary>
/// <param name="basisSet">The <c>Set</c> object that this object will wrap.</param>
public SynchronizedSet(Set basisSet)
{
_basisSet = basisSet;
_syncRoot = basisSet.SyncRoot;
if(_syncRoot == null)
throw new NullReferenceException("The Set you specified returned a null SyncRoot.");
}
示例2: Union
/// <summary>
/// Performs a "union" of the two sets, where all the elements
/// in both sets are present. That is, the element is included if it is in either <c>a</c> or <c>b</c>.
/// Neither this set nor the input set are modified during the operation. The return value
/// is a <c>Clone()</c> of this set with the extra elements added in.
/// </summary>
/// <param name="a">A collection of elements.</param>
/// <returns>A new <c>Set</c> containing the union of this <c>Set</c> with the specified collection.
/// Neither of the input objects is modified by the union.</returns>
public Set Union(Set a)
{
Set resultSet = (Set)this.Clone();
if(a != null)
resultSet.AddAll(a);
return resultSet;
}
示例3: Refine
public BinaryDecisionTree Refine(string prop, Set<int> enabledStates)
{
// dont refine already added property
if (this.property.Equals(prop))
return this;
if (states.IsEmpty)
return this;
Set<int> s1 = states.Intersect(enabledStates);
Set<int> s2 = states.Difference(enabledStates);
if (this.trueEdge != null) this.trueEdge.Refine(prop,s1);
if (this.falseEdge != null) this.falseEdge.Refine(prop,s2);
if (this.trueEdge == null && this.falseEdge == null)
{
//if (!s1.IsEmpty)
//{
this.trueEdge = new BinaryDecisionTree(prop, null, null,this.maxValue,this.minValue, s1);
//}
//else this.trueEdge = null;
//if (!s2.IsEmpty)
//{
this.falseEdge = new BinaryDecisionTree(prop, null, null,this.maxValue,this.minValue, s2);
//}
//else this.falseEdge = null;
}
return this;
}
示例4: CometServer
public CometServer()
{
_clients = new Dictionary<string, CometClient>();
_pathIndex = new Dictionary<string, List<CometClient>>();
_usernameIndex = new Dictionary<string, List<CometClient>>();
_requestPaths = new Set<string>();
}
示例5: getEdgesBetween
/// <summary>
/// Returns all Edges that connect the two nodes (which are assumed to be different).
/// </summary>
/// <param name="node0"></param>
/// <param name="node1"></param>
/// <returns></returns>
public static IList getEdgesBetween(Node node0, Node node1)
{
IList edges0 = DirectedEdge.ToEdges(node0.OutEdges.Edges);
Set<DirectedEdge> commonEdges = new Set<DirectedEdge>(edges0.Cast<DirectedEdge>());
IList edges1 = DirectedEdge.ToEdges(node1.OutEdges.Edges);
commonEdges.RemoveMany(edges1.Cast<DirectedEdge>());
return new ArrayList(commonEdges);
}
示例6: CreateSet
/// <summary>Create the Set just once</summary>
private static void CreateSet()
{
lock(typeof(MessageSequencer))
{
if (msgs != null)
return;
msgs = new Set<int>(s_seqMessages);
}
}
示例7: BinaryDecisionTree
public BinaryDecisionTree(string prop, BinaryDecisionTree t, BinaryDecisionTree f, double maxv, double minv, Set<int> setStates)
{
this.property = prop;
this.trueEdge = t;
this.falseEdge = f;
this.maxValue = maxv;
this.minValue = minv;
this.states = setStates;
}
示例8: UpdateFront
void UpdateFront() {
var newFrontEdges = new Set<CdtEdge>();
foreach (var t in addedTriangles)
foreach (var e in t.Edges)
if (e.CwTriangle == null || e.CcwTriangle == null)
newFrontEdges.Insert(e);
foreach (var e in newFrontEdges)
AddEdgeToFront(e);
}
示例9: Main
static void Main(string[] args)
{
var stackOfValues = new Stack<string>();
GetInitialValuesFromArgs(args, ref stackOfValues);
var demoSet1 = new Set<string>(stackOfValues.ToArray());
Console.WriteLine(demoSet1.ToString());
var demoSet3 = new SortedSet(stackOfValues.ToArray());
Console.WriteLine(demoSet3.ToString());
Console.ReadKey();
}
示例10: TestSetDifference
public void TestSetDifference(Set<string> setFirst, Set<string> setSecond, Set<string> resultSet)
{
setFirst.Difference(setSecond);
var iteratorFirst = setFirst.GetEnumerator();
var resultIterator = resultSet.GetEnumerator();
while (iteratorFirst.MoveNext() && resultIterator.MoveNext())
{
Assert.AreEqual(iteratorFirst.Current, resultIterator.Current);
}
}
示例11: NumberOfActiveNodesIsUnderThreshold
internal static bool NumberOfActiveNodesIsUnderThreshold(List<Edge> inParentEdges, List<Edge> outParentEdges, int threshold) {
var usedNodeSet = new Set<Node>();
foreach (var edge in inParentEdges)
if(SetOfActiveNodesIsLargerThanThreshold((Cluster)edge.Target, edge.Source, usedNodeSet, threshold))
return false;
foreach (var edge in outParentEdges)
if(SetOfActiveNodesIsLargerThanThreshold((Cluster)edge.Source, edge.Target, usedNodeSet, threshold))
return false;
return true;
}
示例12: IsSimple
/// <summary>
/// A MultiPoint is simple if it has no repeated points.
/// </summary>
public bool IsSimple(IMultiPoint mp)
{
if (mp.IsEmpty)
return true;
Set<ICoordinate> points = new Set<ICoordinate>();
for (int i = 0; i < mp.NumGeometries; i++)
{
IPoint pt = (IPoint) mp.GetGeometryN(i);
ICoordinate p = pt.Coordinate;
if (points.Contains(p))
return false;
points.Add(p);
}
return true;
}
示例13: SelectAction
/// <summary>
/// Select an action that is enabled in the current state
/// and whose action symbol is in the set <paramref name="actionSymbols"/>.
/// Use coverage points and reward policy.
/// </summary>
/// <param name="actionSymbols">set of candidate action symbols</param>
/// <returns>the chosen action or null if no choice is possible</returns>
public override Action SelectAction(Set<Symbol> actionSymbols)
{
if (actionSymbols == null)
throw new ArgumentNullException("actionSymbols");
if (actionSymbols.IsEmpty)
return null;
Sequence<Action> actions = new Sequence<Action>(this.GetEnabledActions(actionSymbols));
if (actions.IsEmpty)
return null;
Action a = ChooseAction(actions, this.CurrentState); //choose a tester action
//System.Console.WriteLine("Chosen Action " + a.ToString());
return a;
}
示例14: IntersectionTest
public void IntersectionTest()
{
Set<int> a = new Set<int>();
for(int i = 0; i < 16; i += 2)
a.Add(i);
Set<int> b = new Set<int>();
for(int i = 0; i < 16; i += 3)
b.Add(i);
Set<int> inter = a.Intersect(b);
Assert.AreEqual(3, inter.Count, "A01");
Assert.AreEqual(0, inter[0], "A02");
Assert.AreEqual(6, inter[1], "A03");
Assert.AreEqual(12, inter[2], "A04");
}
示例15: minusTest
public void minusTest()
{
Collections.Set<int> s = new Collections.Set<int>();
Collections.Set<int> s2 = new Collections.Set<int>();
int[] a = { 1, 5, 6, 9 };
int[] b = { 1, 4, 7, 9 };
for (int i = 0; i < a.Length; i++)
{
s += (a[i]);
s2 += (b[i]);
}
for (int i = 0; i < a.Length; i++)
{
s -= (a[i]);
s2 -= (b[i]);
}
Assert.AreEqual(0, s.size());
Assert.AreEqual(0, s2.size());
}