Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
A
Anvoker.Maps
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
An Ionescu
Anvoker.Maps
Commits
8a4b0711
Commit
8a4b0711
authored
Nov 21, 2018
by
An Ionescu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding add methods to MultiBiMap that select between adding values and adding new keys.
parent
8037445d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
0 deletions
+76
-0
Assets/Anvoker.Collections/Maps/MultiBiMap.cs
Assets/Anvoker.Collections/Maps/MultiBiMap.cs
+76
-0
No files found.
Assets/Anvoker.Collections/Maps/MultiBiMap.cs
View file @
8a4b0711
...
...
@@ -353,6 +353,82 @@ namespace Anvoker.Collections.Maps
#
region
Public
Methods
/// <summary>
/// If the specified key already exists in the
/// <see cref="MultiBiMap{TKey, TVal}"/>, adds the specified value to
/// that key; otherwise it adds a new element with the specified key and
/// value.
/// </summary>
/// <param name="key">The key of the element.</param>
/// <param name="value">The value of the element. The value can
/// be null for reference types.</param>
/// <returns>True if either the key didn't already exist or the value
/// didn't already exist on the specified key; otherwise, false.
/// </returns>
public
bool
Add
(
TKey
key
,
TVal
value
)
{
if
(
ContainsKey
(
key
))
{
return
AddValue
(
key
,
value
);
}
else
{
AddKey
(
key
,
value
);
return
true
;
}
}
/// <summary>
/// If the specified key already exists in the
/// <see cref="MultiBiMap{TKey, TVal}"/>, adds the specified values to
/// that key; otherwise it adds a new element with the specified key and
/// values.
/// </summary>
/// <param name="key">The key of the element.</param>
/// <param name="values">The values of the element.</param>
/// <returns>True if either the key didn't already exist or at least one
/// value didn't already exist on the specified key; otherwise, false.
/// </returns>
public
bool
Add
(
TKey
key
,
IEnumerable
<
TVal
>
values
)
{
if
(
ContainsKey
(
key
))
{
return
AddValues
(
key
,
values
);
}
else
{
AddKey
(
key
,
values
);
return
true
;
}
}
/// <summary>
/// If the specified key already exists in the
/// <see cref="MultiBiMap{TKey, TVal}"/>, adds the specified values to
/// that key; otherwise it adds a new element with the specified key and
/// values. <para>This doesn't copy the collection, it passes it by
/// reference.</para> <para>Will throw <see cref="ArgumentException"/>
/// if the passed <see cref="HashSet{TVal}"/>'s comparer isn't reference
/// equal to <see cref="ComparerValue"/>.</para>
/// </summary>
/// <param name="key">The key of the element.</param>
/// <param name="values">The values of the element.</param>
/// <returns>True if either the key didn't already exist or at least one
/// value didn't already exist on the specified key; otherwise, false.
/// </returns>
public
bool
Add
(
TKey
key
,
HashSet
<
TVal
>
values
)
{
if
(
ContainsKey
(
key
))
{
return
AddValues
(
key
,
values
);
}
else
{
AddKey
(
key
,
values
);
return
true
;
}
}
/// <summary>
/// Adds the specified key to the <see cref="MultiBiMap{TKey, TVal}"/>
/// with an empty value collection.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment