#[derive(Default, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct HashFunctionConfiguration
{
pub(crate) function: Option<HashFunctionName>,
pub(crate) indirection_table: Option<IndirectionTable>,
pub(crate) seed: Option<HashFunctionSeed>,
}
impl HashFunctionConfiguration
{
pub(crate) const Unsupported: Self = Self
{
function: None,
indirection_table: None,
seed: None,
};
#[inline(always)]
pub(crate) fn indirection_table_length_u32(&self) -> Result<Option<NonZeroU32>, IndirectionTableLengthError>
{
use self::IndirectionTableLengthError::*;
match self.indirection_table
{
None => Ok(None),
Some(ref indirection_table) =>
{
let len: usize = indirection_table.len();
let x = len.try_into().map_err(IndirectionTableIsTooLongForU32)?;
Ok(Some(NonZeroU32::new(x).ok_or(IndirectionTableLengthIsZero)?))
}
}
}
#[inline(always)]
pub(crate) fn new_seed_matching_in_length(&self, hash_function_seed: &HashFunctionSeed) -> Option<HashFunctionSeed>
{
self.seed.as_ref().map(|existing_seed|
{
let must_be_seed_length = existing_seed.len();
let mut hash_function_seed = hash_function_seed.clone();
hash_function_seed.resize(must_be_seed_length);
hash_function_seed
})
}
}