Guest User

Untitled

a guest
Apr 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. DiskMap<string> testMap = new DiskMap<string>("C:path");
  4.  
  5. for (int i = 0; i < 100000; i++)
  6. {
  7. testMap.Add("a" + i, "aa" + i);
  8. }
  9. }
  10.  
  11. public class DiskMap<TValue>
  12. {
  13. private string path;
  14. private int loadedDictionaryId;
  15. private Dictionary<string, TValue> loadedDictionary;
  16.  
  17. public DiskMap(string path)
  18. {
  19. this.limit = limit;
  20. this.path = path;
  21. File.WriteAllText(path + "\0.txt", "{");
  22. File.WriteAllText(path + "\1.txt", "{");
  23.  
  24. loadedDictionary = new Dictionary<string, TValue>();
  25. loadedDictionaryId = 0;
  26. }
  27.  
  28. public void Add(string key, TValue value)
  29. {
  30. int dictionaryId = GetId(key); // returns 0 or 1 in this example
  31. if (dictionaryId == loadedDictId)
  32. {
  33. loadedDict.Add(key, value);
  34. }
  35. else
  36. {
  37. string filePath = this.path + "\" + dictionaryId + ".txt";
  38. File.AppendAllText(filePath, JsonConvert.SerializeObject(key) + ":" + JsonConvert.SerializeObject(value) + ","); // It breaks at this line
  39. }
  40. }
  41. }
Add Comment
Please, Sign In to add comment