Last active
March 6, 2024 17:44
-
-
Save davispuh/56d64d2798d743fe6ea376e17d791d42 to your computer and use it in GitHub Desktop.
Remove items from sorted array fast!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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