public void Add3Test() { var node = new CacheNode<int, int>(10, 10, 0, Comparer<int>.Default); node.AddNode(11, 11, 0, 0); node.AddNode(9, 9, 0, 0); int depth = 0; Assert.AreEqual(9, node.FindNode(9, 0, out depth)); Assert.AreEqual(1, depth); Assert.AreEqual(11, node.FindNode(11, 0, out depth)); Assert.AreEqual(1, depth); }
public void Add3Test() { var node = new CacheNode <int, int>(10, 10, 0, Comparer <int> .Default); node.AddNode(11, 11, 0, 0); node.AddNode(9, 9, 0, 0); int depth = 0; Assert.AreEqual(9, node.FindNode(9, 0, out depth)); Assert.AreEqual(1, depth); Assert.AreEqual(11, node.FindNode(11, 0, out depth)); Assert.AreEqual(1, depth); }
public void AddWithCollectingTest() { var node = new CacheNode<int, int>(10, 10, 0, Comparer<int>.Default); node.AddNode(11, 11, 0, 0); node.AddNode(9, 9, 0, 0); int depth; Assert.AreEqual(9, node.FindNode(9, 0, out depth)); Assert.AreEqual(1, depth);; Assert.AreEqual(11, node.FindNode(11, 0, out depth)); Assert.AreEqual(1, depth); GC.Collect(2,GCCollectionMode.Forced); GC.Collect(2, GCCollectionMode.Forced); GC.Collect(2, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); Assert.AreEqual(0, node.FindNode(9, 0, out depth)); Assert.AreEqual(0, node.FindNode(11, 0, out depth)); }
public void AddWithCollectingTest() { var node = new CacheNode <int, int>(10, 10, 0, Comparer <int> .Default); node.AddNode(11, 11, 0, 0); node.AddNode(9, 9, 0, 0); int depth; Assert.AreEqual(9, node.FindNode(9, 0, out depth)); Assert.AreEqual(1, depth);; Assert.AreEqual(11, node.FindNode(11, 0, out depth)); Assert.AreEqual(1, depth); GC.Collect(2, GCCollectionMode.Forced); GC.Collect(2, GCCollectionMode.Forced); GC.Collect(2, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); Assert.AreEqual(0, node.FindNode(9, 0, out depth)); Assert.AreEqual(0, node.FindNode(11, 0, out depth)); }
private CacheNode<int, double> BuildTree(int[] frequences, int maxFixedBranchDepth = 0) { var freqSum = frequences.Sum(); var root = new CacheNode<int, double>(0, (double)frequences[0] / freqSum, maxFixedBranchDepth, Comparer<int>.Default, probabilityCalc: k => (float)k); var frs = Enumerable.Range(0, frequences.Length).ToList(); var rnd = new Random(); for (int i = 1; i < frequences.Length; i++) { var t = rnd.Next(frs.Count - 1) + 1; var key = frs[t]; root.AddNode(key, (double)frequences[key] / freqSum, maxFixedBranchDepth, 0); frs.RemoveAt(t); } return root; }
private CacheNode <int, double> BuildTree(int[] frequences, int maxFixedBranchDepth = 0) { var freqSum = frequences.Sum(); var root = new CacheNode <int, double>(0, (double)frequences[0] / freqSum, maxFixedBranchDepth, Comparer <int> .Default, probabilityCalc: k => (float)k); var frs = Enumerable.Range(0, frequences.Length).ToList(); var rnd = new Random(); for (int i = 1; i < frequences.Length; i++) { var t = rnd.Next(frs.Count - 1) + 1; var key = frs[t]; root.AddNode(key, (double)frequences[key] / freqSum, maxFixedBranchDepth, 0); frs.RemoveAt(t); } return(root); }
public void DeepAddWithCollectingWithNonZeroFixedBranchLengthTest() { var node = new CacheNode <int, int>(10, 10, 1, Comparer <int> .Default); #region Prepare node.AddNode(8, 8, 1, 0); node.AddNode(7, 7, 1, 0); node.AddNode(9, 9, 1, 0); node.AddNode(12, 12, 1, 0); node.AddNode(11, 11, 1, 0); node.AddNode(13, 13, 1, 0); int depth = 0; Assert.AreEqual(7, node.FindNode(7, 0, out depth)); Assert.AreEqual(2, depth); depth = 0; Assert.AreEqual(8, node.FindNode(8, 0, out depth)); Assert.AreEqual(1, depth); depth = 0; Assert.AreEqual(9, node.FindNode(9, 0, out depth)); Assert.AreEqual(2, depth); depth = 0; Assert.AreEqual(10, node.FindNode(10, 0, out depth)); Assert.AreEqual(0, depth); depth = 0; Assert.AreEqual(11, node.FindNode(11, 0, out depth)); Assert.AreEqual(2, depth); depth = 0; Assert.AreEqual(12, node.FindNode(12, 0, out depth)); Assert.AreEqual(1, depth); depth = 0; Assert.AreEqual(13, node.FindNode(13, 0, out depth)); Assert.AreEqual(2, depth); depth = 0; #endregion #region First collection GC.Collect(2, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); Assert.AreEqual(0, node.FindNode(7, 0, out depth)); depth = 0; Assert.AreEqual(8, node.FindNode(8, 0, out depth)); Assert.AreEqual(1, depth); depth = 0; Assert.AreEqual(0, node.FindNode(9, 0, out depth)); depth = 0; Assert.AreEqual(10, node.FindNode(10, 0, out depth)); Assert.AreEqual(0, depth); depth = 0; Assert.AreEqual(0, node.FindNode(11, 0, out depth)); depth = 0; Assert.AreEqual(12, node.FindNode(12, 0, out depth)); Assert.AreEqual(1, depth); depth = 0; Assert.AreEqual(0, node.FindNode(13, 0, out depth)); #endregion GC.Collect(2, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); Assert.AreEqual(0, node.FindNode(7, 0, out depth)); Assert.AreEqual(8, node.FindNode(8, 0, out depth)); Assert.AreEqual(0, node.FindNode(9, 0, out depth)); depth = 0; Assert.AreEqual(10, node.FindNode(10, 0, out depth)); Assert.AreEqual(0, depth); Assert.AreEqual(0, node.FindNode(11, 0, out depth)); Assert.AreEqual(12, node.FindNode(12, 0, out depth)); Assert.AreEqual(0, node.FindNode(13, 0, out depth)); }
public void DeepAddWithCollectingWithNonZeroFixedBranchLengthTest() { var node = new CacheNode<int, int>(10, 10,1, Comparer<int>.Default); #region Prepare node.AddNode(8, 8, 1, 0); node.AddNode(7, 7, 1, 0); node.AddNode(9, 9, 1, 0); node.AddNode(12, 12, 1, 0); node.AddNode(11, 11, 1, 0); node.AddNode(13, 13, 1, 0); int depth = 0; Assert.AreEqual(7, node.FindNode(7, 0, out depth)); Assert.AreEqual(2, depth); depth = 0; Assert.AreEqual(8, node.FindNode(8, 0, out depth)); Assert.AreEqual(1, depth); depth = 0; Assert.AreEqual(9, node.FindNode(9, 0, out depth)); Assert.AreEqual(2, depth); depth = 0; Assert.AreEqual(10, node.FindNode(10, 0, out depth)); Assert.AreEqual(0, depth); depth = 0; Assert.AreEqual(11, node.FindNode(11, 0, out depth)); Assert.AreEqual(2, depth); depth = 0; Assert.AreEqual(12, node.FindNode(12, 0, out depth)); Assert.AreEqual(1, depth); depth = 0; Assert.AreEqual(13, node.FindNode(13, 0, out depth)); Assert.AreEqual(2, depth); depth = 0; #endregion #region First collection GC.Collect(2, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); Assert.AreEqual(0, node.FindNode(7, 0, out depth)); depth = 0; Assert.AreEqual(8, node.FindNode(8, 0, out depth)); Assert.AreEqual(1, depth); depth = 0; Assert.AreEqual(0, node.FindNode(9, 0, out depth)); depth = 0; Assert.AreEqual(10, node.FindNode(10, 0, out depth)); Assert.AreEqual(0, depth); depth = 0; Assert.AreEqual(0, node.FindNode(11, 0, out depth)); depth = 0; Assert.AreEqual(12, node.FindNode(12, 0, out depth)); Assert.AreEqual(1, depth); depth = 0; Assert.AreEqual(0, node.FindNode(13, 0, out depth)); #endregion GC.Collect(2, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); Assert.AreEqual(0, node.FindNode(7, 0, out depth)); Assert.AreEqual(8, node.FindNode(8, 0, out depth)); Assert.AreEqual(0, node.FindNode(9, 0, out depth)); depth = 0; Assert.AreEqual(10, node.FindNode(10, 0, out depth)); Assert.AreEqual(0, depth); Assert.AreEqual(0, node.FindNode(11, 0, out depth)); Assert.AreEqual(12, node.FindNode(12, 0, out depth)); Assert.AreEqual(0, node.FindNode(13, 0, out depth)); }