Function pullIndices

Returns a range excluding the specified indices.

auto auto pullIndices(Range, Indices...) (
  Range range,
  Indices indices
)
if (from.std.range.isInputRange!Range && from.std.meta.allSatisfy!(from.std.traits.isIntegral, from.bolts.meta.Flatten!Indices));

The indices can be given as a range of indices, or single integral arguments or a mixture of both. All index arguments will be concated together and sorted before returning a range that then goes through the original range exlusing the resulting concatenation of indices.

The running time is O(n) if indices is a single sorted range or a single index to remove, else there's an additional cost of standard sort running time.

Parameters

NameDescription
range an input range
indices zero or more integral elements or ranges

Returns

A range excluding the supplied indices

Benchmarks

  • single args: pullIndices(8, 16, 14...)
  • single range: pullIndices([8, 16, 14...])
  • sorted range: pullIndices([8, 16, 14...].sort)
  • canFind range: indices.filter!(canFind)
  • canFind sorted: indices.sort.filter!(canFind)
  • Benchmarking pullIndices against filter/canFind:
      numbers: [12, 11, 1, 9, 11, 4, 1, 4, 2, 7, 16, 8, 8, 9, 6, 15, 9, 0, 15, 2]
      indices: [8, 16, 14, 11, 0, 16, 12, 10, 15, 17]
    pullIndices:
      single args:    3 ms, 885 μs, and 6 hnsecs
      single range:   1 ms and 610 μs
      sorted range:   185 μs and 2 hnsecs
      canFind range:  5 ms and 547 μs
      canFind sorted: 4 hnsecs
    pullIndices (with .array):
      single args:    8 ms, 765 μs, and 8 hnsecs
      single range:   6 ms, 823 μs, and 8 hnsecs
      sorted range:   6 ms, 571 μs, and 2 hnsecs
      canFind range:  10 ms, 479 μs, and 2 hnsecs
      canFind sorted: 9 ms, 330 μs, and 5 hnsecs

    Since

    0.0.1