private void addChildrenWithStride(FibTreeNode to, FibTreeNode from, Dictionary <FibTreeNode, CompressData> compressData) { if (from.Label != null) { FibTreeLabel label = Labels.GetLabelByNextHop(from.Label.NextHop); if (label == null) { label = Labels.AddLabelForNextHop(from.Label.NextHop); } to.Label = label; } if (from.Children.Count == 0) { return; } List <FibTreeNode> childrenToAdd = from.GetChildrenAtLevel(compressData[from].OptimalStride); foreach (FibTreeNode childToAdd in childrenToAdd) { FibTreeNode newNode = to.AddChild(getConcatenatedEdgeLabelBetweenNodes(from, childToAdd)); addChildrenWithStride(newNode, childToAdd, compressData); } }
private void calculateCompressData(FibTreeNode node, Dictionary <FibTreeNode, CompressData> compressData) { if (node.Children.Count == 0) { compressData.Add(node, new CompressData() { Node = node, Depth = 0, OptimalStride = 0, PointerCount = 0 }); } else { foreach (FibTreeNode child in node.Children.Values) { calculateCompressData(child, compressData); } CompressData nodeCompressData = new CompressData() { Node = node, Depth = node.GetDepth(), OptimalStride = -1, PointerCount = -1 }; for (int k = 1; k <= nodeCompressData.Depth; k++) { int pointerCount = (int)Math.Pow(2, k); foreach (FibTreeNode child in node.GetChildrenAtLevel(k)) { pointerCount += compressData[child].PointerCount; } if ((nodeCompressData.PointerCount == -1) || (pointerCount < nodeCompressData.PointerCount)) { nodeCompressData.OptimalStride = k; nodeCompressData.PointerCount = pointerCount; } } compressData.Add(node, nodeCompressData); } }