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
cfd2c21c
Verified
Commit
cfd2c21c
authored
7 years ago
by
David Mehren
Browse files
Options
Downloads
Patches
Plain Diff
[LOUDSTree] Implement labeled_child
Add tests for nth_child()
parent
ecac2ca7
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/trees/louds_tree.rs
+74
-11
74 additions, 11 deletions
src/trees/louds_tree.rs
with
74 additions
and
11 deletions
src/trees/louds_tree.rs
+
74
−
11
View file @
cfd2c21c
...
...
@@ -178,16 +178,19 @@ impl<L: PartialEq + Clone + Debug> SuccinctTree<LOUDSTree<L>, L> for LOUDSTree<L
}
fn
labeled_child
(
&
self
,
index
:
u64
,
label
:
L
)
->
Result
<
u64
,
NodeError
>
{
println!
(
"Foobar"
);
let
left_bound
=
self
let
child_count
=
self
.degree
(
index
)
?
;
for
i
in
1
..=
child_count
{
let
child_index
=
self
.child
(
index
,
i
)
.unwrap
();
let
mut
label_index
=
self
.rankselect
.rank_0
(
index
)
.rank_0
(
child_
index
)
.ok_or
(
NodeError
::
NotANodeError
)
?
;
let
right_bound
=
left_bound
+
self
.degree
(
index
)
?
-
1
;
for
i
in
left_bound
..
right_bound
{
let
item
=
self
.labels
.get
(
i
as
usize
)
.unwrap
();
if
label
==
*
item
{
return
Ok
(
i
);
if
self
.is_leaf
(
child_index
)
.unwrap
()
{
label_index
-=
1
;
}
let
my_label
=
self
.labels
.get
(
label_index
as
usize
)
.unwrap
()
.clone
();
if
my_label
==
label
{
return
Ok
(
child_index
);
}
}
Err
(
NodeError
::
NoSuchChildError
)
...
...
@@ -435,7 +438,6 @@ mod tests {
id_tree
.insert
(
Node
::
new
(
2
),
UnderNode
(
&
root_id
))
.unwrap
();
id_tree
.insert
(
Node
::
new
(
3
),
UnderNode
(
&
child_id
))
.unwrap
();
let
tree
:
LOUDSTree
<
i32
>
=
LOUDSTree
::
from_id_tree
(
id_tree
)
.unwrap
();
tree
.labeled_child
(
0
,
2
);
let
bitvec
=
bit_vec!
[
true
,
true
,
true
,
false
,
true
,
false
,
false
,
false
];
let
other_tree
=
LOUDSTree
::
from_bitvec
(
bitvec
)
.unwrap
();
assert_eq!
(
tree
,
other_tree
)
...
...
@@ -475,4 +477,65 @@ mod tests {
assert_eq!
(
*
bp_tree
.child_label
(
6
)
.unwrap
(),
"second_root_child"
);
assert_eq!
(
*
bp_tree
.child_label
(
7
)
.unwrap
(),
"leaf"
);
}
#[test]
fn
labeled_child
()
{
let
mut
id_tree
:
Tree
<
String
>
=
TreeBuilder
::
new
()
.with_node_capacity
(
5
)
.build
();
let
root_id
:
NodeId
=
id_tree
.insert
(
Node
::
new
(
String
::
from
(
"root"
)),
AsRoot
)
.unwrap
();
let
child_id
=
id_tree
.insert
(
Node
::
new
(
String
::
from
(
"first_root_child"
)),
UnderNode
(
&
root_id
),
)
.unwrap
();
id_tree
.insert
(
Node
::
new
(
String
::
from
(
"leaf"
)),
UnderNode
(
&
child_id
))
.unwrap
();
id_tree
.insert
(
Node
::
new
(
String
::
from
(
"second_root_child"
)),
UnderNode
(
&
root_id
),
)
.unwrap
();
let
louds_tree
=
LOUDSTree
::
from_id_tree
(
id_tree
)
.unwrap
();
assert_eq!
(
louds_tree
.labeled_child
(
1
,
String
::
from
(
"second_root_child"
))
.unwrap
(),
6
);
assert_eq!
(
louds_tree
.labeled_child
(
1
,
String
::
from
(
"first_root_child"
))
.unwrap
(),
4
);
assert_eq!
(
louds_tree
.labeled_child
(
4
,
String
::
from
(
"leaf"
))
.unwrap
(),
7
);
}
#[test]
fn
nth_child
()
{
let
bitvec
=
bit_vec!
[
true
,
true
,
true
,
true
,
false
,
true
,
false
,
true
,
false
,
false
,
false
,
false
];
let
tree
:
LOUDSTree
<
String
>
=
LOUDSTree
::
from_bitvec
(
bitvec
.clone
())
.unwrap
();
assert_eq!
(
tree
.child
(
1
,
1
)
.unwrap
(),
5
);
assert_eq!
(
tree
.child
(
1
,
2
)
.unwrap
(),
7
);
assert_eq!
(
tree
.child
(
1
,
3
)
.unwrap
(),
9
);
assert_eq!
(
tree
.child
(
5
,
1
)
.unwrap
(),
10
);
assert_eq!
(
tree
.child
(
7
,
1
)
.unwrap
(),
11
);
let
bitvec2
=
bit_vec!
[
true
,
true
,
false
,
true
,
false
,
false
];
let
tree2
:
LOUDSTree
<
String
>
=
LOUDSTree
::
from_bitvec
(
bitvec2
)
.unwrap
();
assert_eq!
(
tree2
.child
(
1
,
1
)
.unwrap
(),
3
);
assert_eq!
(
tree2
.child
(
3
,
1
)
.unwrap
(),
5
);
let
bitvec3
=
bit_vec!
[
true
,
true
,
true
,
false
,
true
,
false
,
false
,
false
];
let
tree3
:
LOUDSTree
<
String
>
=
LOUDSTree
::
from_bitvec
(
bitvec3
)
.unwrap
();
assert_eq!
(
tree3
.child
(
1
,
1
)
.unwrap
(),
4
);
assert_eq!
(
tree3
.child
(
1
,
2
)
.unwrap
(),
6
);
assert_eq!
(
tree3
.child
(
4
,
1
)
.unwrap
(),
7
);
}
}
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