Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
memory-faucet
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
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
数学の武士
memory-faucet
Commits
22a45a4b
Commit
22a45a4b
authored
4 months ago
by
数学の武士
Browse files
Options
Downloads
Patches
Plain Diff
Lmbda func impl for compare functions
parent
d01961de
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/mf-utils.h
+2
-5
2 additions, 5 deletions
include/mf-utils.h
src/mf-utils.cpp
+14
-17
14 additions, 17 deletions
src/mf-utils.cpp
with
16 additions
and
22 deletions
include/mf-utils.h
+
2
−
5
View file @
22a45a4b
...
...
@@ -12,18 +12,15 @@ enum class buf_choose_policy
namespace
mf_utils
{
bool
free_size_comparator
(
const
buffer
&
obj
,
const
size_t
required_size
);
bool
size_comparator
(
const
size_t
required_size
,
const
buffer
&
obj
);
typename
std
::
vector
<
buffer
>::
iterator
get_lower_bound
(
typename
std
::
vector
<
buffer
>::
iterator
first
,
typename
std
::
vector
<
buffer
>::
iterator
last
,
const
size_t
value
,
std
::
function
<
bool
(
const
buffer
&
,
const
size_t
)
>&
comp
);
bool
(
*
comp
)
(
const
buffer
&
,
const
size_t
));
typename
std
::
vector
<
buffer
>::
iterator
get_upper_bound
(
typename
std
::
vector
<
buffer
>::
iterator
first
,
typename
std
::
vector
<
buffer
>::
iterator
last
,
const
size_t
value
,
std
::
function
<
bool
(
const
size_t
,
const
buffer
&
)
>&
comp
);
bool
(
*
comp
)
(
const
size_t
,
const
buffer
&
));
template
<
buf_choose_policy
choose_type
=
buf_choose_policy
::
naive
>
int
get_buffer
(
const
size_t
required_size
,
...
...
This diff is collapsed.
Click to expand it.
src/mf-utils.cpp
+
14
−
17
View file @
22a45a4b
#include
"mf-utils.h"
bool
mf_utils
::
free_size_comparator
(
const
buffer
&
obj
,
const
size_t
required_size
)
{
if
(
obj
.
get_status
()
==
false
)
return
false
;
return
obj
.
get_size
()
<=
required_size
;
}
bool
mf_utils
::
size_comparator
(
const
size_t
required_size
,
const
buffer
&
obj
)
{
return
required_size
<
obj
.
get_size
();
}
typename
std
::
vector
<
buffer
>::
iterator
mf_utils
::
get_lower_bound
(
typename
std
::
vector
<
buffer
>::
iterator
first
,
typename
std
::
vector
<
buffer
>::
iterator
last
,
const
size_t
value
,
std
::
function
<
bool
(
const
buffer
&
,
const
size_t
)
>&
comp
)
bool
(
*
comp
)
(
const
buffer
&
,
const
size_t
))
{
typename
std
::
vector
<
buffer
>::
iterator
it
;
typename
std
::
iterator_traits
<
typename
std
::
vector
<
buffer
>::
iterator
>::
difference_type
count
,
step
;
...
...
@@ -43,7 +30,7 @@ typename std::vector<buffer>::iterator mf_utils::get_lower_bound(
typename
std
::
vector
<
buffer
>::
iterator
mf_utils
::
get_upper_bound
(
typename
std
::
vector
<
buffer
>::
iterator
first
,
typename
std
::
vector
<
buffer
>::
iterator
last
,
const
size_t
value
,
std
::
function
<
bool
(
const
size_t
,
const
buffer
&
)
>&
comp
)
bool
(
*
comp
)
(
const
size_t
,
const
buffer
&
))
{
typename
std
::
vector
<
buffer
>::
iterator
it
;
typename
std
::
iterator_traits
<
typename
std
::
vector
<
buffer
>::
iterator
>::
difference_type
count
,
step
;
...
...
@@ -119,7 +106,10 @@ int mf_utils::get_buffer<buf_choose_policy::sorted_vec>(const size_t required_si
}
typename
std
::
vector
<
buffer
>::
iterator
buf_it
;
std
::
function
<
bool
(
const
size_t
,
const
buffer
&
)
>
comparator
=
mf_utils
::
size_comparator
;
auto
comparator
=
[](
const
size_t
required_size
,
const
buffer
&
obj
)
->
bool
{
return
required_size
<
obj
.
get_size
();
};
buf_it
=
mf_utils
::
get_upper_bound
(
buff_vec
.
begin
(),
buff_vec
.
end
(),
required_size
,
comparator
);
buf_it
=
buff_vec
.
insert
(
buf_it
,
buffer
(
required_size
,
mem
));
(
*
ptr
)
=
buf_it
->
get_ptr
();
...
...
@@ -135,7 +125,14 @@ int mf_utils::get_buffer<buf_choose_policy::find_best_unsorted>(const size_t req
void
**
ptr
)
{
typename
std
::
vector
<
buffer
>::
iterator
available_buf_it
;
std
::
function
<
bool
(
const
buffer
&
,
const
size_t
)
>
comparator
=
mf_utils
::
free_size_comparator
;
auto
comparator
=
[](
const
buffer
&
obj
,
const
size_t
required_size
)
->
bool
{
if
(
obj
.
get_status
()
==
false
)
return
false
;
return
obj
.
get_size
()
<=
required_size
;
};
available_buf_it
=
mf_utils
::
get_lower_bound
(
buff_vec
.
begin
(),
buff_vec
.
end
(),
required_size
,
comparator
);
if
(
available_buf_it
!=
buff_vec
.
end
())
{
...
...
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