Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CS744 DECS-PA4-KEYVALUE-SERVER
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kamal Khodabhai
CS744 DECS-PA4-KEYVALUE-SERVER
Commits
e7a645a8
Commit
e7a645a8
authored
Nov 13, 2021
by
Kamal Khodabhai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload finger.cpp
parent
e5ffc566
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
Finger table/finger.cpp
Finger table/finger.cpp
+42
-0
No files found.
Finger table/finger.cpp
0 → 100644
View file @
e7a645a8
#include <bits/stdc++.h>
using
namespace
std
;
unordered_map
<
int
,
int
>
idPortMapping
;
map
<
int
,
int
>
fingureTable
;
vector
<
int
>
idList
;
void
genrateFingerTable
(
int
id
,
int
n
)
{
string
line
;
idList
.
clear
();
idPortMapping
.
clear
();
ifstream
id_port
(
"id_port.csv"
);
while
(
getline
(
id_port
,
line
))
{
char
temp
[
line
.
length
()];
strcpy
(
temp
,
line
.
c_str
());
char
*
token1
=
strtok
(
temp
,
","
);
char
*
token2
=
strtok
(
NULL
,
"-"
);
idPortMapping
[
atoi
(
token1
)]
=
atoi
(
token2
);
idList
.
push_back
(
atoi
(
token1
));
}
sort
(
idList
.
begin
(),
idList
.
end
());
id_port
.
close
();
int
modulo
=
pow
(
2
,
n
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
int
tmp
=
(
int
)(
id
+
pow
(
2
,
i
))
%
modulo
;
auto
lb
=
lower_bound
(
idList
.
begin
(),
idList
.
end
(),
tmp
);
fingureTable
[
tmp
]
=
idPortMapping
[
lb
==
idList
.
end
()
?
idList
[
0
]
:
*
lb
];
}
}
int
main
()
{
int
id
;
cin
>>
id
;
genrateFingerTable
(
id
,
8
);
for
(
auto
i
:
fingureTable
)
cout
<<
i
.
first
<<
" => "
<<
i
.
second
<<
endl
;
return
0
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment