Skip to content

Instantly share code, notes, and snippets.

@davispuh
Last active March 6, 2024 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davispuh/56d64d2798d743fe6ea376e17d791d42 to your computer and use it in GitHub Desktop.
Save davispuh/56d64d2798d743fe6ea376e17d791d42 to your computer and use it in GitHub Desktop.
Remove items from sorted array fast!
import std.algorithm : remove, sort;
import std.range : SortedRange;
void fastRemove(ref SortedRange!(int[]) list, const int[] itemsToRemove)
{
foreach (removeItem; itemsToRemove)
{
ulong index = list.lowerBound(removeItem).length;
if (index < hashes.length && list[index] == removeItem)
{
list = list.remove(index);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment