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
d940a961
Unverified
Commit
d940a961
authored
2 months ago
by
Cheuk Pui Lam
Browse files
Options
Downloads
Patches
Plain Diff
(main):Started BRC implementation
parent
8b165c03
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Cargo.lock
+4
-0
4 additions, 0 deletions
Cargo.lock
Cargo.toml
+1
-1
1 addition, 1 deletion
Cargo.toml
client-brc/Cargo.toml
+6
-0
6 additions, 0 deletions
client-brc/Cargo.toml
client-brc/src/main.rs
+98
-0
98 additions, 0 deletions
client-brc/src/main.rs
with
109 additions
and
1 deletion
Cargo.lock
+
4
−
0
View file @
d940a961
...
...
@@ -347,6 +347,10 @@ dependencies = [
"url",
]
[[package]]
name = "client-brc"
version = "0.1.0"
[[package]]
name = "colorchoice"
version = "1.0.3"
...
...
This diff is collapsed.
Click to expand it.
Cargo.toml
+
1
−
1
View file @
d940a961
...
...
@@ -4,5 +4,5 @@ resolver = "2"
members
=
[
"client"
,
"server"
,
"crypto-utils"
,
"crypto-utils"
,
"client-brc"
,
]
This diff is collapsed.
Click to expand it.
client-brc/Cargo.toml
0 → 100644
+
6
−
0
View file @
d940a961
[package]
name
=
"client-brc"
version
=
"0.1.0"
edition
=
"2021"
[dependencies]
This diff is collapsed.
Click to expand it.
client-brc/src/main.rs
0 → 100644
+
98
−
0
View file @
d940a961
use
std
::{
collections
::
HashMap
,
vec
};
/// A node in the binary tree.
#[derive(Debug,
Clone)]
struct
Node
<
T
:
Ord
>
{
min
:
T
,
max
:
T
,
left
:
Subtree
<
T
>
,
right
:
Subtree
<
T
>
,
}
/// A possibly-empty subtree.
#[derive(Debug,
Clone)]
struct
Subtree
<
T
:
Ord
>
(
Option
<
Box
<
Node
<
T
>>>
);
impl
Subtree
<
usize
>
{
fn
to_hashtable
(
&
self
)
->
HashMap
<
(
usize
,
usize
),
Subtree
<
usize
>>
{
let
mut
hashtable
=
HashMap
::
new
();
match
&
self
.0
{
Some
(
node
)
=>
{
let
left
=
node
.left
.to_hashtable
();
let
right
=
node
.right
.to_hashtable
();
if
node
.left
.0
.is_some
()
&&
node
.right
.0
.is_some
(){
hashtable
.insert
((
node
.min
,
node
.max
),
Subtree
(
Some
(
Box
::
new
(
Node
{
min
:
node
.left
.0
.as_ref
()
.unwrap
()
.min
,
max
:
node
.right
.0
.as_ref
()
.unwrap
()
.max
,
left
:
node
.left
.clone
(),
right
:
node
.right
.clone
(),
}))));
}
hashtable
.insert
((
node
.min
,
node
.max
),
Subtree
(
Some
(
Box
::
new
(
Node
{
min
:
node
.min
,
max
:
node
.max
,
left
:
node
.left
.clone
(),
right
:
node
.right
.clone
(),
}))));
for
(
key
,
value
)
in
left
.iter
()
{
hashtable
.insert
(
*
key
,
value
.clone
());
}
for
(
key
,
value
)
in
right
.iter
()
{
hashtable
.insert
(
*
key
,
value
.clone
());
}
},
None
=>
{}
}
hashtable
}
}
fn
main
()
{
let
vec
:
Vec
<
usize
>
=
vec!
[
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
];
// println!("{:?}", from_sorted_list(vec).to_hashtable());
for
(
key
,
value
)
in
from_sorted_list
(
vec
)
.to_hashtable
()
.iter
()
{
println!
(
"{:?} / {:?}"
,
key
,
value
);
// map.remove(key);
}
}
fn
from_sorted_list
(
vec
:
Vec
<
usize
>
)
->
Subtree
<
usize
>
{
let
len
=
vec
.len
();
if
len
==
1
{
return
Subtree
(
Some
(
Box
::
new
(
Node
{
min
:
vec
[
0
],
max
:
vec
[
0
],
left
:
Subtree
(
None
),
right
:
Subtree
(
None
),
})));
}
if
len
==
0
{
return
Subtree
(
None
);
}
let
mid
=
len
/
2
;
let
left
=
from_sorted_list
(
vec
[
..
mid
]
.to_vec
());
let
right
=
from_sorted_list
(
vec
[
mid
..
]
.to_vec
());
let
min
=
match
&
left
.0
{
Some
(
node
)
=>
node
.min
,
None
=>
match
&
right
.0
{
Some
(
node
)
=>
node
.min
,
None
=>
vec
[
0
],
},
};
let
max
=
match
&
right
.0
{
Some
(
node
)
=>
node
.max
,
None
=>
match
&
left
.0
{
Some
(
node
)
=>
node
.max
,
None
=>
vec
[
len
-
1
],
},
};
Subtree
(
Some
(
Box
::
new
(
Node
{
left
,
right
,
min
,
max
,
})))
}
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