Java code help needed

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;
}
}
Comments
5
It hashes a key.
Hashes you mean randomising it?
Parent
Hashing is a refinement of the simple idea that searching can be made more efficient if one can quickly narrow one's search by locating a subset of items to search. Each item is characterized by a key, a part of the item which uniquely identifies it; such as an employee-number. Hashing creates a subset of items to search by computing from the key a characteristic value, called the hash, and then groups items with the same hash; the group is called a bin.
Parent
private static long method1(String key, int vectorLenght) {
//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;
}
}
Thank you allot and heres your kiss :()... sorry dont know how to make inet kiss...
Parent
Back to top