本文整理汇总了C#中HashSet.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.ToString方法的具体用法?C# HashSet.ToString怎么用?C# HashSet.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashSet
的用法示例。
在下文中一共展示了HashSet.ToString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetShortestPath
public List<Coordinate> GetShortestPath(Coordinate start, Coordinate goal)
{
HashSet<Coordinate> visited = new HashSet<Coordinate>();
Dictionary<Coordinate, Coordinate> parents = new Dictionary<Coordinate, Coordinate>();
Dictionary<Coordinate, double> gScore = new Dictionary<Coordinate, double>();
HeapPriorityQueue<Coordinate> fScoreQueue = new HeapPriorityQueue<Coordinate>(rows * cols);
parents[start] = start;
gScore.Add(start, 0);
fScoreQueue.Enqueue(start, gScore[start] + Heuristic(start, goal));
while (fScoreQueue.Count() != 0)
{
Coordinate current = fScoreQueue.Dequeue();
Console.Out.WriteLine("");
Console.Out.WriteLine("Current = " + current.ToString());
Console.Out.WriteLine("Visited = " + visited.ToString());
Console.Out.WriteLine("Parents = " + parents.ToString());
Console.Out.WriteLine("gScore = " + gScore.ToString());
Console.Out.WriteLine("fScoreQueue = " + fScoreQueue.ToString());
if (current == goal)
{
return ReconstructPath(parents, goal);
}
visited.Add(start);
foreach (Coordinate neighbor in board[current.row,current.col].GetNeighborCoordinates())
{
if (visited.Contains(neighbor)) continue;
double newGScore = gScore[current] + Distance(current, neighbor);
if (!fScoreQueue.Contains(neighbor))
{
parents[neighbor] = current;
gScore[neighbor] = newGScore;
fScoreQueue.Enqueue(neighbor, newGScore + Heuristic(neighbor, goal));
}
else if (newGScore < gScore[neighbor])
{
parents[neighbor] = current;
gScore[neighbor] = newGScore;
fScoreQueue.UpdatePriority(neighbor, newGScore + Heuristic(neighbor, goal));
}
}
}
return null;
}
示例2: TestToString
public void TestToString()
{
HashSet<Object> s = new HashSet<Object>();
s.Add(s);
String result = s.ToString();
Assert.IsTrue(result.IndexOf("(this") > -1, "should contain self ref");
}
示例3: addTagsToEntry
public void addTagsToEntry(long newEntryID, HashSet<string> tags)
{
Console.WriteLine("{0}, {1}", newEntryID, tags.ToString());
try
{
var connectionString = String.Format("Data Source={0};Version=3;", DB);
using (var conn = new SQLiteConnection(connectionString))
{
conn.Open();
using (var cmd = conn.CreateCommand())
{
foreach (var item in tags)
{
//cmd.CommandText = String.Format(@"INSERT INTO Entry_Tag (EntryID, TagID) VALUES ('{0}', (SELECT TagID FROM Tag WHERE Name = '{1}'))", newEntryID, item);
cmd.CommandText = @"INSERT INTO Entry_Tag (EntryID, TagID) VALUES (@NewEntryID, (SELECT TagID FROM Tag WHERE Name = @Item))";
SQLiteParameter pNewEntryID = new SQLiteParameter { ParameterName = "@NewEntryID", Value = newEntryID };
cmd.Parameters.Add(pNewEntryID);
SQLiteParameter pItem = new SQLiteParameter { ParameterName = "@Item", Value = item };
cmd.Parameters.Add(pItem);
cmd.CommandType = CommandType.Text;
tracer.PutSQLQuery(cmd, 17);
cmd.ExecuteNonQuery();
}
}
}
}
catch (System.IO.IOException exception)
{
Console.WriteLine(String.Format("{0}: {1}", exception.Source, exception.Message));
}
catch (System.Data.SQLite.SQLiteException exception)
{
Console.WriteLine(String.Format("{0}: {1}", exception.Source, exception.Message));
}
}
示例4: TestGetFieldNames
//.........这里部分代码省略.........
doc.Add(new TextField("text2", "test1", Field.Store.YES));
doc.Add(new Field("unindexed2", "test1", customType3));
doc.Add(new TextField("unstored2", "test1", Field.Store.NO));
writer.AddDocument(doc);
}
// new termvector fields
FieldType customType5 = new FieldType(TextField.TYPE_STORED);
customType5.StoreTermVectors = true;
FieldType customType6 = new FieldType(TextField.TYPE_STORED);
customType6.StoreTermVectors = true;
customType6.StoreTermVectorOffsets = true;
FieldType customType7 = new FieldType(TextField.TYPE_STORED);
customType7.StoreTermVectors = true;
customType7.StoreTermVectorPositions = true;
FieldType customType8 = new FieldType(TextField.TYPE_STORED);
customType8.StoreTermVectors = true;
customType8.StoreTermVectorOffsets = true;
customType8.StoreTermVectorPositions = true;
for (int i = 0; i < 5 * mergeFactor; i++)
{
doc = new Document();
doc.Add(new TextField("tvnot", "tvnot", Field.Store.YES));
doc.Add(new Field("termvector", "termvector", customType5));
doc.Add(new Field("tvoffset", "tvoffset", customType6));
doc.Add(new Field("tvposition", "tvposition", customType7));
doc.Add(new Field("tvpositionoffset", "tvpositionoffset", customType8));
writer.AddDocument(doc);
}
writer.Dispose();
// verify fields again
reader = DirectoryReader.Open(d);
fieldInfos = MultiFields.GetMergedFieldInfos(reader);
ICollection<string> allFieldNames = new HashSet<string>();
ICollection<string> indexedFieldNames = new HashSet<string>();
ICollection<string> notIndexedFieldNames = new HashSet<string>();
ICollection<string> tvFieldNames = new HashSet<string>();
foreach (FieldInfo fieldInfo in fieldInfos)
{
string name = fieldInfo.Name;
allFieldNames.Add(name);
if (fieldInfo.Indexed)
{
indexedFieldNames.Add(name);
}
else
{
notIndexedFieldNames.Add(name);
}
if (fieldInfo.HasVectors())
{
tvFieldNames.Add(name);
}
}
Assert.IsTrue(allFieldNames.Contains("keyword"));
Assert.IsTrue(allFieldNames.Contains("text"));
Assert.IsTrue(allFieldNames.Contains("unindexed"));
Assert.IsTrue(allFieldNames.Contains("unstored"));
Assert.IsTrue(allFieldNames.Contains("keyword2"));
Assert.IsTrue(allFieldNames.Contains("text2"));
Assert.IsTrue(allFieldNames.Contains("unindexed2"));
Assert.IsTrue(allFieldNames.Contains("unstored2"));
Assert.IsTrue(allFieldNames.Contains("tvnot"));
Assert.IsTrue(allFieldNames.Contains("termvector"));
Assert.IsTrue(allFieldNames.Contains("tvposition"));
Assert.IsTrue(allFieldNames.Contains("tvoffset"));
Assert.IsTrue(allFieldNames.Contains("tvpositionoffset"));
// verify that only indexed fields were returned
Assert.AreEqual(11, indexedFieldNames.Count); // 6 original + the 5 termvector fields
Assert.IsTrue(indexedFieldNames.Contains("keyword"));
Assert.IsTrue(indexedFieldNames.Contains("text"));
Assert.IsTrue(indexedFieldNames.Contains("unstored"));
Assert.IsTrue(indexedFieldNames.Contains("keyword2"));
Assert.IsTrue(indexedFieldNames.Contains("text2"));
Assert.IsTrue(indexedFieldNames.Contains("unstored2"));
Assert.IsTrue(indexedFieldNames.Contains("tvnot"));
Assert.IsTrue(indexedFieldNames.Contains("termvector"));
Assert.IsTrue(indexedFieldNames.Contains("tvposition"));
Assert.IsTrue(indexedFieldNames.Contains("tvoffset"));
Assert.IsTrue(indexedFieldNames.Contains("tvpositionoffset"));
// verify that only unindexed fields were returned
Assert.AreEqual(2, notIndexedFieldNames.Count); // the following fields
Assert.IsTrue(notIndexedFieldNames.Contains("unindexed"));
Assert.IsTrue(notIndexedFieldNames.Contains("unindexed2"));
// verify index term vector fields
Assert.AreEqual(4, tvFieldNames.Count, tvFieldNames.ToString()); // 4 field has term vector only
Assert.IsTrue(tvFieldNames.Contains("termvector"));
reader.Dispose();
d.Dispose();
}
示例5: lasso_finding_test
private bool lasso_finding_test(HashSet<Arc> g, HashSet<Arc> h, int init){
if(!Head.ContainsKey(g.ToString())){
HashSet<int> H=new HashSet<int>();
foreach (Arc arc_g in g)
{
if(arc_g.From==init){
H.Add(arc_g.To);
}
}
Head.Add(g.ToString(), H);
}
if(!Tail.ContainsKey(h.ToString())){
FiniteAutomaton fa=new FiniteAutomaton();
OneToOneTreeMap<int,FAState> st=new OneToOneTreeMap<int,FAState>();
foreach (Arc arc_h in h)
{
if(!st.containsKey(arc_h.From))
st.put(arc_h.From, fa.createState());
if(!st.containsKey(arc_h.To))
st.put(arc_h.To, fa.createState());
fa.addTransition(st.getValue(arc_h.From), st.getValue(arc_h.To), arc_h.Label?"1":"0");
}
SCC s=new SCC(fa);
HashSet<int> T=new HashSet<int>();
foreach (FAState state in s.getResult())
{
T.Add(st.getKey(state));
}
int TailSize=0;
HashSet<Arc> isolatedArcs=h;
while(TailSize!=T.Count){
TailSize = T.Count;
HashSet<Arc> isolatedArcsTemp=new HashSet<Arc>();
foreach (Arc arc in isolatedArcs)
{
if(!T.Contains(arc.To)){
isolatedArcsTemp.Add(arc);
}else{
T.Add(arc.From);
}
}
isolatedArcs=isolatedArcsTemp;
}
Tail.Add(h.ToString(), T);
}
HashSet<int> intersection = new HashSet<int>(Head[g.ToString()]);
//intersection.retainAll(Tail[h.ToString()]);
intersection.IntersectWith(Tail[h.ToString()]);
//if(debug){
// if(intersection.isEmpty()){
// //debug("g_graph:"+g+", Head: "+Head.get(g.ToString()));
// //debug("h_graph:"+h+", Tail: "+Tail.get(h.ToString()));
// }
//}
return intersection.Count > 0;
}
示例6: problem60
static string problem60()
{
List<int> primes = Prime(20000);
HashSet<Point> pairs = new HashSet<Point>();
for (int i = 0; i < primes.Count; i++ )
{
for ( int j = 1 + 1; j < primes.Count; j++ )
{
Point pair = new Point(primes[i], primes[j]);
if (IsPair(pair.X, pair.Y))
pairs.Add(pair);
}
}
for (int a = 0; a < primes.Count; a++ )
{
int aa = primes[a];
for (int b = a + 1; b < primes.Count; b++ )
{
int bb = primes[b];
if (!pairs.Contains(new Point(aa,bb)))
continue;
for (int c = b + 1; c < primes.Count; c++ )
{
int cc = primes[c];
if (!pairs.Contains(new Point(aa, cc)))
continue;
if (!pairs.Contains(new Point(bb, cc)))
continue;
for (int d = c + 1; d < primes.Count; d++)
{
int dd = primes[d];
if (!pairs.Contains(new Point(aa, dd)))
continue;
if (!pairs.Contains(new Point(bb, dd)))
continue;
if (!pairs.Contains(new Point(cc, dd)))
continue;
for (int e = d + 1; e < primes.Count;e++ )
{
int ee = primes[e];
if (!pairs.Contains(new Point(aa, ee)))
continue;
if (!pairs.Contains(new Point(bb, ee)))
continue;
if (!pairs.Contains(new Point(cc, ee)))
continue;
if (!pairs.Contains(new Point(dd, ee)))
continue;
Console.Write(aa.ToString() + " ");
Console.Write(bb.ToString() + " ");
Console.Write(cc.ToString() + " ");
Console.Write(dd.ToString() + " ");
Console.Write(ee.ToString() + "\n");
}
}
}
}
}
return pairs.ToString();
}
示例7: assertException
public void assertException(FaultException<cmisFaultType> actualException, HashSet<enumServiceException> expectedExceptions)
{
if (expectedExceptions == null || expectedExceptions.Count < 1)
{
return;
}
enumServiceException actualExceptionType = enumServiceException.runtime;
bool found = false;
if (actualException.Detail != null && actualException.Detail.Nodes != null)
{
foreach (XmlNode node in actualException.Detail.Nodes)
{
if (node != null && node.Name != null && node.Name.Equals("type") && node.InnerText != null)
{
try
{
actualExceptionType = (enumServiceException)Enum.Parse(typeof(enumServiceException), node.InnerText, true);
found = true;
}
catch (Exception)
{
}
}
}
}
if (!found || !expectedExceptions.Contains(actualExceptionType))
{
Assert.Fail("Received exception '" + actualExceptionType + "' is not in set of expected exceptions: " + expectedExceptions.ToString() + "'");
}
}