Skip to content

Commit fd213bc

Browse files
committed
added RemoveRange overload for IMap to remove a range of keys
1 parent dd1c2e1 commit fd213bc

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

Source/Base/Collections/Spring.Collections.Base.pas

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ TMapBase<TKey, TValue> = class abstract(TCollectionBase<TPair<TKey, TValue>>)
639639
procedure Add(const key: TKey; const value: TValue); overload;
640640

641641
function Remove(const item: TKeyValuePair): Boolean;
642+
function RemoveRange(const keys: array of TKey): Integer; overload;
643+
function RemoveRange(const keys: IEnumerable<TKey>): Integer; overload;
642644

643645
function Extract(const item: TKeyValuePair): TKeyValuePair;
644646

@@ -2668,6 +2670,24 @@ function TMapBase<TKey, TValue>.Remove(const item: TKeyValuePair): Boolean;
26682670
Result := IMap<TKey, TValue>(this).Remove(item.Key, item.Value);
26692671
end;
26702672

2673+
function TMapBase<TKey, TValue>.RemoveRange(const keys: array of TKey): Integer;
2674+
var
2675+
i: Integer;
2676+
begin
2677+
Result := 0;
2678+
for i := 0 to High(keys) do
2679+
Inc(Result, Integer(IMap<TKey, TValue>(this).Remove(keys[i])));
2680+
end;
2681+
2682+
function TMapBase<TKey, TValue>.RemoveRange(const keys: IEnumerable<TKey>): Integer;
2683+
var
2684+
key: TKey;
2685+
begin
2686+
Result := 0;
2687+
for key in keys do
2688+
Inc(Result, Integer(IMap<TKey, TValue>(this).Remove(key)));
2689+
end;
2690+
26712691
{$ENDREGION}
26722692

26732693

Source/Base/Collections/Spring.Collections.Dictionaries.pas

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ TInverse = class(TCollectionBase<TValueKeyPair>,
213213
function TryAdd(const value: TValue; const key: TKey): Boolean;
214214
function Remove(const value: TValue): Boolean; overload;
215215
function Remove(const value: TValue; const key: TKey): Boolean; overload;
216+
function RemoveRange(const values: array of TValue): Integer; overload;
217+
function RemoveRange(const values: IEnumerable<TValue>): Integer; overload;
216218
function Extract(const value: TValue; const key: TKey): TValueKeyPair; overload;
217219
function Contains(const value: TValue; const key: TKey): Boolean; overload;
218220
function ContainsKey(const value: TValue): Boolean;
@@ -2048,6 +2050,26 @@ function TBidiDictionary<TKey, TValue>.TInverse.Remove(
20482050
Result := Remove(item.Key, item.Value);
20492051
end;
20502052

2053+
function TBidiDictionary<TKey, TValue>.TInverse.RemoveRange(
2054+
const values: array of TValue): Integer;
2055+
var
2056+
i: Integer;
2057+
begin
2058+
Result := 0;
2059+
for i := 0 to High(values) do
2060+
Inc(Result, Integer(Remove(values[i])));
2061+
end;
2062+
2063+
function TBidiDictionary<TKey, TValue>.TInverse.RemoveRange(
2064+
const values: IEnumerable<TValue>): Integer;
2065+
var
2066+
value: TValue;
2067+
begin
2068+
Result := 0;
2069+
for value in values do
2070+
Inc(Result, Integer(Remove(value)));
2071+
end;
2072+
20512073
procedure TBidiDictionary<TKey, TValue>.TInverse.SetCapacity(value: Integer);
20522074
begin
20532075
fSource.SetCapacity(value);

Source/Base/Collections/Spring.Collections.pas

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,30 @@ TLinkedListNode<T> = class sealed
17151715
/// </returns>
17161716
function Remove(const key: TKey; const value: TValue): Boolean; overload;
17171717

1718+
/// <summary>
1719+
/// Removes the specified range of keys from the IMap&lt;TKey,
1720+
/// TValue&gt;.
1721+
/// </summary>
1722+
/// <param name="keys">
1723+
/// The keys of the elements to remove.
1724+
/// </param>
1725+
/// <returns>
1726+
/// The number of elements that were actually removed.
1727+
/// </returns>
1728+
function RemoveRange(const keys: array of TKey): Integer; overload;
1729+
1730+
/// <summary>
1731+
/// Removes the specified range of keys from the IMap&lt;TKey,
1732+
/// TValue&gt;.
1733+
/// </summary>
1734+
/// <param name="keys">
1735+
/// The keys of the elements to remove.
1736+
/// </param>
1737+
/// <returns>
1738+
/// The number of elements that were actually removed.
1739+
/// </returns>
1740+
function RemoveRange(const keys: IEnumerable<TKey>): Integer; overload;
1741+
17181742
function Extract(const key: TKey; const value: TValue): TPair<TKey, TValue>;
17191743

17201744
/// <summary>

0 commit comments

Comments
 (0)