@Test public void computeByteHash() throws UnsupportedEncodingException { CommandLineArgumentParser.parseFromProperties(this); Set<String> keys = new HashSet<>(this.iterationCount); Set<Long> hashedKeys = new HashSet<>(this.iterationCount); long collisionCount = 0; for (int i = 0; i < this.iterationCount; i++) { String k = "-string-" + i; byte[] bytes = k.getBytes(Utils.CHARSET); String stringHash = computeHash(bytes, 0, bytes.length); String stringHash2 = computeHash(bytes, 0, bytes.length); assertEquals(stringHash, stringHash2); assertTrue(keys.add(k)); } Logger.getAnonymousLogger().info("Generated keys: " + keys.size()); long s = System.nanoTime() / 1000; for (String key : keys) { byte[] bytes = key.getBytes(Utils.CHARSET); long hash = FNVHash.compute(bytes, 0, bytes.length); assertTrue(hash != 0); if (!hashedKeys.add(hash)) { collisionCount++; } } long e = System.nanoTime() / 1000; double thpt = this.iterationCount / ((e - s) / 1000000.0); Logger.getAnonymousLogger().info("Throughput: " + thpt); Logger.getAnonymousLogger().info("Collisions: " + collisionCount); }
public static String computeHash(CharSequence content) { return Long.toHexString(FNVHash.compute(content)); }
Utils { public static String computeHash(CharSequence content) { return Long.toHexString(FNVHash.compute(content)); } }
Utils { public static String computeHash(CharSequence content) { return Long.toHexString(FNVHash.compute(content)); } private  Utils(); }
Utils { public static String computeHash(CharSequence content) { return Long.toHexString(FNVHash.compute(content)); } private  Utils(); static void registerCustomJsonMapper(Class<?> clazz,
            JsonMapper mapper); static void registerCustomKryoSerializer(ThreadLocal<Kryo> kryoThreadLocal,
            boolean isDocumentSerializer); static T clone(T t); static T cloneObject(T t); static String computeSignature(ServiceDocument s, ServiceDocumentDescription description); static byte[] getBuffer(int capacity); static int toBytes(Object o, byte[] buffer, int position); static Object fromBytes(byte[] bytes); static Object fromBytes(byte[] bytes, int position, int length); static ServiceDocument fromQueryBinaryDocument(String link, Object binaryData); static void performMaintenance(); static String computeHash(CharSequence content); static String toJson(Object body); static String toJsonHtml(Object body); static String toJson(Set<JsonMapper.JsonOptions> options, Object body); static T fromJson(String json, Class<T> clazz); static T fromJson(Object json, Class<T> clazz); static T fromJson(Object json, Type type); static T getJsonMapValue(Object json, String key, Class<T> valueClazz); static T getJsonMapValue(Object json, String key, Type valueType); static String toString(Throwable t); static String toString(Map<?, Throwable> exceptions); static void log(Class<?> type, String classOrUri, Level level, String fmt,
            Object... args); static void log(Class<?> type, String classOrUri, Level level,
            Supplier<String> messageSupplier); static void log(Logger lg, Integer nestingLevel, String classOrUri, Level level,
            String fmt, Object... args); static void log(Logger lg, Integer nestingLevel, String classOrUri, Level level,
            Supplier<String> messageSupplier); static void logWarning(String fmt, Object... args); static String toDocumentKind(Class<?> type); static String fromDocumentKind(String kind); static String registerKind(Class<?> type, String kind); static Class<?> getTypeFromKind(String kind); static String buildKind(Class<?> type); static ServiceErrorResponse toServiceErrorResponse(Throwable e); static ServiceErrorResponse toValidationErrorResponse(Throwable t, Operation op); static boolean isValidationError(Throwable e); static String buildServicePath(Class<? extends Service> klass); static String buildUiResourceUriPrefixPath(Class<? extends Service> klass); static String buildUiResourceUriPrefixPath(Service service); static String buildCustomUiResourceUriPrefixPath(Service service); static Object setJsonProperty(Object body, String fieldName, String fieldValue); static String validateServiceOption(EnumSet<ServiceOption> options,
            ServiceOption option); static boolean isReachable(SystemHostInfo systemInfo, InetAddress addr, long timeoutMs); static void setFactoryAvailabilityIfOwner(ServiceHost host, String factoryLink,
            String factoryNodeSelectorPath, boolean isAvailable); static boolean isReachableByPing(SystemHostInfo systemInfo, InetAddress addr,
            long timeoutMs); static String getNormalizedHostAddress(SystemHostInfo systemInfo, InetAddress addr); static void encodeAndTransferLinkedStateToBody(Operation source, Operation target,
            boolean useBinary); static byte[] encodeBody(Operation op, boolean isRequest); static byte[] encodeBody(Operation op, Object body, String contentType, boolean isRequest); static void decodeBody(Operation op, ByteBuffer buffer, boolean isRequest); static void decodeBody(
            Operation op, ByteBuffer buffer, boolean isRequest, boolean compressed); static String decodeIfText(ByteBuffer buffer, String contentType); static ByteBuffer compressGZip(String text); static boolean isContentTypeKryoBinary(String contentType); static Path getServiceUiResourcePath(Service s); static boolean mergeWithState(
            ServiceDocumentDescription desc,
            T source, T patch); static boolean mergeWithState(T currentState, Operation op); static EnumSet<MergeResult> mergeWithStateAdvanced(
            ServiceDocumentDescription desc, T currentState, Class<T> type, Operation op); static void validateState(
            ServiceDocumentDescription desc, T state); static long fromNowMicrosUtc(long deltaMicros); static boolean beforeNow(long microsUtc); static long getSystemNowMicrosUtc(); static long getNowMicrosUtc(); static void setTimeDriftThreshold(long micros); static void resetTimeComparisonEpsilonMicros(); static void setTimeComparisonEpsilonMicros(long micros); static long getTimeComparisonEpsilonMicros(); static boolean isWithinTimeComparisonEpsilon(long timeMicros); static StringBuilder getBuilder(); static boolean updateCollections(T currentState,
            ServiceStateCollectionUpdateRequest patchBody); static boolean updateMaps(T currentState,
            ServiceStateMapUpdateRequest patchBody); static String buildUUID(String id); static T buildServiceConfig(T config, Service service); }
