Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs267
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
recolic-hust
cs267
Commits
0a7afb0b
There was an error fetching the commit references. Please try again later.
Commit
0a7afb0b
authored
6 years ago
by
Recolic Keghart
Browse files
Options
Downloads
Patches
Plain Diff
updated
parent
e0ac51b3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hw3/dist_kv_store.hpp
+31
-11
31 additions, 11 deletions
hw3/dist_kv_store.hpp
hw3/hash_map.hpp
+1
-2
1 addition, 2 deletions
hw3/hash_map.hpp
with
32 additions
and
13 deletions
hw3/dist_kv_store.hpp
+
31
−
11
View file @
0a7afb0b
...
@@ -55,7 +55,7 @@ public:
...
@@ -55,7 +55,7 @@ public:
std
::
pair
<
bool
,
value_type
>
operator
[](
const
key_type
&
k
)
const
{
std
::
pair
<
bool
,
value_type
>
operator
[](
const
key_type
&
k
)
const
{
auto
target_rank
=
find_rank_for_hash
(
find_hash_for_ele
(
k
));
auto
target_rank
=
find_rank_for_hash
(
find_hash_for_ele
(
k
));
if
(
my_rank
==
target_rank
)
{
if
(
my_rank
==
target_rank
)
{
return
std
::
make_pair
(
true
,
do_find
(
k
));
return
std
::
make_pair
(
true
,
*
do_find
(
k
));
}
}
else
{
else
{
auto
res
=
upcxx
::
rpc
(
target_rank
,
std
::
bind
(
&
this_type
::
do_rpc_find
,
this
,
k
)).
wait
();
auto
res
=
upcxx
::
rpc
(
target_rank
,
std
::
bind
(
&
this_type
::
do_rpc_find
,
this
,
k
)).
wait
();
...
@@ -65,6 +65,21 @@ public:
...
@@ -65,6 +65,21 @@ public:
}
}
}
}
bool
push_if_is_mine
(
const
key_type
&
k
,
const
value_type
&
v
)
{
auto
target_rank
=
find_rank_for_hash
(
find_hash_for_ele
(
k
));
if
(
my_rank
==
target_rank
)
{
do_insert
(
k
,
v
);
}
return
my_rank
==
target_rank
;
}
std
::
pair
<
bool
,
value_type
>
find_if_is_mine
(
const
key_type
&
k
)
{
auto
target_rank
=
find_rank_for_hash
(
find_hash_for_ele
(
k
));
if
(
my_rank
==
target_rank
)
return
std
::
make_pair
(
true
,
*
do_find
(
k
));
else
return
std
::
make_pair
(
false
,
value_type
{});
}
private
:
private
:
bool
do_rpc_insert
(
key_type
k
,
value_type
v
)
{
bool
do_rpc_insert
(
key_type
k
,
value_type
v
)
{
...
@@ -79,10 +94,11 @@ private:
...
@@ -79,10 +94,11 @@ private:
}
}
auto
do_rpc_find
(
key_type
k
)
const
{
auto
do_rpc_find
(
key_type
k
)
const
{
try
{
try
{
return
rpc_find_result
{
true
,
true
,
do_find
(
k
)};
const
auto
*
res
=
do_find
(
k
,
true
);
}
if
(
res
)
catch
(
std
::
out_of_range
&
o
)
{
return
rpc_find_result
{
true
,
true
,
*
res
};
return
rpc_find_result
{
false
,
true
,
value_type
{}};
else
return
rpc_find_result
{
false
,
true
,
value_type
{}};
}
}
catch
(
std
::
exception
&
e
)
{
catch
(
std
::
exception
&
e
)
{
rlib
::
println
(
std
::
cerr
,
"Error: exception while executing rpc find: "
,
e
.
what
());
rlib
::
println
(
std
::
cerr
,
"Error: exception while executing rpc find: "
,
e
.
what
());
...
@@ -111,25 +127,29 @@ private:
...
@@ -111,25 +127,29 @@ private:
}
}
}
}
const
value_type
&
do_find
(
const
key_type
&
k
)
const
{
const
value_type
*
do_find
(
const
key_type
&
k
,
bool
no_throw
=
false
)
const
{
const
auto
&
target_ls
=
find_slot
(
k
);
const
auto
&
target_ls
=
find_slot
(
k
);
{
{
for
(
const
auto
&
ele
:
target_ls
)
{
for
(
const
auto
&
ele
:
target_ls
)
{
if
(
equal_engine_type
{}(
ele
.
first
,
k
))
if
(
equal_engine_type
{}(
ele
.
first
,
k
))
return
ele
.
second
;
return
&
ele
.
second
;
}
}
}
}
throw
std
::
out_of_range
(
"Element not found."
);
if
(
not
no_throw
)
throw
std
::
out_of_range
(
"Element not found."
);
return
nullptr
;
}
}
value_type
&
do_find
(
const
key_type
&
k
)
{
value_type
*
do_find
(
const
key_type
&
k
,
bool
no_throw
=
false
)
{
auto
&
target_ls
=
find_slot
(
k
);
auto
&
target_ls
=
find_slot
(
k
);
{
{
for
(
auto
&
ele
:
target_ls
)
{
for
(
auto
&
ele
:
target_ls
)
{
if
(
equal_engine_type
{}(
ele
.
first
,
k
))
if
(
equal_engine_type
{}(
ele
.
first
,
k
))
return
ele
.
second
;
return
&
ele
.
second
;
}
}
}
}
throw
std
::
out_of_range
(
"Element not found."
);
if
(
not
no_throw
)
throw
std
::
out_of_range
(
"Element not found."
);
return
nullptr
;
}
}
const
auto
&
find_slot
(
const
key_type
&
k
)
const
{
const
auto
&
find_slot
(
const
key_type
&
k
)
const
{
...
...
This diff is collapsed.
Click to expand it.
hw3/hash_map.hpp
+
1
−
2
View file @
0a7afb0b
...
@@ -23,8 +23,7 @@ struct HashMap {
...
@@ -23,8 +23,7 @@ struct HashMap {
}
}
bool
insert
(
const
kmer_pair
&
kmer
)
{
bool
insert
(
const
kmer_pair
&
kmer
)
{
real_db
.
push
(
kmer
.
kmer
,
kmer
);
return
real_db
.
push_if_is_mine
(
kmer
.
kmer
,
kmer
);
return
true
;
}
}
bool
find
(
const
pkmer_t
&
key_kmer
,
kmer_pair
&
val_kmer
)
{
bool
find
(
const
pkmer_t
&
key_kmer
,
kmer_pair
&
val_kmer
)
{
auto
res
=
real_db
[
key_kmer
];
auto
res
=
real_db
[
key_kmer
];
...
...
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