Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ETHHash extends HashTable {
- public ETHHash(int size) {
- super(size);
- }
- @Override
- public int hash(String item) {
- if (item != null) {
- int bn = 1;
- for (int i = 0; i < item.length(); i++) {
- bn = Integer.valueOf(item.charAt(i))*((bn % 257) + 1);
- }
- return bn % getCapacity();
- }
- return 0;
- }
- }
- class GNUCPPHash extends HashTable {
- public GNUCPPHash(int size) {
- super(size);
- }
- @Override
- public int hash(String item) {
- if (item != null) {
- int bn = 0;
- for (int i = 0; i < item.length(); i++) {
- bn = 4*bn + Integer.valueOf(item.charAt(i));
- }
- return (((1 << 31) - 1) & bn) % getCapacity();
- }
- return 0;
- }
- }
- class GNUCC1Hash extends HashTable {
- public GNUCC1Hash(int size) {
- super(size);
- }
- @Override
- public int hash(String item) {
- if (item != null) {
- int bn = item.length();
- for (int i = 0; i < item.length(); i++) {
- bn = 613*bn + Integer.valueOf(item.charAt(i));
- }
- return (((1 << 30) - 1) & bn) % getCapacity();
- }
- return 0;
- }
- }
- class HashCodeHash extends HashTable {
- public HashCodeHash(int size) {
- super(size);
- }
- @Override
- public int hash(String item) {
- if (item != null) {
- return Math.abs(item.hashCode()) % getCapacity();
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement