Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ojl_bimap
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Oskar Lappi
ojl_bimap
Commits
3ed74a9c
Commit
3ed74a9c
authored
1 year ago
by
Oskar Lappi
Browse files
Options
Downloads
Patches
Plain Diff
Added min and max element accessors
parent
2503e847
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/ojl/bimap.hpp
+134
-0
134 additions, 0 deletions
include/ojl/bimap.hpp
test/cmake/TestSetup.cmake
+0
-2
0 additions, 2 deletions
test/cmake/TestSetup.cmake
with
134 additions
and
2 deletions
include/ojl/bimap.hpp
+
134
−
0
View file @
3ed74a9c
...
...
@@ -2,7 +2,9 @@
#include
<vector>
#include
<utility>
#include
<iterator>
#include
<ranges>
#include
<unordered_set>
#include
<algorithm>
namespace
ojl
{
template
<
typename
T
>
...
...
@@ -254,6 +256,138 @@ namespace ojl {
return
r_relations
.
count
(
r
);
}
// Min elements
std
::
optional
<
L
>
l_min_element
()
{
auto
it
=
std
::
min_element
(
left_elements
.
begin
(),
left_elements
.
end
());
if
(
it
!=
left_elements
.
end
()){
return
*
it
;
}
return
std
::
nullopt
;
}
std
::
optional
<
R
>
r_min_element
()
{
auto
it
=
std
::
min_element
(
right_elements
.
begin
(),
right_elements
.
end
());
if
(
it
!=
right_elements
.
end
()){
return
*
it
;
}
return
std
::
nullopt
;
}
// Max elements
std
::
optional
<
L
>
l_max_element
()
{
auto
it
=
std
::
max_element
(
left_elements
.
begin
(),
left_elements
.
end
());
if
(
it
!=
left_elements
.
end
()){
return
*
it
;
}
return
std
::
nullopt
;
}
std
::
optional
<
R
>
r_max_element
()
{
auto
it
=
std
::
max_element
(
right_elements
.
begin
(),
right_elements
.
end
());
if
(
it
!=
right_elements
.
end
()){
return
*
it
;
}
return
std
::
nullopt
;
}
// Min mapped elements
std
::
optional
<
R
>
min_mapped_element
(
left
l_key
)
{
auto
it
=
std
::
ranges
::
min_element
(
l_relations
|
std
::
views
::
filter
([
&
l_key
](
relation
rel
){
return
rel
.
first
==
l_key
.
val
;}));
if
(
it
!=
l_relations
.
end
()){
return
it
->
second
;
}
return
std
::
nullopt
;
}
std
::
optional
<
R
>
min_mapped_element
(
right
r_key
)
{
auto
it
=
std
::
ranges
::
min_element
(
l_relations
|
std
::
views
::
filter
([
&
r_key
](
relation
rel
){
return
rel
.
second
==
r_key
.
val
;}));
if
(
it
!=
l_relations
.
end
()){
return
it
->
first
;
}
return
std
::
nullopt
;
}
std
::
optional
<
R
>
l_min_mapped_element
(
L
l
)
{
auto
it
=
std
::
ranges
::
min_element
(
l_relations
|
std
::
views
::
filter
([
&
l
](
relation
rel
){
return
rel
.
first
==
l
;}));
if
(
it
!=
l_relations
.
end
()){
return
it
->
second
;
}
return
std
::
nullopt
;
}
std
::
optional
<
R
>
r_min_mapped_element
(
R
r
)
{
auto
it
=
std
::
ranges
::
min_element
(
l_relations
|
std
::
views
::
filter
([
&
r
](
relation
rel
){
return
rel
.
second
==
r
;}));
if
(
it
!=
l_relations
.
end
()){
return
it
->
first
;
}
return
std
::
nullopt
;
}
// Max mapped elements
std
::
optional
<
R
>
max_mapped_element
(
left
l_key
)
{
auto
it
=
std
::
ranges
::
max_element
(
l_relations
|
std
::
views
::
filter
([
&
l_key
](
relation
rel
){
return
rel
.
first
==
l_key
.
val
;}));
if
(
it
!=
l_relations
.
end
()){
return
it
->
second
;
}
return
std
::
nullopt
;
}
std
::
optional
<
R
>
max_mapped_element
(
right
r_key
)
{
auto
it
=
std
::
ranges
::
max_element
(
l_relations
|
std
::
views
::
filter
([
&
r_key
](
relation
rel
){
return
rel
.
second
==
r_key
.
val
;}));
if
(
it
!=
l_relations
.
end
()){
return
it
->
first
;
}
return
std
::
nullopt
;
}
std
::
optional
<
R
>
l_max_mapped_element
(
L
l
)
{
auto
it
=
std
::
ranges
::
max_element
(
l_relations
|
std
::
views
::
filter
([
&
l
](
relation
rel
){
return
rel
.
first
==
l
;}));
if
(
it
!=
l_relations
.
end
()){
return
it
->
second
;
}
return
std
::
nullopt
;
}
std
::
optional
<
R
>
r_max_mapped_element
(
R
r
)
{
auto
it
=
std
::
ranges
::
max_element
(
l_relations
|
std
::
views
::
filter
([
&
r
](
relation
rel
){
return
rel
.
second
==
r
;}));
if
(
it
!=
l_relations
.
end
()){
return
it
->
first
;
}
return
std
::
nullopt
;
}
// Equal range
std
::
pair
<
relation_iterator
,
relation_iterator
>
equal_range
(
left
l_key
)
...
...
This diff is collapsed.
Click to expand it.
test/cmake/TestSetup.cmake
+
0
−
2
View file @
3ed74a9c
#TODO: make this macro take an argument
macro
(
find_catch2_and_define_test_target
)
if
(
TARGET TestInterface
)
set
(
TestInterface_EXISTS 1
)
...
...
@@ -33,4 +32,3 @@ macro(find_catch2_and_define_test_target)
endif
()
endmacro
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment