public static double TimeInput(SearchTableOptions options, bool showItems = false) { var file = File.OpenRead("tale.txt"); Scanner scanner = new Scanner(new StreamReader(file)); ISearchTable <string, int> searchTable = CreateSearchTable <string, int>(options); StopWatch stopWatch = new StopWatch(); while (scanner.HasNext()) { var word = scanner.Read(); //if (word.Length <= 4) // continue; if (!searchTable.Contains(word)) { searchTable.Put(word, 1); } else { searchTable.Put(word, searchTable.Get(word) + 1); } } if (showItems) { foreach (var key in searchTable.Keys()) { searchTable.Get(key); } } double time = stopWatch.ElapsedTime; return(time); }
} //图 public SymbolDiGraph(string filename, string delim, SearchTableOptions options = SearchTableOptions.SequantialST) { st = SearchTableExamples.CreateSearchTable <string, int?>(options); Scanner scanner = new Scanner(new StreamReader(File.OpenRead(filename))); while (scanner.HasNextLine()) //构造索引 { string[] a = scanner.ReadLine().Split(delim); //为每个不同的字符串关联一个索引 for (int i = 0; i < a.Length; i++) { if (!st.Contains(a[i])) { st.Put(a[i], st.Size); } } } keys = new string[st.Size]; //用来获得顶点名反向索引 foreach (string name in st.Keys()) { keys[st.Get(name) ?? -1] = name; } G = new DiGraph(st.Size); scanner = new Scanner(new StreamReader(File.OpenRead(filename))); //第二遍 while (scanner.HasNextLine()) { string[] a = scanner.ReadLine().Split(delim); //将每一行的第一个顶点和该行的其他顶点相连 int v = st.Get(a[0]) ?? -1; for (int i = 1; i < a.Length; i++) { G.AddEdge(v, st.Get(a[i]) ?? -1); } } }