public void IterateAllItems_CheckConsistency() { string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize <Customer, string> backingFile = new BackingUnknownSize <Customer, string>(path, 100); Dictionary <Customer, string> dict = new Dictionary <Customer, string>(backingFile); Customer c1 = new Customer { Name = "Mikael" }; Customer c2 = new Customer { Name = "Svenson" }; Customer c3 = new Customer { Name = "Boss" }; dict.Add(c1, "Mikael"); dict.Add(c2, "Svenson"); dict.Add(c3, "Boss"); int count = 0; foreach (KeyValuePair <Customer, string> pair in dict) { Assert.AreEqual(pair.Key.Name, pair.Value); count++; } Assert.AreEqual(3, count); }
public void AddThreeItems_RemoveMiddleItem_CheckConsistency() { string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize<Customer, string> backingFile = new BackingUnknownSize<Customer, string>(path, 100); MMFDictionary<Customer, string> dict = new MMFDictionary<Customer, string>(path, 1000); Customer c1 = new Customer {Name = "Mikael"}; Customer c2 = new Customer {Name = "Svenson"}; Customer c3 = new Customer {Name = "Boss"}; dict.Add(c1, "test"); dict.Add(c2, "test2"); dict.Add(c3, "test3"); var result = dict.Remove(c2); Assert.IsTrue(result); result = dict.Remove(c2); Assert.IsFalse(result); dict.Add(c2, "test2"); result = dict.Remove(c2); Assert.IsTrue(result); var res2 = dict[c3]; Assert.AreEqual("test3", res2); }
private static void SingelThread_HashCompositeOnDisk() { Console.WriteLine("SingelThread_HashOnDisk"); string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize <int, Person> backingFile = new BackingUnknownSize <int, Person>(path, MaxCount); Dictionary <int, Person> dict = new Dictionary <int, Person>(backingFile); Stopwatch sw = Stopwatch.StartNew(); for (int i = 0; i < MaxCount; i++) { dict.Add(i, new Person() { Id = i, Name = "Name" + i }); Person p = null; if (!dict.TryGetValue(i, out p)) { throw new Exception(); } } sw.Stop(); Console.WriteLine(sw.Elapsed); }
public void AddThreeItems_RemoveMiddleItem_CheckConsistency() { string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize <Customer, string> backingFile = new BackingUnknownSize <Customer, string>(path, 100); Dictionary <Customer, string> dict = new Dictionary <Customer, string>(backingFile); Customer c1 = new Customer { Name = "Mikael" }; Customer c2 = new Customer { Name = "Svenson" }; Customer c3 = new Customer { Name = "Boss" }; dict.Add(c1, "test"); dict.Add(c2, "test2"); dict.Add(c3, "test3"); var result = dict.Remove(c2); Assert.IsTrue(result); result = dict.Remove(c2); Assert.IsFalse(result); dict.Add(c2, "test2"); result = dict.Remove(c2); Assert.IsTrue(result); var res2 = dict[c3]; Assert.AreEqual("test3", res2); }
public void Dispose() { if (_persistHandler != null) { _persistHandler.Dispose(); } _persistHandler = null; }
public void AddTwoValues_CheckConsistency() { string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize<Customer, string> backingFile = new BackingUnknownSize<Customer, string>(path, 100); MMFDictionary<Customer, string> dict = new MMFDictionary<Customer, string>(path,1000); Customer c1 = new Customer {Name = "Mikael"}; Customer c2 = new Customer {Name = "Svenson"}; dict.Add(c1, "test"); dict.Add(c2, "test2"); string result = dict[c1]; Assert.AreEqual("test", result); result = dict[c2]; Assert.AreEqual("test2", result); }
public void IterateAllItems_CheckConsistency2() { string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize <int, int> backingFile = new BackingUnknownSize <int, int>(path, 100); Dictionary <int, int> dict = new Dictionary <int, int>(backingFile); dict.Add(1, 1); dict.Add(2, 2); dict.Add(3, 3); int count = 0; foreach (KeyValuePair <int, int> pair in dict) { Assert.AreEqual(pair.Key, pair.Value); count++; } Assert.AreEqual(3, count); }
public void AddTwoValues_CheckConsistency() { string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize <Customer, string> backingFile = new BackingUnknownSize <Customer, string>(path, 100); Dictionary <Customer, string> dict = new Dictionary <Customer, string>(backingFile); Customer c1 = new Customer { Name = "Mikael" }; Customer c2 = new Customer { Name = "Svenson" }; dict.Add(c1, "test"); dict.Add(c2, "test2"); string result = dict[c1]; Assert.AreEqual("test", result); result = dict[c2]; Assert.AreEqual("test2", result); }
private static void Threaded_HashCompositeOnDisk() { Console.WriteLine("Threaded_HashOnDisk"); string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize <string, Person> backingFile = new BackingUnknownSize <string, Person>(path, MaxCount); Dictionary <string, Person> dict = new Dictionary <string, Person>(backingFile); Console.WriteLine("Queuing {0} items to Thread Pool", MaxCount); Console.WriteLine("Queue to Thread Pool 0"); System.Collections.Generic.List <WaitHandle> handles = new System.Collections.Generic.List <WaitHandle>(); Stopwatch sw = Stopwatch.StartNew(); for (int iItem = 1; iItem < 20; iItem++) { ManualResetEvent mre = new ManualResetEvent(false); handles.Add(mre); ThreadPool.QueueUserWorkItem(d => { for (int i = 0; i < MaxCount / 20; i++) { string key = Guid.NewGuid().ToString(); dict.Add(key, new Person { Id = i, Name = "Name" + i }); Person p = null; if (!dict.TryGetValue(key, out p)) { throw new Exception(); } } mre.Set(); }, null); } Console.WriteLine("Waiting for Thread Pool to drain"); WaitHandle.WaitAll(handles.ToArray()); sw.Stop(); Console.WriteLine("Thread Pool has been drained (Event fired)"); Console.WriteLine(sw.Elapsed); }
/* * private static void Threaded_HashInMemory() * { * Console.WriteLine("Threaded_HashInMemory"); * string path = AppDomain.CurrentDomain.BaseDirectory; * DictionaryPersist<string, string> backingFile = new DictionaryPersist<string, string>(path, MaxCount); * * Dictionary<string, string> dict = new Dictionary<string, string>(backingFile); * * Console.WriteLine("Queuing {0} items to Thread Pool", MaxCount); * Console.WriteLine("Queue to Thread Pool 0"); * System.Collections.Generic.List<WaitHandle> handles = new System.Collections.Generic.List<WaitHandle>(); * Stopwatch sw = Stopwatch.StartNew(); * for (int iItem = 1; iItem < 20; iItem++) * { * ManualResetEvent mre = new ManualResetEvent(false); * handles.Add(mre); * ThreadPool.QueueUserWorkItem(d => * { * for (int i = 0; i < MaxCount/20; i++) * { * string key = Guid.NewGuid().ToString(); * dict.Add(key, key); * if (string.IsNullOrEmpty(dict[key])) throw new Exception(); * } * mre.Set(); * }, null); * } * Console.WriteLine("Waiting for Thread Pool to drain"); * WaitHandle.WaitAll(handles.ToArray()); * sw.Stop(); * Console.WriteLine("Thread Pool has been drained (Event fired)"); * Console.WriteLine(sw.Elapsed); * } */ private static void SingelThread_HashOnDisk() { Console.WriteLine("SingelThread_HashOnDisk"); string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize <string, string> backingFile = new BackingUnknownSize <string, string>(path, MaxCount); Dictionary <string, string> dict = new Dictionary <string, string>(backingFile); Stopwatch sw = Stopwatch.StartNew(); for (int i = 0; i < MaxCount; i++) { string key = Guid.NewGuid().ToString(); dict.Add(key, key); if (string.IsNullOrEmpty(dict[key])) { throw new Exception(); } } sw.Stop(); Console.WriteLine(sw.Elapsed); }
public void AddValues_VerifyValues() { string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize <string, string> backingFile = new BackingUnknownSize <string, string>(path, 2000000); Dictionary <string, string> dict = new Dictionary <string, string>(backingFile); string prevKey = null; string prevVal = null; for (int i = 0; i < 500000; i++) { string key = Guid.NewGuid().ToString(); string value = Guid.NewGuid().ToString(); dict.Add(key, value); if (prevKey != null) { string result = dict[prevKey]; Assert.AreEqual(prevVal, result); } prevKey = key; prevVal = value; } }
public void AddValues_VerifyValues() { string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize<string, string> backingFile = new BackingUnknownSize<string, string>(path, 2000000); MMFDictionary<string, string> dict = new MMFDictionary<string, string>(path, 10000); string prevKey = null; string prevVal = null; for (int i = 0; i < 500000; i++) { string key = Guid.NewGuid().ToString(); string value = Guid.NewGuid().ToString(); dict.Add(key, value); if (prevKey != null) { string result = dict[prevKey]; Assert.AreEqual(prevVal, result); } prevKey = key; prevVal = value; } }
public void IterateAllItems_CheckConsistency2() { string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize<int, int> backingFile = new BackingUnknownSize<int, int>(path, 100); MMFDictionary<int, int> dict = new MMFDictionary<int, int>(path, 1000, PersistenceMode.TemporaryPersist); dict.Add(1, 1); dict.Add(2, 2); dict.Add(3, 3); int count = 0; foreach (KeyValuePair<int, int> pair in dict) { Assert.AreEqual(pair.Key, pair.Value); count++; } Assert.AreEqual(3, count); }
public void IterateAllItems_CheckConsistency() { string path = AppDomain.CurrentDomain.BaseDirectory; BackingUnknownSize<Customer, string> backingFile = new BackingUnknownSize<Customer, string>(path, 100); MMFDictionary<Customer, string> dict = new MMFDictionary<Customer, string>(path, 1000); Customer c1 = new Customer {Name = "Mikael"}; Customer c2 = new Customer {Name = "Svenson"}; Customer c3 = new Customer {Name = "Boss"}; dict.Add(c1, "Mikael"); dict.Add(c2, "Svenson"); dict.Add(c3, "Boss"); int count = 0; foreach (KeyValuePair<Customer, string> pair in dict) { Assert.AreEqual(pair.Key.Name, pair.Value); count++; } Assert.AreEqual(3, count); }
private Dictionary(BackingUnknownSize <TKey, TValue> persistHandler) { _persistHandler = persistHandler; }