/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.collection;

import java.util.function.BiPredicate;
import java.util.function.ToIntFunction;

public interface HashFunction<K> {

    int hashCode(K object);

    boolean equals(K a, K b);
    
    static <K> HashFunction<K> produce(ToIntFunction<K> hash, BiPredicate<K,K> eq) {
        return new HashFunction<K>(){
            @Override
            public int hashCode(K object) {
                return hash.applyAsInt(object);
            }

            @Override
            public boolean equals(K a, K b) {
                return eq.test(a, b);
            }
            
        };
    }
}
