public void ProcessNumber(string number) { if (number.Length == Depth) { return; } //We are matched int currChar = Int32.Parse(number[Depth].ToString()); if (!SubNodes.Any(n => n.NumberStored == currChar)) { Log($"Creating node: {currChar} under {NumberStored}"); var node = new NumberStorageNode(_log) { Depth = Depth + 1, NumberStored = currChar }; SubNodes.Add(node); } else { Log($"Node: {currChar} already present under {NumberStored}"); } //Handover the processing of the number to our children SubNodes.First(s => s.NumberStored == currChar).ProcessNumber(number); }
private int CalculateStorageSpace(List <string> numbers) { NumberStorageNode rootNode = new NumberStorageNode((o) => Log(o)); foreach (var n in numbers) { Log($"Processing: {n}"); rootNode.ProcessNumber(n); } return(rootNode.GetNodeCount()); }