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-2023 Wilhelm Burger, Mark J. Burge. All rights reserved. 007 * Visit https://imagingbook.com for additional details. 008 ******************************************************************************/ 009 010package imagingbook.common.noise.hashing; 011 012/** 013 * <p> 014 * Integer hash function proposed by Thomas Wang in [1]. See [2] for details. 015 * </p> 016 * <p> 017 * [1] Thomas Wang, "Integer Hash Function", 018 * <a href="http://web.archive.org/web/20071223173210/http://www.concentric.net/~Ttwang/tech/inthash.htm"> 019 * http://www.concentric.net/~Ttwang/tech/inthash.htm</a> (Jan. 2007).<br> [2] W. Burger, M.J. Burge, <em>Principles of 020 * Digital Image Processing – Advanced Methods</em> (Vol. 3), Supplementary Chapter 8: "Synthetic Gradient Noise", 021 * Springer (2013). <a href= 022 * "https://dx.doi.org/10.13140/RG.2.1.3427.7284">https://dx.doi.org/10.13140/RG.2.1.3427.7284</a> 023 * </p> 024 * 025 * @author WB 026 * @version 2022/11/24 027 */ 028public class Hash32ShiftMult extends Hash32 { 029 030 /** 031 * Constructor, creates a hash function with a random seed value. 032 */ 033 public Hash32ShiftMult() { 034 this(0); 035 } 036 037 /** 038 * Constructor creating a hash function with the specified seed value. 039 * @param seed the random seed value (set to 0 use a random seed value). 040 */ 041 public Hash32ShiftMult(int seed) { 042 super(seed); 043 } 044 045 @Override 046 int hashInt(int key) { 047 key = key + seed; // WB added 048 int c2 = 668265261; //= 0x27d4eb2d, which is not a prime, closest prime is 668265263 049 key = (key ^ 61) ^ (key >>> 16); 050 key = key + (key << 3); 051 key = key ^ (key >>> 4); 052 key = key * c2; 053 key = key ^ (key >>> 15); 054 return key; 055 } 056}