Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSE-108c Project 1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cheuk Pui Lam
CSE-108c Project 1
Commits
1efe51c5
Unverified
Commit
1efe51c5
authored
2 months ago
by
Cheuk Pui Lam
Browse files
Options
Downloads
Patches
Plain Diff
feat(client-brc): Finished best cover function
parent
eacf5b96
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
client-brc/src/brc.rs
+35
-6
35 additions, 6 deletions
client-brc/src/brc.rs
with
35 additions
and
6 deletions
client-brc/src/brc.rs
+
35
−
6
View file @
1efe51c5
pub
mod
brc_tree
{
#![allow(dead_code)]
use
std
::{
io
::
Write
,
path
::
Path
};
use
std
::{
io
::
Write
,
path
::
Path
,
vec
};
use
indexmap
::
IndexMap
;
...
...
@@ -115,6 +115,38 @@ pub mod brc_tree {
}
Ok
(())
}
pub
fn
possible_covers
(
&
self
,
min
:
isize
,
max
:
isize
)
->
Vec
<
Subtree
>
{
match
&
self
.0
{
Some
(
node
)
=>
{
if
node
.min
>
max
||
node
.max
<
min
{
return
vec!
[];
}
if
min
<=
node
.min
&&
max
>=
node
.max
{
return
vec!
[
self
.clone
()];
}
let
mut
left
=
node
.left
.possible_covers
(
min
,
max
);
let
right
=
node
.right
.possible_covers
(
min
,
max
);
left
.extend
(
right
);
left
}
None
=>
vec!
[],
}
}
pub
fn
range
(
&
self
)
->
(
isize
,
isize
)
{
match
&
self
.0
{
Some
(
node
)
=>
(
node
.min
,
node
.max
),
None
=>
(
0
,
0
),
}
}
}
#[test]
fn
test_possible_covers
()
{
let
tree
=
parse_from_file
(
std
::
path
::
Path
::
new
(
"../brc_table.partitions"
))
.unwrap
();
let
covers
=
tree
.possible_covers
(
0
,
111000
);
println!
(
"{:?}"
,
tree
);
println!
(
"{:?}"
,
covers
.iter
()
.map
(|
x
|
x
.range
())
.collect
::
<
Vec
<
_
>>
());
}
pub
fn
parse_from_file
(
file_name
:
&
Path
)
->
anyhow
::
Result
<
Subtree
>
{
let
contents
=
std
::
fs
::
read_to_string
(
file_name
)
?
;
...
...
@@ -128,7 +160,6 @@ pub mod brc_tree {
}
let
(
min_max
,
rest
)
=
s
.split_at
(
s
.find
(
'('
)
.unwrap
());
println!
(
"MM:{:?}"
,
min_max
);
let
(
min
,
max
)
=
{
let
mut
parts
=
min_max
.split
(
','
);
(
...
...
@@ -151,10 +182,8 @@ pub mod brc_tree {
}
}
let
left_str
=
&
rest
[
1
..
split_index
];
let
right_str
=
&
rest
[
split_index
+
2
..
rest
.len
()
-
2
];
let
left
=
parse_from_string
(
left_str
.to_string
())
?
;
let
right
=
parse_from_string
(
right_str
.to_string
())
?
;
let
left
=
parse_from_string
(
rest
[
1
..
split_index
]
.to_string
())
?
;
let
right
=
parse_from_string
(
rest
[
split_index
+
2
..
rest
.len
()
-
2
]
.to_string
())
?
;
Ok
(
Subtree
(
Some
(
Box
::
new
(
Node
{
min
,
...
...
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