private static IEnumerable <int> FindNodeIndices( string concatenatedNames, ImmutableArray <Node> nodes, string name, StringSliceComparer comparer) { // find any node that matches case-insensitively var startingPosition = BinarySearch(concatenatedNames, nodes, name); var nameSlice = new StringSlice(name); if (startingPosition != -1) { // yield if this matches by the actual given comparer if (comparer.Equals(nameSlice, GetNameSlice(concatenatedNames, nodes, startingPosition))) { yield return(startingPosition); } var position = startingPosition; while (position > 0 && s_caseInsensitiveComparer.Equals(GetNameSlice(concatenatedNames, nodes, position - 1), nameSlice)) { position--; if (comparer.Equals(GetNameSlice(concatenatedNames, nodes, position), nameSlice)) { yield return(position); } } position = startingPosition; while (position + 1 < nodes.Length && s_caseInsensitiveComparer.Equals(GetNameSlice(concatenatedNames, nodes, position + 1), nameSlice)) { position++; if (comparer.Equals(GetNameSlice(concatenatedNames, nodes, position), nameSlice)) { yield return(position); } } } }
private IEnumerable <int> FindNodeIndices(string name, StringSliceComparer comparer) => FindNodeIndices(_concatenatedNames, _nodes, name, comparer);
/// <summary> /// Gets all the node indices with matching names per the <paramref name="comparer" />. /// </summary> private IEnumerable<int> FindNodeIndices( string name, StringSliceComparer comparer) { // find any node that matches case-insensitively var startingPosition = BinarySearch(name); var nameSlice = new StringSlice(name); if (startingPosition != -1) { // yield if this matches by the actual given comparer if (comparer.Equals(nameSlice, GetNameSlice(startingPosition))) { yield return startingPosition; } int position = startingPosition; while (position > 0 && s_caseInsensitiveComparer.Equals(GetNameSlice(position - 1), nameSlice)) { position--; if (comparer.Equals(GetNameSlice(position), nameSlice)) { yield return position; } } position = startingPosition; while (position + 1 < _nodes.Length && s_caseInsensitiveComparer.Equals(GetNameSlice(position + 1), nameSlice)) { position++; if (comparer.Equals(GetNameSlice(position), nameSlice)) { yield return position; } } } }