public TableItem(ISearchTable table, long prepareCheckpoint, long commitCheckpoint, int level) { Table = table; PrepareCheckpoint = prepareCheckpoint; CommitCheckpoint = commitCheckpoint; Level = level; }
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 SymbolGraph(string filename, string delim, SearchTableOptions options = SearchTableOptions.RedBlack) { 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 Graph(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); } } }
void FrequencyCounter() { ISearchTable <string, int> searchTable = null; var file = File.OpenRead("tale.txt"); Scanner scanner = new Scanner(new StreamReader(file)); Dictionary <string, int> dic = new Dictionary <string, int>(); StopWatch stopWatch = new StopWatch(); while (scanner.HasNext()) { var word = scanner.Read(); //if (word.Length <= 4) // continue; if (!dic.ContainsKey(word)) { dic.Add(word, 1); } else { dic[word]++; } } Console.WriteLine(stopWatch.ElapsedTime); var list = dic.Where((keyPair) => keyPair.Key.Length > 3).ToList(); list.Sort((v1, v2) => v2.Value.CompareTo(v1.Value)); Console.WriteLine(stopWatch.ElapsedTime); int i = 0; while (i++ < 10) { StdOut.Println(list[i]); } }
public static ISearchTable <Key, Value> CreateSearchTable <Key, Value>(SearchTableOptions options) where Key : IComparable <Key> { ISearchTable <Key, Value> table = options switch { SearchTableOptions.SequantialST => new SequantialSearchST <Key, Value>(), SearchTableOptions.BinarySearchST => new BinarySearchST <Key, Value>(), SearchTableOptions.BST => new BST <Key, Value>(), SearchTableOptions.RedBlack => new RedBlackBST <Key, Value>(), _ => throw new NotImplementedException(), }; return(table); }
public EnumerableTable(byte mergedPTableVersion, ISearchTable table, Func <string, ulong, ulong> upgradeHash, Func <IndexEntry, bool> existsAt, Func <IndexEntry, Tuple <string, bool> > readRecord) { _mergedPTableVersion = mergedPTableVersion; _ptable = table; _upgradeHash = upgradeHash; _existsAt = existsAt; _readRecord = readRecord; if (table.Version == PTableVersions.IndexV1 && mergedPTableVersion != PTableVersions.IndexV1) { _list = new List <IndexEntry>(); _enumerator = _list.GetEnumerator(); _ptableEnumerator = _ptable.IterateAllInOrder().GetEnumerator(); } else { _enumerator = _ptable.IterateAllInOrder().GetEnumerator(); } }
public TableItem(ISearchTable table, long prepareCheckpoint, long commitCheckpoint) { Table = table; PrepareCheckpoint = prepareCheckpoint; CommitCheckpoint = commitCheckpoint; }
public TableItem(ISearchTable table, long prepareCheckpoint, long commitCheckpoint) { Table = table; PrepareCheckpoint = prepareCheckpoint; CommitCheckpoint = commitCheckpoint; }