public bool Trim(DataSourceBuilder sourceBuilder) { if (sourceBuilder is null) { throw new ArgumentNullException(nameof(sourceBuilder)); } int lastGoodNode = 0; ushort firstGoodNode = 0; bool trimmed = false; if (Header != -1 && !HasValidChild) { if (Math.Abs(GetScore(sourceBuilder.Result.BaseRate)) < sourceBuilder.Settings.Results.MinumumScore && ParentNode != null) { sourceBuilder.Settings.TrimmedNode?.Invoke(this); parentNode.RemoveNode(this); return(true); } #if DEBUG else { } #endif LastNode = true; } if (!HasValidChild) { if (this.next != null && this.ChildCount > 0) { this.next = new MemoryNode[0]; trimmed = true; } } else { foreach (MemoryNode mn in this.next) { if (mn != null) { trimmed = trimmed || mn.Trim(sourceBuilder); } } for (int i = next.Length; i > 0; i--) { if (next[i - 1] != null) { lastGoodNode = i; break; } } for (ushort i = 0; i < next.Length; i++) { if (next[i] != null) { firstGoodNode = i; break; } } if (lastGoodNode != next.Length) { trimmed = true; next = next.Take(lastGoodNode).ToArray(); } if (firstGoodNode != 0) { trimmed = true; SkipChildren += firstGoodNode; next = next.Skip(firstGoodNode).ToArray(); } } return(trimmed); }