hashfunction.java

来自「发布/订阅系统路由重配算法,可应用于ad hoc环境」· Java 代码 · 共 54 行

JAVA
54
字号
/* * project: RebecaSim * package: broker * file:    HashFunction.java *  * version: 0.1 * date:    10.05.2005 *  * This software is part of the diploma thesis "Ein adaptives Brokernetz  * für Publish/Subscribe Systeme". */package broker;import java.util.*;/** * This class implements a simple hash function based on java's own * pseudo random generator. To hash a value the random generator's seed * is set to a value dependent bit pattern. The pattern is determined * by value xor hashseed, where hashseed is the hash functions own seed. * * @version 10.05.2005 * @author  parzy */public class HashFunction {	/**	 * The used random generator.	 */	private static Random rand = new Random();		/**	 * The hash functions own seed.	 */	private long seed;		/**	 * Creates a hash function with the given seed.	 * @param seed the hash function's seed.	 */	public HashFunction(long seed){		this.seed = seed;	}		/**	 * Hashs the value. 	 * @param value the value to hash.	 * @return the value's hash.	 */	public int hash(int value){		rand.setSeed(seed ^ value);		return rand.nextInt();	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?