public static int getCRC16(byte[] bytes) { return getCRC16(bytes, 0, bytes.length); }
public static int getSlot(byte[] key) { int s = -1; int e = -1; boolean sFound = false; for (int i = 0; i < key.length; i++) { if (key[i] == '{' && !sFound) { s = i; sFound = true; } if (key[i] == '}' && sFound) { e = i; break; } } if (s > -1 && e > -1 && e != s + 1) { return getCRC16(key, s + 1, e) & (16384 - 1); } return getCRC16(key) & (16384 - 1); }
public static int getSlot(String key) { int s = key.indexOf("{"); if (s > -1) { int e = key.indexOf("}", s + 1); if (e > -1 && e != s + 1) { key = key.substring(s + 1, e); } } // optimization with modulo operator with power of 2 // equivalent to getCRC16(key) % 16384 return getCRC16(key) & (16384 - 1); }
public static int getCRC16(String key) { byte[] bytesKey = SafeEncoder.encode(key); return getCRC16(bytesKey, 0, bytesKey.length); } }