001/*******************************************************************************
002 * This software is provided as a supplement to the authors' textbooks on digital
003 *  image processing published by Springer-Verlag in various languages and editions.
004 * Permission to use and distribute this software is granted under the BSD 2-Clause 
005 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause). 
006 * Copyright (c) 2006-2016 Wilhelm Burger, Mark J. Burge. All rights reserved. 
007 * Visit http://imagingbook.com for additional details.
008 *******************************************************************************/
009
010package imagingbook.pub.noise.hashing;
011
012/**
013 * Hash function described in G. Ward, "A recursive implementation 
014 * of the Perlin noise function", Graphics Gems II, 1991
015 */
016public class Hash32Ward extends Hash32 {
017        
018        public Hash32Ward() {
019                super();
020        }
021        
022        public Hash32Ward(int seed) {
023                super(seed);
024        }
025        
026        int hashInt(int key) {
027                return hashIntWard(key);
028        }
029        
030        //  lower 16 bits are highly repetitive and perfectly uniform!!!!
031        int hashIntWard(int key) {
032                key = (key << 13) ^ key; // ^ denotes bitwise XOR operation
033                key = (key * (key * key * 15731 + 789221) + 1376312589);
034                return key;
035        }
036}