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
5194e00d
Unverified
Commit
5194e00d
authored
2 months ago
by
Cheuk Pui Lam
Browse files
Options
Downloads
Patches
Plain Diff
feat(client-brc): Added function to convert brc to urc
parent
1efe51c5
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
+61
-5
61 additions, 5 deletions
client-brc/src/brc.rs
with
61 additions
and
5 deletions
client-brc/src/brc.rs
+
61
−
5
View file @
5194e00d
pub
mod
brc_tree
{
#![allow(dead_code)]
use
std
::{
io
::
Write
,
path
::
Path
,
vec
};
use
std
::{
collections
::
VecDeque
,
io
::
Write
,
path
::
Path
,
vec
};
use
indexmap
::
IndexMap
;
...
...
@@ -116,7 +116,8 @@ pub mod brc_tree {
Ok
(())
}
pub
fn
possible_covers
(
&
self
,
min
:
isize
,
max
:
isize
)
->
Vec
<
Subtree
>
{
pub
fn
covers
(
&
self
,
min
:
isize
,
max
:
isize
)
->
Vec
<
Subtree
>
{
// Returns the set of nodes that covers the entire range
match
&
self
.0
{
Some
(
node
)
=>
{
if
node
.min
>
max
||
node
.max
<
min
{
...
...
@@ -125,8 +126,8 @@ pub mod brc_tree {
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
);
let
mut
left
=
node
.left
.covers
(
min
,
max
);
let
right
=
node
.right
.covers
(
min
,
max
);
left
.extend
(
right
);
left
}
...
...
@@ -140,11 +141,22 @@ pub mod brc_tree {
None
=>
(
0
,
0
),
}
}
pub
fn
level
(
&
self
)
->
isize
{
match
&
self
.0
{
Some
(
node
)
=>
{
let
left
=
node
.left
.level
();
let
right
=
node
.right
.level
();
1
+
left
.max
(
right
)
}
None
=>
-
1
,
}
}
}
#[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
);
let
covers
=
tree
.covers
(
0
,
111000
);
println!
(
"{:?}"
,
tree
);
println!
(
"{:?}"
,
covers
.iter
()
.map
(|
x
|
x
.range
())
.collect
::
<
Vec
<
_
>>
());
}
...
...
@@ -153,6 +165,50 @@ pub mod brc_tree {
parse_from_string
(
contents
)
}
pub
fn
brc_to_urc
(
vec
:
Vec
<
Subtree
>
)
->
Vec
<
Subtree
>
{
// assume vec is sorted by level
let
mut
deq
=
VecDeque
::
from
(
vec
);
let
max_level
=
deq
[
deq
.len
()
-
1
]
.level
();
let
mut
urc
=
vec!
[];
let
mut
seen
=
VecDeque
::
from_iter
(
0
..
max_level
+
1
);
while
!
deq
.is_empty
()
{
let
node
=
deq
.pop_front
()
.unwrap
()
.to_owned
();
if
node
.0
.is_none
()
{
continue
;
}
match
node
.level
()
{
i
if
i
<
seen
[
0
]
=>
{
urc
.push
(
node
);
}
i
if
i
==
seen
[
0
]
=>
{
seen
.pop_front
();
urc
.push
(
node
);
}
_
=>
{
deq
.push_front
(
node
.clone
()
.0
.unwrap
()
.left
);
deq
.push_front
(
node
.0
.unwrap
()
.right
);
}
}
}
urc
}
#[test]
fn
test_brc_to_urc
()
{
let
tree
=
from_sorted_list
(
indexmap
::
indexmap!
{
0
=>
vec!
[
"a"
.to_string
()],
1
=>
vec!
[
"a"
.to_string
()],
2
=>
vec!
[
"b"
.to_string
()],
3
=>
vec!
[
"c"
.to_string
()],
4
=>
vec!
[
"d"
.to_string
()],
5
=>
vec!
[
"e"
.to_string
()],
6
=>
vec!
[
"f"
.to_string
()],
7
=>
vec!
[
"g"
.to_string
()],
});
let
urc
=
brc_to_urc
(
tree
.covers
(
2
,
7
));
println!
(
"{:?}"
,
urc
.iter
()
.map
(|
x
|
x
.range
())
.collect
::
<
Vec
<
_
>>
());
}
fn
parse_from_string
(
s
:
String
)
->
anyhow
::
Result
<
Subtree
>
{
let
s
=
s
.trim
();
if
s
.is_empty
()
{
...
...
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