private int calculateHashCode() { return BobHash.hash(serialized, 0); }
a += (unsign(k[offset + 0]) + (unsign(k[offset + 1]) << 8) + (unsign(k[offset + 2]) << 16) + (unsign(k[offset + 3]) << 24)); b += (unsign(k[offset + 4]) + (unsign(k[offset + 5]) << 8) + (unsign(k[offset + 6]) << 16) + (unsign(k[offset + 7]) << 24)); c += (unsign(k[offset + 8]) + (unsign(k[offset + 9]) << 8) + (unsign(k[offset + 10]) << 16) + (unsign(k[offset + 11]) << 24)); abcBuffer = mix(a, b, c); a = abcBuffer[0]; b = abcBuffer[1]; c += (unsign(k[offset + 10]) << 24); c += (unsign(k[offset + 9]) << 16); c += (unsign(k[offset + 8]) << 8); b += (unsign(k[offset + 7]) << 24); b += (unsign(k[offset + 6]) << 16); b += (unsign(k[offset + 5]) << 8); b += unsign(k[offset + 4]); a += (unsign(k[offset + 3]) << 24);
/** * Hashes a string, by calling hash(byte[] key,int initval) with * the utf-8 bytes of the string as key and 0 as initval. * Note: This is copying the string content, change implementation to * use efficiently on large strings. * * bratseth */ public static int hash(String key) { return hash(Utf8.toBytes(key), 0); }
private int getDiskSeed(BucketId bucket, int nodeIndex) { // Assumes MODULO_BID for now. long currentid = bucket.withoutCountBits(); byte[] ordered = new byte[8]; ordered[0] = (byte)(currentid >> (0*8)); ordered[1] = (byte)(currentid >> (1*8)); ordered[2] = (byte)(currentid >> (2*8)); ordered[3] = (byte)(currentid >> (3*8)); ordered[4] = (byte)(currentid >> (4*8)); ordered[5] = (byte)(currentid >> (5*8)); ordered[6] = (byte)(currentid >> (6*8)); ordered[7] = (byte)(currentid >> (7*8)); int initval = (1664525 * nodeIndex + 0xdeadbeef); return BobHash.hash(ordered, initval); } /**
private static Object applyFunction(String function, Object value) { if (function.equalsIgnoreCase("abs")) { if (Number.class.isInstance(value)) { Number nValue = (Number)value; if (value instanceof Double) { return nValue.doubleValue() * (nValue.doubleValue() < 0 ? -1 : 1); } else if (value instanceof Float) { return nValue.floatValue() * (nValue.floatValue() < 0 ? -1 : 1); } else if (value instanceof Long) { return nValue.longValue() * (nValue.longValue() < 0 ? -1 : 1); } else if (value instanceof Integer) { return nValue.intValue() * (nValue.intValue() < 0 ? -1 : 1); } } throw new IllegalStateException("Function 'abs' is only available for numerical values."); } else if (function.equalsIgnoreCase("hash")) { return BobHash.hash(value.toString()); } else if (function.equalsIgnoreCase("lowercase")) { return value.toString().toLowerCase(); } else if (function.equalsIgnoreCase("uppercase")) { return value.toString().toUpperCase(); } throw new IllegalStateException("Function '" + function + "' is not supported."); }
/** * The field id must be unique within a document type, and also * within a (unknown at this time) hierarchy of document types. * In addition it should be as resilient to doctype content changes * and inheritance hierarchy changes as possible. * All of this is enforced for names, so id's should follow names. * Therefore we hash on name. */ private int calculateIdV6(DocumentType owner) { int newId = BobHash.hash(getName()); // Using a portfriendly hash if (newId < 0) newId = -newId; // Highest bit is reserved to tell 7-bit id's from 31-bit ones validateId(newId, owner, 6); return newId; }
/** * The field id must be unique within a document type, and also * within a (unknown at this time) hierarchy of document types. * In addition it should be as resilient to doctype content changes * and inheritance hierarchy changes as possible. * All of this is enforced for names, so id's should follow names. * Therefore we hash on name. */ protected int calculateIdV7(DocumentType owner) { String combined = getName() + dataType.getId(); int newId = BobHash.hash(combined); // Using a portfriendly hash if (newId < 0) newId = -newId; // Highest bit is reserved to tell 7-bit id's from 31-bit ones validateId(newId, owner, Document.SERIALIZED_VERSION); return newId; }