diff --git a/Dalamud.DrunkenToad/Collections/ThreadSafeCollection.cs b/Dalamud.DrunkenToad/Collections/ThreadSafeCollection.cs index 4308200..e26ae3b 100644 --- a/Dalamud.DrunkenToad/Collections/ThreadSafeCollection.cs +++ b/Dalamud.DrunkenToad/Collections/ThreadSafeCollection.cs @@ -79,6 +79,33 @@ public int AddRange(IEnumerable> itemsToAdd) /// True if the item was removed successfully; otherwise, false. public bool Remove(TKey key) => this.items.TryRemove(key, out _); + /// + /// Removes a range of key-value pairs from the collection based on the keys. + /// + /// The keys of the items to remove from the collection. + /// The number of items successfully removed from the collection. + public int RemoveRange(IEnumerable keysToRemove) + { + var removedCount = 0; + this.rwLock.EnterWriteLock(); + try + { + foreach (var key in keysToRemove) + { + if (this.items.TryRemove(key, out _)) + { + removedCount++; + } + } + } + finally + { + this.rwLock.ExitWriteLock(); + } + + return removedCount; + } + /// /// Gets an item from the collection. /// diff --git a/Dalamud.DrunkenToad/Collections/ThreadSafeSortedCollection.cs b/Dalamud.DrunkenToad/Collections/ThreadSafeSortedCollection.cs index acaa7c8..912d143 100644 --- a/Dalamud.DrunkenToad/Collections/ThreadSafeSortedCollection.cs +++ b/Dalamud.DrunkenToad/Collections/ThreadSafeSortedCollection.cs @@ -230,6 +230,33 @@ public bool Remove(T item) return false; } + /// + /// Removes a range of items from the collection. + /// + /// The items to be removed. + /// The number of items successfully removed. + public int RemoveRange(IEnumerable itemsToRemove) + { + this.setLock.EnterWriteLock(); + var removedCount = 0; + try + { + foreach (var item in itemsToRemove) + { + if (this.Remove(item)) + { + removedCount++; + } + } + } + finally + { + this.setLock.ExitWriteLock(); + } + + return removedCount; + } + /// /// Updates an item in the collection by removing it, performing the specified action, and adding it back. ///