1 57 58 package org.enhydra.apache.xerces.utils; 59 60 73 public final class StringHasher { 74 81 public static int hashString(String str, int strLength) { 82 int hashcode = 0; 83 for (int i = 0; i < strLength; i++) { 84 int top = hashcode >> 24; 85 hashcode += ((hashcode * 37) + top + ((int)str.charAt(i))); 86 } 87 hashcode = (hashcode & 0x7fffffff); 88 return (hashcode == 0) ? 1 : hashcode; 89 } 90 98 public static int hashChars(char[] chars, int offset, int length) { 99 int hashcode = 0; 100 for (int i = 0; i < length; i++) { 101 int top = hashcode >> 24; 102 hashcode += ((hashcode * 37) + top + ((int)(chars[offset++] & 0xFFFF))); 103 } 104 hashcode = (hashcode & 0x7fffffff); 105 return (hashcode == 0) ? 1 : hashcode; 106 } 107 117 public static int hashChar(int hashcode, int ch) { 118 int top = hashcode >> 24; 119 hashcode += ((hashcode * 37) + top + ch); 120 return hashcode; 121 } 122 129 public static int finishHash(int hashcode) { 130 hashcode = (hashcode & 0x7fffffff); 131 return (hashcode == 0) ? 1 : hashcode; 132 } 133 } 134 | Popular Tags |