private void SplitIfTooLarge(XFastTrie <RBTree> .LeafNode separator) { if (separator.value.Count <= upperLimit) { return; } RBTree newTree = SplitNew(ref separator.value); cluster.Add(((RBUIntNode)newTree.LastNode()).key, newTree); }
public override KeyValuePair <uint, T>?Lower(uint key) { XFastTrie <RBTree> .LeafNode separator = Separator(key); if (separator == null) { return(null); } RBUIntNode predNode = RBUtils.LowerNode(separator.value, key); if (predNode == null) { if (separator == cluster.leafList) { return(null); } RBUIntNode highestLeft = (RBUIntNode)((XFastTrie <RBTree> .LeafNode)separator.left).value.LastNode(); return(new KeyValuePair <uint, T>(highestLeft.key, highestLeft.value)); } return(new KeyValuePair <uint, T>(predNode.key, predNode.value)); }
public override KeyValuePair <uint, T>?Higher(uint key) { XFastTrie <RBTree> .LeafNode higherNode = cluster.HigherNode(key); if (higherNode == null) { return(null); } XFastTrie <RBTree> .LeafNode left = (XFastTrie <RBTree> .LeafNode)higherNode.left; if (((XFastTrie <RBTree> .LeafNode)higherNode.left).key == key) { var succNode = (RBUIntNode)higherNode.value.FirstNode(); return(new KeyValuePair <uint, T>(succNode.key, succNode.value)); } RBUIntNode rbHigher = RBUtils.HigherNode(higherNode.value, key); if (rbHigher == null) { return(null); } return(new KeyValuePair <uint, T>(rbHigher.key, rbHigher.value)); }
private XFastTrie <RBTree> .LeafNode Separator(uint key) { if (cluster.leafList == null) { return(null); } // special check for maxval if (((XFastTrie <RBTree> .LeafNode)cluster.leafList.left).key == key) { return((XFastTrie <RBTree> .LeafNode)cluster.leafList.left); } var succ = cluster.HigherNode(key); if (succ == null) { return(null); } XFastTrie <RBTree> .LeafNode left = (XFastTrie <RBTree> .LeafNode)succ.left; if (left.key == key) { return(left); } return(succ); }
public static MeasureResults MeasureSeriesDelete(StructureType types, int start, int count, int step) { // validate types types &= DictionaryMask; // initialize result sets Tuple <long, long>[] rbTreeResults = new Tuple <long, long> [count]; Tuple <long, long>[] vebResults = new Tuple <long, long> [count]; Tuple <long, long>[] dphResults = new Tuple <long, long> [count]; Tuple <long, long>[] xfastDPHResults = new Tuple <long, long> [count]; Tuple <long, long>[] yfastDPHResults = new Tuple <long, long> [count]; Tuple <long, long>[] xfastStandardResults = new Tuple <long, long> [count]; Tuple <long, long>[] yfastStandardResults = new Tuple <long, long> [count]; // calc the ranges int maxval = 2 * (int)BitHacks.RoundToPower((uint)(start + (count - 1) * step)); int width = BitHacks.Power2MSB((uint)maxval); // run benchmarks int i = 0; foreach (var size in Enumerable.Range(0, count).Select(x => start + (x * step))) { var itemSet = GenerateRandomSet(size, maxval).ToArray(); var delSet = itemSet.ToArray(); Shuffle(delSet); if (types.HasFlag(StructureType.RBTree)) { var dict = new FromMono.SortedDictionary <uint, uint>(); Fill(delSet, delSet, dict); rbTreeResults[i] = Tuple.Create((long)size, MeasureDelete(delSet, dict)); } if (types.HasFlag(StructureType.VEB)) { var dict = new VEBTree <uint>(width); Fill(delSet, delSet, dict); vebResults[i] = Tuple.Create((long)size, MeasureDelete(delSet, dict)); } if (types.HasFlag(StructureType.DPH)) { var dict = new HashTable <uint>(); Fill(delSet, delSet, dict); dphResults[i] = Tuple.Create((long)size, MeasureDelete(delSet, dict)); } if (types.HasFlag(StructureType.XTrieDPH)) { var dict = new XFastTrie <uint>(width); Fill(delSet, delSet, dict); xfastDPHResults[i] = Tuple.Create((long)size, MeasureDelete(delSet, dict)); } if (types.HasFlag(StructureType.YTrieDPH)) { var dict = new YFastTrie <uint>(width); Fill(delSet, delSet, dict); yfastDPHResults[i] = Tuple.Create((long)size, MeasureDelete(delSet, dict)); } if (types.HasFlag(StructureType.XTrieStandard)) { var dict = XFastTrie <uint> .FromDictionary <Dictionary <uint, XFastNode> >(width); Fill(delSet, delSet, dict); xfastStandardResults[i] = Tuple.Create((long)size, MeasureDelete(delSet, dict)); } if (types.HasFlag(StructureType.YTrieStandard)) { var dict = YFastTrie <uint> .FromDictionary <Dictionary <uint, XFastNode> >(width); Fill(delSet, delSet, dict); yfastStandardResults[i] = Tuple.Create((long)size, MeasureDelete(delSet, dict)); } i++; } // dump the results MeasureResults results = new MeasureResults(types, maxval); results.SetResults(StructureType.RBTree, rbTreeResults); results.SetResults(StructureType.VEB, vebResults); results.SetResults(StructureType.DPH, dphResults); results.SetResults(StructureType.XTrieDPH, xfastDPHResults); results.SetResults(StructureType.YTrieDPH, yfastDPHResults); results.SetResults(StructureType.XTrieStandard, xfastStandardResults); results.SetResults(StructureType.YTrieStandard, yfastStandardResults); return(results); }
public static MeasureResults MeasureSeriesSearch(StructureType types, int start, int count, int step, int control) { // validate types types &= SortedDictionaryMask; // initialize result sets Tuple <long, long>[] rbTreeResults = new Tuple <long, long> [count]; Tuple <long, long>[] vebResults = new Tuple <long, long> [count]; Tuple <long, long>[] dphResults = new Tuple <long, long> [count]; Tuple <long, long>[] xfastDPHResults = new Tuple <long, long> [count]; Tuple <long, long>[] yfastDPHResults = new Tuple <long, long> [count]; Tuple <long, long>[] xfastStandardResults = new Tuple <long, long> [count]; Tuple <long, long>[] yfastStandardResults = new Tuple <long, long> [count]; // calc the ranges int maxval = 2 * Math.Max((int)BitHacks.RoundToPower((uint)(start + (count - 1) * step)), control); int width = BitHacks.Power2MSB((uint)maxval); int positive = (int)(0.9 * control); int negative = control - positive; // run benchmarks int i = 0; foreach (var size in Enumerable.Range(0, count).Select(x => start + (x * step))) { uint[] searchSet = new uint[control]; HashSet <uint> itemSet = GenerateRandomSet(size, maxval); uint[] itemArray = itemSet.ToArray(); int j = 0; for (; j < positive; j++) { searchSet[j] = itemArray[random.Next(itemArray.Length)]; } while (j < searchSet.Length) { uint next = (uint)random.Next(maxval); if (!itemSet.Contains(next)) { searchSet[j] = next; j++; } } if (types.HasFlag(StructureType.RBTree)) { var dict = new FromMono.SortedDictionary <uint, uint>(); Fill(itemArray, itemArray, dict); rbTreeResults[i] = Tuple.Create((long)size, MeasureSearch(searchSet, dict)); } if (types.HasFlag(StructureType.VEB)) { var dict = new VEBTree <uint>(width); Fill(itemArray, itemArray, dict); vebResults[i] = Tuple.Create((long)size, MeasureSearch(searchSet, dict)); } if (types.HasFlag(StructureType.DPH)) { var dict = new HashTable <uint>(); Fill(itemArray, itemArray, dict); dphResults[i] = Tuple.Create((long)size, MeasureSearch(searchSet, dict)); } if (types.HasFlag(StructureType.XTrieDPH)) { var dict = new XFastTrie <uint>(width); Fill(itemArray, itemArray, dict); xfastDPHResults[i] = Tuple.Create((long)size, MeasureSearch(searchSet, dict)); } if (types.HasFlag(StructureType.YTrieDPH)) { var dict = new YFastTrie <uint>(width); Fill(itemArray, itemArray, dict); yfastDPHResults[i] = Tuple.Create((long)size, MeasureSearch(searchSet, dict)); } if (types.HasFlag(StructureType.XTrieStandard)) { var dict = XFastTrie <uint> .FromDictionary <Dictionary <uint, XFastNode> >(width); Fill(itemArray, itemArray, dict); xfastStandardResults[i] = Tuple.Create((long)size, MeasureSearch(searchSet, dict)); } if (types.HasFlag(StructureType.YTrieStandard)) { var dict = YFastTrie <uint> .FromDictionary <Dictionary <uint, XFastNode> >(width); Fill(itemArray, itemArray, dict); yfastStandardResults[i] = Tuple.Create((long)size, MeasureSearch(searchSet, dict)); } i++; } // dump the results MeasureResults results = new MeasureResults(types, maxval); results.SetResults(StructureType.RBTree, rbTreeResults); results.SetResults(StructureType.VEB, vebResults); results.SetResults(StructureType.DPH, dphResults); results.SetResults(StructureType.XTrieDPH, xfastDPHResults); results.SetResults(StructureType.YTrieDPH, yfastDPHResults); results.SetResults(StructureType.XTrieStandard, xfastStandardResults); results.SetResults(StructureType.YTrieStandard, yfastStandardResults); return(results); }
public static YFastTrie <T> FromDictionary <TDict>(int width) where TDict : IDictionary <uint, XFastNode>, new() { return(new YFastTrie <T>(XFastTrie <RBTree> .FromDictionary <TDict>(width))); }
public override void Clear() { count = 0; version = 0; cluster = new XFastTrie <RBTree>(); }
private YFastTrie(XFastTrie <RBTree> newTree) { cluster = newTree; lowerLimit = (cluster.width / 2); upperLimit = (cluster.width * 2); }