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
00a10c91
Verified
Commit
00a10c91
authored
7 years ago
by
David Mehren
Browse files
Options
Downloads
Patches
Plain Diff
[BPTree] Add serialization/deserialization
parent
95ee30ba
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
Cargo.toml
+4
-1
4 additions, 1 deletion
Cargo.toml
src/lib.rs
+3
-0
3 additions, 0 deletions
src/lib.rs
src/trees/bp_tree.rs
+45
-2
45 additions, 2 deletions
src/trees/bp_tree.rs
testdata/bptree_invalid.testdata
+0
-0
0 additions, 0 deletions
testdata/bptree_invalid.testdata
with
52 additions
and
3 deletions
Cargo.toml
+
4
−
1
View file @
00a10c91
...
@@ -8,3 +8,6 @@ bv = "0.7"
...
@@ -8,3 +8,6 @@ bv = "0.7"
bio
=
"0.19.0"
bio
=
"0.19.0"
id_tree
=
"1.3.0"
id_tree
=
"1.3.0"
failure
=
"0.1.1"
failure
=
"0.1.1"
serde
=
"1.0.64"
serde_derive
=
"1.0.64"
bincode
=
"1.0.0"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/lib.rs
+
3
−
0
View file @
00a10c91
...
@@ -3,6 +3,9 @@ extern crate bv;
...
@@ -3,6 +3,9 @@ extern crate bv;
extern
crate
id_tree
;
extern
crate
id_tree
;
#[macro_use]
#[macro_use]
extern
crate
failure
;
extern
crate
failure
;
#[macro_use]
extern
crate
serde_derive
;
extern
crate
bincode
;
pub
mod
common
;
pub
mod
common
;
pub
mod
trees
;
pub
mod
trees
;
This diff is collapsed.
Click to expand it.
src/trees/bp_tree.rs
+
45
−
2
View file @
00a10c91
use
bincode
::{
deserialize
,
serialize
};
use
bio
::
data_structures
::
rank_select
::
RankSelect
;
use
bio
::
data_structures
::
rank_select
::
RankSelect
;
use
bv
::{
BitVec
,
BitsMut
};
use
bv
::{
BitVec
,
BitsMut
};
use
common
::
succinct_tree
::
SuccinctTree
;
use
common
::
succinct_tree
::
SuccinctTree
;
use
failure
::
Error
;
use
failure
::
{
Error
,
ResultExt
}
;
use
id_tree
::
Tree
;
use
id_tree
::
Tree
;
use
std
::
fmt
;
use
std
::
fmt
;
use
std
::
fmt
::
Debug
;
use
std
::
fmt
::
Debug
;
use
std
::
fmt
::
Formatter
;
use
std
::
fmt
::
Formatter
;
use
std
::
fs
;
use
std
::
fs
::
File
;
use
std
::
io
::
Write
;
#[derive(Serialize,
Deserialize)]
pub
struct
BPTree
{
pub
struct
BPTree
{
bits
:
BitVec
<
u8
>
,
bits
:
BitVec
<
u8
>
,
rankselect
:
RankSelect
,
rankselect
:
RankSelect
,
rminmax
:
String
,
rminmax
:
String
,
}
}
impl
PartialEq
for
BPTree
{
fn
eq
(
&
self
,
other
:
&
BPTree
)
->
bool
{
self
.bits
==
other
.bits
}
}
impl
SuccinctTree
<
BPTree
>
for
BPTree
{
impl
SuccinctTree
<
BPTree
>
for
BPTree
{
fn
is_leaf
(
&
self
,
index
:
u64
)
->
bool
{
fn
is_leaf
(
&
self
,
index
:
u64
)
->
bool
{
unimplemented!
()
unimplemented!
()
...
@@ -64,6 +75,19 @@ impl BPTree {
...
@@ -64,6 +75,19 @@ impl BPTree {
rminmax
:
"foo"
.to_string
(),
rminmax
:
"foo"
.to_string
(),
})
})
}
}
pub
fn
from_file
(
path
:
String
)
->
Result
<
BPTree
,
Error
>
{
let
file
=
fs
::
read
(
path
)
.context
(
"Could not read saved tree."
)
?
;
let
tree
:
BPTree
=
deserialize
(
&
file
)
.context
(
"Error while deserializing tree."
)
?
;
Ok
(
tree
)
}
pub
fn
save_to
(
&
self
,
path
:
String
)
->
Result
<
(),
Error
>
{
let
encoded
=
serialize
(
&
self
)
.context
(
"Error while serializing tree."
)
?
;
let
mut
file
=
File
::
create
(
path
)
.context
(
"Could not save tree."
)
?
;
file
.write_all
(
&
encoded
)
?
;
Ok
(())
}
}
}
#[cfg(test)]
#[cfg(test)]
...
@@ -84,7 +108,26 @@ mod tests {
...
@@ -84,7 +108,26 @@ mod tests {
#[test]
#[test]
#[should_panic(expected
=
"ErrorMessage { msg:
\"
Bit vector not valid.
\"
}"
)]
#[should_panic(expected
=
"ErrorMessage { msg:
\"
Bit vector not valid.
\"
}"
)]
fn
new_from_bitvec_invalid
()
{
fn
new_from_bitvec_invalid
()
{
let
mut
bitvec
=
BitVec
::
new_fill
(
false
,
2
);
let
bitvec
=
BitVec
::
new_fill
(
false
,
2
);
BPTree
::
from_bitvec
(
bitvec
.clone
())
.unwrap
();
BPTree
::
from_bitvec
(
bitvec
.clone
())
.unwrap
();
}
}
#[test]
fn
save_load
()
{
let
tree
=
BPTree
::
stub_create
();
tree
.save_to
(
"testdata/bptree.testdata"
.to_string
())
.unwrap
();
let
result
=
BPTree
::
from_file
(
"testdata/bptree.testdata"
.to_string
())
.unwrap
();
assert_eq!
(
tree
,
result
,
"The loaded tree is not equal to the original one."
);
}
#[test]
#[should_panic(expected
=
"Error while deserializing tree."
)]
fn
load_invaild
()
{
BPTree
::
from_file
(
"testdata/bptree_invalid.testdata"
.to_string
())
.unwrap
();
}
}
}
This diff is collapsed.
Click to expand it.
testdata/bptree_invalid.testdata
0 → 100644
+
0
−
0
View file @
00a10c91
File added
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