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
dc3bb558
Commit
dc3bb558
authored
7 years ago
by
Kevin Kaßelmann
Browse files
Options
Downloads
Patches
Plain Diff
Test label operations
parent
7fd4212a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/common/succinct_tree.rs
+4
-4
4 additions, 4 deletions
src/common/succinct_tree.rs
src/trees/bp_tree.rs
+71
-8
71 additions, 8 deletions
src/trees/bp_tree.rs
with
75 additions
and
12 deletions
src/common/succinct_tree.rs
+
4
−
4
View file @
dc3bb558
...
...
@@ -4,14 +4,14 @@ use common::errors::NodeError;
use
id_tree
::
Tree
;
use
std
::
fmt
::
Debug
;
pub
trait
SuccinctTree
<
T
,
L
abel
>
:
Debug
{
pub
trait
SuccinctTree
<
T
,
L
>
:
Debug
{
fn
is_leaf
(
&
self
,
index
:
u64
)
->
Result
<
bool
,
NodeError
>
;
fn
parent
(
&
self
,
index
:
u64
)
->
Result
<
u64
,
NodeError
>
;
fn
first_child
(
&
self
,
index
:
u64
)
->
Result
<
u64
,
NodeError
>
;
fn
next_sibling
(
&
self
,
index
:
u64
)
->
Result
<
u64
,
NodeError
>
;
fn
from_id_tree
(
tree
:
Tree
<
L
abel
>
)
->
Result
<
T
,
EmptyTreeError
>
;
fn
child_label
(
&
self
,
index
:
u64
)
->
Result
<&
L
abel
,
NodeError
>
;
fn
labeled_child
(
&
self
,
index
:
u64
,
label
:
L
abel
)
->
Result
<
u64
,
NodeError
>
;
fn
from_id_tree
(
tree
:
Tree
<
L
>
)
->
Result
<
T
,
EmptyTreeError
>
;
fn
child_label
(
&
self
,
index
:
u64
)
->
Result
<&
L
,
NodeError
>
;
fn
labeled_child
(
&
self
,
index
:
u64
,
label
:
L
)
->
Result
<
u64
,
NodeError
>
;
/// Prüft ob ein Bitvector ein gültiger SuccinctTree ist, anhand des gültigen Exzesses und
/// der Anzahl öffnender und schließender Klammern
...
...
This diff is collapsed.
Click to expand it.
src/trees/bp_tree.rs
+
71
−
8
View file @
dc3bb558
...
...
@@ -45,19 +45,19 @@ use std::fs;
use
std
::
fs
::
File
;
use
std
::
io
::
Write
;
pub
struct
BPTree
<
L
>
{
pub
struct
BPTree
<
L
:
PartialEq
+
Clone
+
Debug
>
{
labels
:
Vec
<
L
>
,
rankselect
:
RankSelect
,
minmax
:
MinMax
,
}
impl
<
L
:
PartialEq
+
Clone
>
PartialEq
for
BPTree
<
L
>
{
impl
<
L
:
PartialEq
+
Clone
+
Debug
>
PartialEq
for
BPTree
<
L
>
{
fn
eq
(
&
self
,
other
:
&
Self
)
->
bool
{
self
.rankselect
.bits
()
==
other
.rankselect
.bits
()
}
}
impl
<
L
:
PartialEq
+
Clone
>
SuccinctTree
<
BPTree
<
L
>
,
L
>
for
BPTree
<
L
>
{
impl
<
L
:
PartialEq
+
Clone
+
Debug
>
SuccinctTree
<
BPTree
<
L
>
,
L
>
for
BPTree
<
L
>
{
/// Checks if a node is a leaf.
/// # Arguments
/// * `index` The index of the node to check
...
...
@@ -172,13 +172,13 @@ impl<L: PartialEq + Clone> SuccinctTree<BPTree<L>, L> for BPTree<L> {
}
}
impl
<
L
:
PartialEq
+
Clone
>
Debug
for
BPTree
<
L
>
{
impl
<
L
:
PartialEq
+
Clone
+
Debug
>
Debug
for
BPTree
<
L
>
{
fn
fmt
(
&
self
,
f
:
&
mut
Formatter
)
->
fmt
::
Result
{
write!
(
f
,
"BPTree
\n
{{ bits: {:?} }}"
,
self
.rankselect
.bits
())
}
}
impl
<
L
:
PartialEq
+
Clone
>
BPTree
<
L
>
{
impl
<
L
:
PartialEq
+
Clone
+
Debug
>
BPTree
<
L
>
{
/// Returns whether the index is valid
/// # Arguments
/// * `index` The index which should be valid
...
...
@@ -498,8 +498,71 @@ mod tests {
#[test]
fn
child_label
()
{
let
id_tree
:
Tree
<
i32
>
=
TreeBuilder
::
new
()
.with_node_capacity
(
5
)
.build
();
let
bp_tree
:
Result
<
BPTree
<
i32
>
,
EmptyTreeError
>
=
BPTree
::
from_id_tree
(
id_tree
);
assert_eq!
(
bp_tree
.unwrap_err
(),
EmptyTreeError
);
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
bp_tree
=
BPTree
::
from_id_tree
(
id_tree
)
.unwrap
();
assert_eq!
(
*
bp_tree
.child_label
(
0
)
.unwrap
(),
"root"
);
assert_eq!
(
*
bp_tree
.child_label
(
1
)
.unwrap
(),
"first_root_child"
);
assert_eq!
(
*
bp_tree
.child_label
(
2
)
.unwrap
(),
"leaf"
);
assert_eq!
(
*
bp_tree
.child_label
(
3
)
.unwrap
(),
"second_root_child"
);
assert_eq!
(
bp_tree
.child_label
(
4
)
.err
()
.unwrap
(),
NodeError
::
NoLabelError
);
}
#[test]
#[ignore]
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
bp_tree
=
BPTree
::
from_id_tree
(
id_tree
)
.unwrap
();
assert_eq!
(
bp_tree
.labeled_child
(
0
,
String
::
from
(
"second_root_child"
))
.unwrap
(),
5
);
assert_eq!
(
bp_tree
.labeled_child
(
0
,
String
::
from
(
"first_root_child"
))
.unwrap
(),
1
);
assert_eq!
(
bp_tree
.labeled_child
(
1
,
String
::
from
(
"leaf"
))
.unwrap
(),
3
);
}
}
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