Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- DiskMap<string> testMap = new DiskMap<string>("C:path");
- for (int i = 0; i < 100000; i++)
- {
- testMap.Add("a" + i, "aa" + i);
- }
- }
- public class DiskMap<TValue>
- {
- private string path;
- private int loadedDictionaryId;
- private Dictionary<string, TValue> loadedDictionary;
- public DiskMap(string path)
- {
- this.limit = limit;
- this.path = path;
- File.WriteAllText(path + "\0.txt", "{");
- File.WriteAllText(path + "\1.txt", "{");
- loadedDictionary = new Dictionary<string, TValue>();
- loadedDictionaryId = 0;
- }
- public void Add(string key, TValue value)
- {
- int dictionaryId = GetId(key); // returns 0 or 1 in this example
- if (dictionaryId == loadedDictId)
- {
- loadedDict.Add(key, value);
- }
- else
- {
- string filePath = this.path + "\" + dictionaryId + ".txt";
- File.AppendAllText(filePath, JsonConvert.SerializeObject(key) + ":" + JsonConvert.SerializeObject(value) + ","); // It breaks at this line
- }
- }
- }
Add Comment
Please, Sign In to add comment