Utils { public static String computeHash(CharSequence content) { return Long.toHexString(FNVHash.compute(content)); } private  Utils(); static void registerCustomJsonMapper(Class<?> clazz,
            JsonMapper mapper); static void registerCustomKryoSerializer(ThreadLocal<Kryo> kryoThreadLocal,
            boolean isDocumentSerializer); static T clone(T t); static T cloneObject(T t); static String computeSignature(ServiceDocument s, ServiceDocumentDescription description); static byte[] getBuffer(int capacity); static int toBytes(Object o, byte[] buffer, int position); static Object fromBytes(byte[] bytes); static Object fromBytes(byte[] bytes, int position, int length); static ServiceDocument fromQueryBinaryDocument(String link, Object binaryData); static void performMaintenance(); static String computeHash(CharSequence content); static String toJson(Object body); static String toJsonHtml(Object body); static String toJson(Set<JsonMapper.JsonOptions> options, Object body); static T fromJson(String json, Class<T> clazz); static T fromJson(Object json, Class<T> clazz); static T fromJson(Object json, Type type); static T getJsonMapValue(Object json, String key, Class<T> valueClazz); static T getJsonMapValue(Object json, String key, Type valueType); static String toString(Throwable t); static String toString(Map<?, Throwable> exceptions); static void log(Class<?> type, String classOrUri, Level level, String fmt,
            Object... args); static void log(Class<?> type, String classOrUri, Level level,
            Supplier<String> messageSupplier); static void log(Logger lg, Integer nestingLevel, String classOrUri, Level level,
            String fmt, Object... args); static void log(Logger lg, Integer nestingLevel, String classOrUri, Level level,
            Supplier<String> messageSupplier); static void logWarning(String fmt, Object... args); static String toDocumentKind(Class<?> type); static String fromDocumentKind(String kind); static String registerKind(Class<?> type, String kind); static Class<?> getTypeFromKind(String kind); static String buildKind(Class<?> type); static ServiceErrorResponse toServiceErrorResponse(Throwable e); static ServiceErrorResponse toValidationErrorResponse(Throwable t, Operation op); static boolean isValidationError(Throwable e); static String buildServicePath(Class<? extends Service> klass); static String buildUiResourceUriPrefixPath(Class<? extends Service> klass); static String buildUiResourceUriPrefixPath(Service service); static String buildCustomUiResourceUriPrefixPath(Service service); static Object setJsonProperty(Object body, String fieldName, String fieldValue); static String validateServiceOption(EnumSet<ServiceOption> options,
            ServiceOption option); static boolean isReachable(SystemHostInfo systemInfo, InetAddress addr, long timeoutMs); static void setFactoryAvailabilityIfOwner(ServiceHost host, String factoryLink,
            String factoryNodeSelectorPath, boolean isAvailable); static boolean isReachableByPing(SystemHostInfo systemInfo, InetAddress addr,
            long timeoutMs); static String getNormalizedHostAddress(SystemHostInfo systemInfo, InetAddress addr); static void encodeAndTransferLinkedStateToBody(Operation source, Operation target,
            boolean useBinary); static byte[] encodeBody(Operation op, boolean isRequest); static byte[] encodeBody(Operation op, Object body, String contentType, boolean isRequest); static void decodeBody(Operation op, ByteBuffer buffer, boolean isRequest); static void decodeBody(
            Operation op, ByteBuffer buffer, boolean isRequest, boolean compressed); static String decodeIfText(ByteBuffer buffer, String contentType); static ByteBuffer compressGZip(String text); static boolean isContentTypeKryoBinary(String contentType); static Path getServiceUiResourcePath(Service s); static boolean mergeWithState(
            ServiceDocumentDescription desc,
            T source, T patch); static boolean mergeWithState(T currentState, Operation op); static EnumSet<MergeResult> mergeWithStateAdvanced(
            ServiceDocumentDescription desc, T currentState, Class<T> type, Operation op); static void validateState(
            ServiceDocumentDescription desc, T state); static long fromNowMicrosUtc(long deltaMicros); static boolean beforeNow(long microsUtc); static long getSystemNowMicrosUtc(); static long getNowMicrosUtc(); static void setTimeDriftThreshold(long micros); static void resetTimeComparisonEpsilonMicros(); static void setTimeComparisonEpsilonMicros(long micros); static long getTimeComparisonEpsilonMicros(); static boolean isWithinTimeComparisonEpsilon(long timeMicros); static StringBuilder getBuilder(); static boolean updateCollections(T currentState,
            ServiceStateCollectionUpdateRequest patchBody); static boolean updateMaps(T currentState,
            ServiceStateMapUpdateRequest patchBody); static String buildUUID(String id); static T buildServiceConfig(T config, Service service); static final String PROPERTY_NAME_PREFIX; static final Charset CHARSET_OBJECT; static final String CHARSET; static final String UI_DIRECTORY_NAME; static final String PROPERTY_NAME_TIME_COMPARISON; static final int DEFAULT_IO_THREAD_COUNT; static final int DEFAULT_THREAD_COUNT; static final long DEFAULT_TIME_DRIFT_THRESHOLD_MICROS; }