Here you can find the source of hash(String s)
Parameter | Description |
---|---|
s | the string representing the key |
public static int hash(String s)
//package com.java2s; /*/*from w w w . j a v a 2s . c o m*/ * Title: Mobile CloudSim Toolkit * Description: Extension of CloudSim Toolkit for Modeling and Simulation of Publish/Subscribe * Communication Paradigm with Subscriber Connectivity Change * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * * Copyright (c) 2014-2016, Universidade Federal de Goi?s, Brazil */ public class Main { private static int hashSuffix = 1000; /** * Generates a hash number according with a given string * * @param s * the string representing the key * @return the hash value of string */ public static int hash(String s) { int h = 0; // The hash value is the number the string represents or a function // using ASCII value try { h = Integer.parseInt(s); } catch (NumberFormatException e) { for (int i = 0; i < s.length(); i++) { h += s.charAt(i) - 48; // Don't use the ASCII value but the real // value } } // To have different values we concatenate the hash value if current // time String hr = String.valueOf(h) + String.valueOf(hashSuffix++); return Integer.parseInt(hr); } }