Java code help needed
•
14 Dec 2009, 20:37
•
Journals
I need just put comments on code.. I did everything else except the last part.
If someone could help me? Because I know there are allot of lovely m8s in crossfire who has nothing better to do then help noobies ^^
So if you can explain what happens here I will give you a kiss!
}
private static long method1(String key, int vectorLenght) {
return hash(key) % vectorLength;
}
private static long hash(String key) {
long hash = 0;
for (int i = 0; i < key.length(); i++) {
hash += key.charAt(i);
hash = (hash << 7);
}
hash += (hash << 3);
return hash;
}
}
If someone could help me? Because I know there are allot of lovely m8s in crossfire who has nothing better to do then help noobies ^^
So if you can explain what happens here I will give you a kiss!
}
private static long method1(String key, int vectorLenght) {
return hash(key) % vectorLength;
}
private static long hash(String key) {
long hash = 0;
for (int i = 0; i < key.length(); i++) {
hash += key.charAt(i);
hash = (hash << 7);
}
hash += (hash << 3);
return hash;
}
}
//returns the offcut of the hash of key divided by vectorLength
return hash(key) % vectorLength;
}
private static long hash(String key) {
long hash = 0;
// transform every char of key to a long value and shift every bit 7 bits to the left
for (int i = 0; i < key.length(); i++) {
hash += key.charAt(i);
hash = (hash << 7);
}
// shifts the complete hash 3 bits to the left
hash += (hash << 3);
return hash;
}
}