/** * A hash that uses {@link Object#hashCode()}. * * @return A hash that uses {@link Object#hashCode()}. */ public static <A> Hash<A> anyHash() { return hash(Object::hashCode); }
@Override public int hashCode() { return Hash.naturalHash.hash(this); }
/** * Compute the hash of the given key value using the underlying hashing strategy. * * @param k The key value to computer the hash of. * @return The hash of the given key value. */ public int hash(final K k) { return h.hash(k); }
/** * Maps the given function across this hash as a contra-variant functor. * * @param g The function to map. * @return A new hash. */ public <B> Hash<B> contramap(final F<B, A> g) { return hash(compose(f, g)); }
/** * A hash instance for the {@link Either} type. * * @param ha Hash the left side of <code>Either</code>. * @param hb Hash the right side of <code>Either</code>. * @return A hash instance for the {@link Either} type. */ public static <A, B> Hash<Either<A, B>> eitherHash(final Hash<A> ha, final Hash<B> hb) { return hash(e -> e.isLeft() ? ha.hash(e.left().value()) : hb.hash(e.right().value())); }
@Override public final int hashCode() { return Hash.v4Hash(Hash.<A>anyHash()).hash(this); }
@Override public final int hashCode() { return Hash.v3Hash(Hash.<A>anyHash()).hash(this); }
/** * Compute the hash code from this list as a function of the hash codes of its members. * Delegates to Hash.listHash, using the anyHash() rule, which uses the hash codes of the contents. * * @return the hash code for this list. */ @Override public final int hashCode() { return Hash.listHash(Hash.<A>anyHash()).hash(this); }
@Override public final int hashCode() { return Hash.optionHash(Hash.<A>anyHash()).hash(this); }
@Override public final int hashCode() { return Hash.v2Hash(Hash.<A>anyHash()).hash(this); }
@Override public final int hashCode() { return Hash.v7Hash(Hash.<A>anyHash()).hash(this); }
@Deprecated @Override public final int hashCode() { return Eithers.<A, B>eitherHash(Hash.anyHash(), Hash.anyHash()).hash(this); }
@Override public final int hashCode() { return Hash.p2Hash(Hash.<A>anyHash(), Hash.<B>anyHash()).hash(this); }
@Override public final int hashCode() { return Hash.eitherHash(Hash.<A>anyHash(), Hash.<B>anyHash()).hash(this); }
@Override public int hashCode() { return Hash.treeMapHash(Hash.<K>anyHash(), Hash.<V>anyHash()).hash(this); }
@Override public final int hashCode() { return Hash.resultHash(Hash.<A>anyHash(), Hash.<I>anyHash()).hash(this); }
@Override public final int hashCode() { return Hash.validationHash(Hash.<E>anyHash(), Hash.<T>anyHash()).hash(this); }
public static void main(String[] args) { Expression expr = Add(Const(1), Mult(Const(2), Mult(Const(3), Const(3)))); expressionShow().println(expr); expressionHash().hash(expr); System.out.println(eval(expr)); // (1+(2*(3*3))) = 19 }
@Override public final int hashCode() { return Hash.p7Hash(Hash.<A>anyHash(), Hash.<B>anyHash(), Hash.<C>anyHash(), Hash.<D>anyHash(), Hash.<E>anyHash(), Hash.<F>anyHash(), Hash.<G>anyHash()).hash(this); }