Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
de0ddc0e
Commit
de0ddc0e
authored
Mar 13, 2019
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add findEntry() methods to HashMap and TreeMap.
parent
cffc710e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
map.h
c++/src/kj/map.h
+54
-0
No files found.
c++/src/kj/map.h
View file @
de0ddc0e
...
...
@@ -87,6 +87,14 @@ public:
// Like find() but if the key isn't present then call createEntry() to create the corresponding
// entry and insert it. createEntry() must return type `Entry`.
template
<
typename
KeyLike
>
kj
::
Maybe
<
Entry
&>
findEntry
(
KeyLike
&&
key
);
template
<
typename
KeyLike
>
kj
::
Maybe
<
const
Entry
&>
findEntry
(
KeyLike
&&
key
)
const
;
template
<
typename
KeyLike
,
typename
Func
>
Entry
&
findOrCreateEntry
(
KeyLike
&&
key
,
Func
&&
createEntry
);
// Sometimes you need to see the whole matching Entry, not just the Value.
template
<
typename
KeyLike
>
bool
erase
(
KeyLike
&&
key
);
// Erase the entry with the matching key.
...
...
@@ -176,6 +184,14 @@ public:
// Like find() but if the key isn't present then call createEntry() to create the corresponding
// entry and insert it. createEntry() must return type `Entry`.
template
<
typename
KeyLike
>
kj
::
Maybe
<
Entry
&>
findEntry
(
KeyLike
&&
key
);
template
<
typename
KeyLike
>
kj
::
Maybe
<
const
Entry
&>
findEntry
(
KeyLike
&&
key
)
const
;
template
<
typename
KeyLike
,
typename
Func
>
Entry
&
findOrCreateEntry
(
KeyLike
&&
key
,
Func
&&
createEntry
);
// Sometimes you need to see the whole matching Entry, not just the Value.
template
<
typename
K1
,
typename
K2
>
auto
range
(
K1
&&
k1
,
K2
&&
k2
);
template
<
typename
K1
,
typename
K2
>
...
...
@@ -353,6 +369,25 @@ Value& HashMap<Key, Value>::findOrCreate(KeyLike&& key, Func&& createEntry) {
return
table
.
findOrCreate
(
key
,
kj
::
fwd
<
Func
>
(
createEntry
)).
value
;
}
template
<
typename
Key
,
typename
Value
>
template
<
typename
KeyLike
>
kj
::
Maybe
<
typename
HashMap
<
Key
,
Value
>::
Entry
&>
HashMap
<
Key
,
Value
>::
findEntry
(
KeyLike
&&
key
)
{
return
table
.
find
(
kj
::
fwd
<
KeyLike
>
(
key
));
}
template
<
typename
Key
,
typename
Value
>
template
<
typename
KeyLike
>
kj
::
Maybe
<
const
typename
HashMap
<
Key
,
Value
>::
Entry
&>
HashMap
<
Key
,
Value
>::
findEntry
(
KeyLike
&&
key
)
const
{
return
table
.
find
(
kj
::
fwd
<
KeyLike
>
(
key
));
}
template
<
typename
Key
,
typename
Value
>
template
<
typename
KeyLike
,
typename
Func
>
typename
HashMap
<
Key
,
Value
>::
Entry
&
HashMap
<
Key
,
Value
>::
findOrCreateEntry
(
KeyLike
&&
key
,
Func
&&
createEntry
)
{
return
table
.
findOrCreate
(
kj
::
fwd
<
KeyLike
>
(
key
),
kj
::
fwd
<
Func
>
(
createEntry
));
}
template
<
typename
Key
,
typename
Value
>
template
<
typename
KeyLike
>
bool
HashMap
<
Key
,
Value
>::
erase
(
KeyLike
&&
key
)
{
...
...
@@ -445,6 +480,25 @@ Value& TreeMap<Key, Value>::findOrCreate(KeyLike&& key, Func&& createEntry) {
return
table
.
findOrCreate
(
key
,
kj
::
fwd
<
Func
>
(
createEntry
)).
value
;
}
template
<
typename
Key
,
typename
Value
>
template
<
typename
KeyLike
>
kj
::
Maybe
<
typename
TreeMap
<
Key
,
Value
>::
Entry
&>
TreeMap
<
Key
,
Value
>::
findEntry
(
KeyLike
&&
key
)
{
return
table
.
find
(
kj
::
fwd
<
KeyLike
>
(
key
));
}
template
<
typename
Key
,
typename
Value
>
template
<
typename
KeyLike
>
kj
::
Maybe
<
const
typename
TreeMap
<
Key
,
Value
>::
Entry
&>
TreeMap
<
Key
,
Value
>::
findEntry
(
KeyLike
&&
key
)
const
{
return
table
.
find
(
kj
::
fwd
<
KeyLike
>
(
key
));
}
template
<
typename
Key
,
typename
Value
>
template
<
typename
KeyLike
,
typename
Func
>
typename
TreeMap
<
Key
,
Value
>::
Entry
&
TreeMap
<
Key
,
Value
>::
findOrCreateEntry
(
KeyLike
&&
key
,
Func
&&
createEntry
)
{
return
table
.
findOrCreate
(
kj
::
fwd
<
KeyLike
>
(
key
),
kj
::
fwd
<
Func
>
(
createEntry
));
}
template
<
typename
Key
,
typename
Value
>
template
<
typename
K1
,
typename
K2
>
auto
TreeMap
<
Key
,
Value
>::
range
(
K1
&&
k1
,
K2
&&
k2
)
{
...
...
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