-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPeer.java
More file actions
87 lines (69 loc) · 1.28 KB
/
Peer.java
File metadata and controls
87 lines (69 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package tw.nccu.edu.dht;
import java.io.IOException;
import java.io.Serializable;
public class Peer implements Serializable {
private static final long serialVersionUID = 1L;
private String key;
private String value;
private int x;
private int y;
public Peer(String key, String value) throws IOException {
setX(0);
setY(0);
setKey(key);
setValue(value);
}
public Peer(){
setX(0);
setY(0);
setKey(null);
setValue(null);
}
public int HashX(String key){
int sum=0;
if(key.length() == 1)
return 0;
else
for(int i=0;i<key.toCharArray().length;i++)
if(i % 2 != 0)
sum+= key.charAt(i);
int hashx = sum % 10;
return hashx;
}
public int HashY(String key){
int sum=0;
if(key.length() == 1)
return 1;
else
for(int i=0;i<key.toCharArray().length;i++)
if(i % 2 == 0)
sum+= key.charAt(i);
int hashy = sum % 10;
return hashy;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public int setY(int y) {
this.y = y;
return y;
}
}