本文整理汇总了C#中ST.Get方法的典型用法代码示例。如果您正苦于以下问题:C# ST.Get方法的具体用法?C# ST.Get怎么用?C# ST.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ST
的用法示例。
在下文中一共展示了ST.Get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SymbolGraph
private readonly ST<string, Integer> _st; // string -> index
#endregion Fields
#region Constructors
/// <summary>
/// Initializes a graph from a file using the specified delimiter.
/// Each line in the file contains
/// the name of a vertex, followed by a list of the names
/// of the vertices adjacent to that vertex, separated by the delimiter.
/// </summary>
/// <param name="lines">array of string lines</param>
/// <param name="delimiter">delimiter the delimiter between fields</param>
public SymbolGraph(IList<string> lines, char delimiter)
{
_st = new ST<string, Integer>();
// First pass builds the index by reading strings to associate
// distinct strings with an index
// while (in.hasNextLine()) {
foreach (var line in lines)
{
var a = line.Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries);
foreach (var word in a)
{
if (!_st.Contains(word))
_st.Put(word, _st.Size());
}
}
Console.WriteLine("Done reading");
// inverted index to get string keys in an aray
_keys = new string[_st.Size()];
foreach (var name in _st.Keys())
{
_keys[_st.Get(name)] = name;
}
// second pass builds the graph by connecting first vertex on each
// line to all others
G = new Graph(_st.Size());
foreach (var line in lines)
{
var a = line.Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries);
int v = _st.Get(a[0]);
for (var i = 1; i < a.Length; i++)
{
int w = _st.Get(a[i]);
G.AddEdge(v, w);
}
}
}
示例2: Run
public void Run()
{
Console.WriteLine("Choose file:"); // Prompt
Console.WriteLine("1 - tinyST.txt"); // Prompt
Console.WriteLine("or quit"); // Prompt
var fileNumber = Console.ReadLine();
var fieName = string.Empty;
switch (fileNumber)
{
case "1":
fieName = "tinyST.txt";
break;
case "quit":
return;
default:
return;
}
var @in = new In($"Files\\Searching\\{fieName}");
var keyValues = @in.ReadAllLines();
//var list = words.Select(word => new StringComparable(word)).ToList();
//var listComparable = list.Cast<IComparable>().ToList();
//var arrayComparable = list.Cast<IComparable>().ToArray();
//var listStrings = words.ToList();
var st = new ST<string,string>();
foreach (var keyValue in keyValues)
{
var splittedKeyValue = keyValue.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
var key = splittedKeyValue[0];
var value = splittedKeyValue[1];
st.Put(key,value);
}
// print results
foreach (var item in st.Keys())
{
Console.WriteLine(st.Get(item));
}
Console.WriteLine(st.Max());
Console.WriteLine(st.Min());
Console.ReadLine();
}