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
84f0e3b8
Unverified
Commit
84f0e3b8
authored
2 months ago
by
Cheuk Pui Lam
Browse files
Options
Downloads
Patches
Plain Diff
fix(client-brc): fixed edge cases in urc conversion
parent
5194e00d
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
+42
-9
42 additions, 9 deletions
client-brc/src/brc.rs
with
42 additions
and
9 deletions
client-brc/src/brc.rs
+
42
−
9
View file @
84f0e3b8
...
...
@@ -103,11 +103,9 @@ pub mod brc_tree {
pub
fn
write_structure
(
&
self
,
mut
file
:
&
std
::
fs
::
File
)
->
anyhow
::
Result
<
()
>
{
match
&
self
.0
{
Some
(
node
)
=>
{
file
.write_all
(
format!
(
"{},{}"
,
node
.min
,
node
.max
)
.as_bytes
())
?
;
file
.write_all
(
"("
.as_bytes
())
?
;
file
.write_all
(
format!
(
"{},{}("
,
node
.min
,
node
.max
)
.as_bytes
())
?
;
node
.left
.write_structure
(
file
)
?
;
file
.write_all
(
")"
.as_bytes
())
?
;
file
.write_all
(
"("
.as_bytes
())
?
;
file
.write_all
(
")("
.as_bytes
())
?
;
node
.right
.write_structure
(
file
)
?
;
file
.write_all
(
");"
.as_bytes
())
?
;
}
...
...
@@ -142,9 +140,19 @@ pub mod brc_tree {
}
}
pub
fn
range_level
(
&
self
)
->
(
isize
,
isize
,
isize
)
{
match
&
self
.0
{
Some
(
node
)
=>
(
node
.min
,
node
.max
,
self
.level
()),
None
=>
(
0
,
0
,
0
),
}
}
pub
fn
level
(
&
self
)
->
isize
{
match
&
self
.0
{
Some
(
node
)
=>
{
if
node
.max
==
node
.min
{
return
0
;
}
let
left
=
node
.left
.level
();
let
right
=
node
.right
.level
();
1
+
left
.max
(
right
)
...
...
@@ -156,21 +164,35 @@ pub mod brc_tree {
#[test]
fn
test_possible_covers
()
{
let
tree
=
parse_from_file
(
std
::
path
::
Path
::
new
(
"../brc_table.partitions"
))
.unwrap
();
let
covers
=
tree
.covers
(
0
,
111000
);
let
mut
covers
=
tree
.covers
(
0
,
111000
);
println!
(
"{:?}"
,
tree
);
println!
(
"{:?}"
,
covers
.iter
()
.map
(|
x
|
x
.range
())
.collect
::
<
Vec
<
_
>>
());
covers
.sort_by_key
(|
a
|
a
.level
());
println!
(
"{:?}"
,
brc_to_urc
(
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
)
?
;
parse_from_string
(
contents
)
}
impl
PartialEq
for
Subtree
{
fn
eq
(
&
self
,
other
:
&
Self
)
->
bool
{
self
.range
()
==
other
.range
()
}
}
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
);
let
mut
urc
:
Vec
<
Subtree
>
=
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
()
{
...
...
@@ -178,11 +200,15 @@ pub mod brc_tree {
}
match
node
.level
()
{
i
if
i
<
seen
[
0
]
=>
{
urc
.push
(
node
);
if
!
urc
.contains
(
&
node
)
{
urc
.push
(
node
);
}
}
i
if
i
==
seen
[
0
]
=>
{
seen
.pop_front
();
urc
.push
(
node
);
if
!
urc
.contains
(
&
node
)
{
urc
.push
(
node
);
}
}
_
=>
{
deq
.push_front
(
node
.clone
()
.0
.unwrap
()
.left
);
...
...
@@ -209,6 +235,13 @@ pub mod brc_tree {
println!
(
"{:?}"
,
urc
.iter
()
.map
(|
x
|
x
.range
())
.collect
::
<
Vec
<
_
>>
());
}
impl
TryInto
<
Subtree
>
for
String
{
type
Error
=
anyhow
::
Error
;
fn
try_into
(
self
)
->
Result
<
Subtree
,
Self
::
Error
>
{
parse_from_string
(
self
)
}
}
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