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
a5778c5e
Commit
a5778c5e
authored
7 years ago
by
frederik stehli
Browse files
Options
Downloads
Patches
Plain Diff
[min_max] fixed bwd search and added tests
parent
bb930a7d
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/datastructures/min_max.rs
+58
-38
58 additions, 38 deletions
src/datastructures/min_max.rs
with
58 additions
and
38 deletions
src/datastructures/min_max.rs
+
58
−
38
View file @
a5778c5e
...
...
@@ -309,8 +309,8 @@ impl MinMax {
while
bottom_up
&&
current_node
>
0
{
if
current_node
%
2
==
0
{
if
self
.heap
[
current_node
as
usize
-
1
]
.max_excess
>=
look_for
&&
self
.heap
[
current_node
as
usize
-
1
]
.min_excess
<=
look_for
if
self
.heap
[
current_node
as
usize
-
1
]
.max_excess
>=
-
1
*
look_for
&&
self
.heap
[
current_node
as
usize
-
1
]
.min_excess
<=
-
1
*
look_for
{
bottom_up
=
false
;
top_down
=
true
;
...
...
@@ -325,34 +325,51 @@ impl MinMax {
}
while
top_down
{
if
self
.heap
[
current_node
as
usize
*
2
+
2
]
.max_excess
>=
look_for
&&
self
.heap
[
current_node
as
usize
*
2
+
2
]
.min_excess
<=
look_for
if
current_node
>=
self
.heap
.len
()
as
u64
/
2
{
top_down
=
false
;
block_search
=
true
;
}
else
{
if
self
.heap
[
current_node
as
usize
*
2
+
2
]
.max_excess
-
self
.heap
[
current_node
as
usize
*
2
+
2
]
.min_excess
>=
look_for
.abs
()
{
current_node
=
current_node
*
2
+
2
;
}
else
if
self
.heap
[
current_node
as
usize
*
2
+
1
]
.max_excess
>=
look_for
&&
self
.heap
[
current_node
as
usize
*
2
+
1
]
.min_excess
<=
look_for
}
else
if
self
.heap
[
current_node
as
usize
*
2
+
1
]
.max_excess
-
self
.heap
[
current_node
as
usize
*
2
+
1
]
.min_excess
>=
look_for
.abs
()
{
current_node
=
current_node
*
2
+
1
;
}
else
{
//todo konnte nicht gefunden werden!!
}
}
}
if
current_node
<
self
.heap
.len
()
as
u64
/
2
{
/*while top_down {
if current_node <= self.heap.len() as u64 / 2 {
top_down = false;
block_search = true;
} else {
if self.heap[current_node as usize * 2 + 2].max_excess >= -1 * look_for
&& self.heap[current_node as usize * 2 + 2].min_excess <= -1 * look_for
{
current_node = current_node * 2 + 2;
} else if self.heap[current_node as usize * 2 + 1].max_excess >= -1 * look_for
&& self.heap[current_node as usize * 2 + 1].min_excess <= -1 * look_for
{
current_node = current_node * 2 + 1;
} else {
//todo konnte nicht gefunden werden!!
}
}
}*/
if
block_search
{
block_no
=
current_node
-
(
self
.heap
.len
()
/
2
)
as
u64
;
begin_of_block
=
block_no
*
self
.block_size
;
end_of_block
=
begin_of_block
+
self
.block_size
-
1
;
position
=
end_of_block
;
while
!
found
&&
position
>=
end
_of_block
{
while
!
found
&&
position
>=
begin
_of_block
{
if
self
.bits
[
position
+
1
]
{
look_for
-=
1
;
}
else
{
look_for
+=
1
;
}
else
{
look_for
-=
1
;
}
if
look_for
==
0
{
found
=
true
;
...
...
@@ -366,7 +383,7 @@ impl MinMax {
Ok
(
position
)
}
else
{
//todo konnte nicht gefunden werden!!
Ok
(
1
)
Ok
(
1
0000000
)
}
}
...
...
@@ -536,11 +553,14 @@ mod tests {
}
#[test]
#[ignore]
fn
test_bwd_search
()
{
let
bits
=
bit_vec!
[
true
,
true
,
true
,
false
,
true
,
false
,
false
,
true
,
true
,
false
,
false
,
false
];
let
min_max
=
MinMax
::
new
(
bits
,
4
);
assert_eq!
(
min_max
.bwd_search
(
7
,
1
)
.unwrap
(),
4
);
assert_eq!
(
min_max
.bwd_search
(
5
,
-
1
)
.unwrap
(),
0
);
assert_eq!
(
min_max
.bwd_search
(
10
,
0
)
.unwrap
(),
6
);
}
#[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