
com.jnape.palatable.shoki.api.HashingAlgorithm Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shoki Show documentation
Show all versions of shoki Show documentation
Purely functional data structures in Java
The newest version!
package com.jnape.palatable.shoki.api;
import com.jnape.palatable.lambda.functions.Fn1;
import com.jnape.palatable.lambda.functor.Applicative;
import java.util.Objects;
/**
* A {@link HashingAlgorithm hashing algorithm} is an {@link Fn1 arrow} A -> Integer
. Good
* hashing algorithms are generally fast and uniformly distribute values of type A
across values of type
* {@link Integer} (modulo cardinality differences where A
's cardinality exceeds {@link Integer}'s).
*
* @param the type to hash
*/
public interface HashingAlgorithm extends Fn1 {
/**
* {@inheritDoc}
*/
@Override
default HashingAlgorithm local(Fn1 super A, ? extends A> fn) {
return Fn1.super.local(fn)::apply;
}
/**
* {@inheritDoc}
*/
@Override
default HashingAlgorithm censor(Fn1 super A, ? extends A> fn) {
return Fn1.super.censor(fn)::apply;
}
/**
* {@inheritDoc}
*/
@Override
default HashingAlgorithm discardR(Applicative> appB) {
return Fn1.super.discardR(appB)::apply;
}
/**
* {@inheritDoc}
*/
@Override
default HashingAlgorithm diMapL(Fn1 super Z, ? extends A> fn) {
return Fn1.super.diMapL(fn)::apply;
}
/**
* {@inheritDoc}
*/
@Override
default HashingAlgorithm contraMap(Fn1 super Z, ? extends A> fn) {
return Fn1.super.contraMap(fn)::apply;
}
/**
* A {@link HashingAlgorithm} implemented in terms of {@link Objects#hashCode(Object)}.
*
* @param the type to hash
* @return a {@link HashingAlgorithm} implemented in terms of {@link Objects#hashCode(Object)}.
*/
static HashingAlgorithm objectHashCode() {
return Objects::hashCode;
}
/**
* A {@link HashingAlgorithm} implemented in terms of {@link System#identityHashCode(Object)}.
*
* @param the type to hash
* @return a {@link HashingAlgorithm} implemented in terms of {@link System#identityHashCode(Object)}.
*/
static HashingAlgorithm identityHashCode() {
return System::identityHashCode;
}
/**
* A {@link HashingAlgorithm} implemented in terms of {@link java.util.Arrays#hashCode(Object[])}.
*
* @param the array component type
* @return a {@link HashingAlgorithm} implemented in terms of {@link java.util.Arrays#hashCode(Object[])}.
*/
static HashingAlgorithm arraysHashCode() {
return java.util.Arrays::hashCode;
}
/**
* A {@link HashingAlgorithm} implemented in terms of {@link java.util.Arrays#deepHashCode(Object[])}.
*
* @return a {@link HashingAlgorithm} implemented in terms of {@link java.util.Arrays#deepHashCode(Object[])}.
*/
static HashingAlgorithm
© 2015 - 2025 Weber Informatics LLC | Privacy Policy