Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ece459-w23-a2
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
Patrick Lam
ece459-w23-a2
Commits
2eb11ed1
Commit
2eb11ed1
authored
2 years ago
by
Patrick Lam
Browse files
Options
Downloads
Patches
Plain Diff
refactor out reverse_dict
parent
e2b2dda5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main.rs
+3
-0
3 additions, 0 deletions
src/main.rs
src/packages/parser.rs
+12
-6
12 additions, 6 deletions
src/packages/parser.rs
with
15 additions
and
6 deletions
src/main.rs
+
3
−
0
View file @
2eb11ed1
...
...
@@ -16,4 +16,7 @@ fn main() {
let
(
double_dict
,
triple_dict
,
all_token_list
)
=
packages
::
parser
::
parse_raw
(
args
.raw
);
packages
::
parser
::
print_dict
(
triple_dict
);
// let's say that the cutoff is 72 for Linux2k.log.
// check all of the 2-grams from the less-frequent 3-grams
}
This diff is collapsed.
Click to expand it.
src/packages/parser.rs
+
12
−
6
View file @
2eb11ed1
...
...
@@ -243,9 +243,10 @@ fn test_parse_raw() {
assert_eq!
(
triple_dict
,
triple_dict_oracle
);
}
pub
fn
print_dict
(
d
:
HashMap
<
String
,
i32
>
)
{
let
mut
reverse_d
:
HashMap
<
i32
,
Vec
<
String
>>
=
HashMap
::
new
();
let
mut
key_set
=
BTreeSet
::
new
();
/// standard mapreduce invert map: given {<k1, v1>, <k2, v2>, <k3, v1>}, returns ([v1, v2] (sorted), {<v1, [k1, k3]>, <v2, [k2]>})
pub
fn
reverse_dict
(
d
:
HashMap
<
String
,
i32
>
)
->
(
BTreeSet
<
i32
>
,
HashMap
<
i32
,
Vec
<
String
>>
)
{
let
mut
reverse_d
:
HashMap
<
i32
,
Vec
<
String
>>
=
HashMap
::
new
();
let
mut
val_set
:
BTreeSet
<
i32
>
=
BTreeSet
::
new
();
for
(
key
,
val
)
in
d
.iter
()
{
if
reverse_d
.contains_key
(
val
)
{
...
...
@@ -253,13 +254,18 @@ pub fn print_dict(d: HashMap<String, i32>) {
existing_keys
.push
(
key
.to_string
());
}
else
{
reverse_d
.insert
(
*
val
,
vec!
[
key
.to_string
()]);
key
_set
.insert
(
val
);
val
_set
.insert
(
*
val
);
}
}
return
(
val_set
,
reverse_d
);
}
pub
fn
print_dict
(
d
:
HashMap
<
String
,
i32
>
)
{
let
(
val_set
,
reverse_d
)
=
reverse_dict
(
d
);
println!
(
"printing dict"
);
for
key
in
&
key
_set
{
println!
(
"{}: {:?}"
,
key
,
reverse_d
.get
(
key
)
.unwrap
());
for
val
in
&
val
_set
{
println!
(
"{}: {:?}"
,
val
,
reverse_d
.get
(
val
)
.unwrap
());
}
println!
(
"---"
);
}
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