110353ed766fc48a0af6bd33d934439e695c03e3Mahmood Alipackage annotations.util; 210353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali 3a74f2668d253bb9375805db0f23a01e30ddfba8fwdietl/*>>> 443367280222c6f50f8085ae8d12a985c257b3ea0Michael Ernstimport org.checkerframework.checker.nullness.qual.*; 5a74f2668d253bb9375805db0f23a01e30ddfba8fwdietl*/ 610353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali 710353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali/** 810353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali * A simple class to mash a lot of data into a hash code for use in 910353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali * implementing {@link Object#hashCode}. The mashing algorithm currently is 1010353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali * not very good; the advantage of a {@link Hasher} class is that an 1110353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali * improvement to its mashing algorithm benefits all classes that use it. 1210353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali */ 1310353ed766fc48a0af6bd33d934439e695c03e3Mahmood Alipublic final class Hasher { 1410353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali /** 1510353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali * The calculated hash code for the data that has been contributed so far. 1610353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali */ 1710353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali public int hash = 0; 1810353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali 1910353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali private static final int SHIFT = 5; 2010353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali 2110353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali /** 2210353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali * Contributes the data <code>x</code> to the calculation of the hash code. 2310353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali */ 2410353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali public void mash(int x) { 2510353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali hash = ((hash << SHIFT) | (hash >> (32 - SHIFT))) ^ x; 2610353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali } 2710353ed766fc48a0af6bd33d934439e695c03e3Mahmood Ali} 28