Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-graph
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
Model registry
Operate
Environments
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
Platform
Development
swh-graph
Commits
fd5b91f1
Commit
fd5b91f1
authored
1 year ago
by
vlorentz
Browse files
Options
Downloads
Patches
Plain Diff
sort: Fix crash on empty final buffer
parent
fb1a824d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!347
Add Rust rewrite of the Java code
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
rust/src/utils/sort.rs
+6
-2
6 additions, 2 deletions
rust/src/utils/sort.rs
rust/tests/sort.rs
+53
-0
53 additions, 0 deletions
rust/tests/sort.rs
with
59 additions
and
2 deletions
rust/src/utils/sort.rs
+
6
−
2
View file @
fd5b91f1
...
...
@@ -237,8 +237,12 @@ where
.par_bridge
()
.map
(|
buffer
:
RefCell
<
Vec
<
(
usize
,
usize
)
>>
|
{
let
mut
buffer
=
buffer
.borrow_mut
();
let
sorted_iterator
=
flush
(
temp_dir
,
&
mut
(
*
buffer
)[
..
])
?
;
Ok
(
vec!
[
sorted_iterator
])
if
buffer
.len
()
>
0
{
let
sorted_iterator
=
flush
(
temp_dir
,
&
mut
(
*
buffer
)[
..
])
?
;
Ok
(
vec!
[
sorted_iterator
])
}
else
{
Ok
(
vec!
[])
}
})
.collect
::
<
Vec
<
_
>>
()
.into_iter
(),
...
...
This diff is collapsed.
Click to expand it.
rust/tests/sort.rs
0 → 100644
+
53
−
0
View file @
fd5b91f1
/*
* Copyright (C) 2023 The Software Heritage developers
* See the AUTHORS file at the top-level directory of this distribution
* License: GNU General Public License version 3, or any later version
* See top-level LICENSE file for more information
*/
use
anyhow
::{
Context
,
Result
};
use
rayon
::
prelude
::
*
;
use
swh_graph
::
utils
::
sort
::
*
;
#[test]
fn
test_par_sort_arcs
()
->
Result
<
()
>
{
let
tempdir
=
tempfile
::
tempdir
()
.context
(
"temp dir"
)
?
;
assert_eq!
(
par_sort_arcs
(
tempdir
.path
(),
100
,
vec!
[(
1
,
10
),
(
2
,
1
),
(
1
,
5
),
(
2
,
10
)]
.into_par_iter
(),
|
buf
,
arc
|
{
buf
.push
(
arc
);
Ok
(())
}
)
.context
(
"par_sort_arcs"
)
?
.collect
::
<
Vec
<
_
>>
(),
vec!
[(
1
,
5
),
(
1
,
10
),
(
2
,
1
),
(
2
,
10
)],
);
Ok
(())
}
#[test]
fn
test_par_sort_arcs_empty_buffer
()
->
Result
<
()
>
{
let
tempdir
=
tempfile
::
tempdir
()
.context
(
"temp dir"
)
?
;
assert_eq!
(
par_sort_arcs
(
tempdir
.path
(),
0
,
// Causes buffers to be flushed immediately, so the last batch will be empty
vec!
[(
1
,
10
),
(
2
,
1
),
(
1
,
5
),
(
2
,
10
)]
.into_par_iter
(),
|
buf
,
arc
|
{
buf
.push
(
arc
);
Ok
(())
}
)
.context
(
"par_sort_arcs"
)
?
.collect
::
<
Vec
<
_
>>
(),
vec!
[(
1
,
5
),
(
1
,
10
),
(
2
,
1
),
(
2
,
10
)],
);
Ok
(())
}
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