public void buildTrie() { trie = new Trie(); StreamReader sr = new StreamReader(memStream); theMemCounter = new PerformanceCounter("Memory", "Available MBytes"); bool hasMem = true; int counter = 1; string line = sr.ReadLine(); while (line != null && hasMem) { if (counter % 1000 == 0) { hasMem = theMemCounter.NextValue() > 20; Debug.Print(theMemCounter.NextValue().ToString() + " " + line); } trie.AddWord(line); line = sr.ReadLine(); counter++; Debug.Print(line); } memoryCache.Set("trie", trie, null); }
public string BuildTrie() { data = new Trie(); StreamReader sr = new StreamReader(memStream); memCounter = new PerformanceCounter("Memory", "Available MBytes"); bool hasMemory = true; int i = 0; string nextWord = ""; while (hasMemory) //while (i < 10000) { i++; nextWord = sr.ReadLine().ToLower(); data.AddWord(nextWord); if (i % 1000 == 0) { hasMemory = memCounter.NextValue() > 20; } } memCache.Set("data", data, null); return("last word: " + nextWord + ", memory left: " + memCounter.NextValue() + ", i: " + i); }
public string BuildTrie() { testTrie = new Trie(); //var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).ToString() + "\\wikiedit2.txt"; var path = System.IO.Path.GetTempPath() + "\\wikiedit2.txt"; System.IO.StreamReader file = new System.IO.StreamReader(path); //var lines = File.ReadAllLines(path); int count = 0; string line; while ((line = file.ReadLine()) != null) { if (count % 1000 == 0) { System.Diagnostics.Debug.WriteLine(line + " " + count + " " + this.theMemCounter.NextValue()); if (this.theMemCounter.NextValue() < 75) { break; } } try { testTrie.AddWord(line.ToLower()); count++; } catch (OutOfMemoryException ex) { return("last word: " + line.ToLower()); break; } } System.Diagnostics.Debug.WriteLine(line + " " + count); return("Success, Trie Built with path " + path + " and " + count + " words, last word " + line + " ram = " + this.theMemCounter.NextValue()); }