Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fp-succinct-trees-1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Mehren
fp-succinct-trees-1
Commits
9769fabb
Unverified
Commit
9769fabb
authored
Jul 13, 2018
by
Daniel Rose
Browse files
Options
Downloads
Patches
Plain Diff
[MinMax] excess: add error handling for invalid index value
parent
de7a47c1
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/common/min_max.rs
+4
-1
4 additions, 1 deletion
src/common/min_max.rs
with
4 additions
and
1 deletion
src/common/min_max.rs
+
4
−
1
View file @
9769fabb
...
@@ -204,6 +204,9 @@ impl MinMax {
...
@@ -204,6 +204,9 @@ impl MinMax {
}
}
pub
fn
excess
(
&
self
,
index
:
u64
)
->
Result
<
u64
,
NodeError
>
{
pub
fn
excess
(
&
self
,
index
:
u64
)
->
Result
<
u64
,
NodeError
>
{
if
index
>=
self
.bits
.len
()
{
return
Err
(
NodeError
::
NotANodeError
);
}
let
block_number
=
(
index
/
self
.block_size
);
let
block_number
=
(
index
/
self
.block_size
);
let
position_in_block
=
index
%
self
.block_size
;
let
position_in_block
=
index
%
self
.block_size
;
let
mut
pre_excess
:
i64
=
0
;
let
mut
pre_excess
:
i64
=
0
;
...
@@ -665,7 +668,6 @@ mod tests {
...
@@ -665,7 +668,6 @@ mod tests {
let
min_max
=
MinMax
::
new
(
bits
,
4
);
let
min_max
=
MinMax
::
new
(
bits
,
4
);
assert_eq!
(
min_max
.excess
(
21
)
.unwrap
(),
0
);
assert_eq!
(
min_max
.excess
(
21
)
.unwrap
(),
0
);
assert_eq!
(
min_max
.excess
(
7
)
.unwrap
(),
4
);
assert_eq!
(
min_max
.excess
(
7
)
.unwrap
(),
4
);
// TODO: Werden schon ungültige index-werte zurückgewiesen?
}
}
#[test]
#[test]
...
@@ -674,6 +676,7 @@ mod tests {
...
@@ -674,6 +676,7 @@ mod tests {
let
min_max
=
MinMax
::
new
(
bits
,
2
);
let
min_max
=
MinMax
::
new
(
bits
,
2
);
assert_eq!
(
min_max
.excess
(
0
)
.unwrap
(),
1
);
assert_eq!
(
min_max
.excess
(
0
)
.unwrap
(),
1
);
assert_eq!
(
min_max
.excess
(
1
)
.unwrap
(),
0
);
assert_eq!
(
min_max
.excess
(
1
)
.unwrap
(),
0
);
assert_eq!
(
min_max
.excess
(
2
)
.unwrap_err
(),
NodeError
::
NotANodeError
);
}
}
#[test]
#[test]
...
...
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