Trait fastfield_codecs::StrictlyMonotonicFn
source · [−]pub trait StrictlyMonotonicFn<External: Copy, Internal: Copy> {
fn mapping(&self, inp: External) -> Internal;
fn inverse(&self, out: Internal) -> External;
fn mapping_coerce(
&self,
inp: RangeInclusive<External>
) -> RangeInclusive<Internal> { ... }
fn inverse_coerce(
&self,
out: RangeInclusive<Internal>
) -> RangeInclusive<External> { ... }
}
Expand description
Values need to be strictly monotonic mapped to a Internal
value (u64 or u128) that can be
used in fast field codecs.
The monotonic mapping is required so that PartialOrd
can be used on Internal
without
converting to External
.
All strictly monotonic functions are invertible because they are guaranteed to have a one-to-one
mapping from their range to their domain. The inverse
method is required when opening a codec,
so a value can be converted back to its original domain (e.g. ip address or f64) from its
internal representation.
Required Methods
Provided Methods
sourcefn mapping_coerce(
&self,
inp: RangeInclusive<External>
) -> RangeInclusive<Internal>
fn mapping_coerce(
&self,
inp: RangeInclusive<External>
) -> RangeInclusive<Internal>
Maps a user provded value from External to Internal. It may be necessary to coerce the value if it is outside the value space. In that case it tries to find the next greater value in the value space.
Returns a bool to mark if a value was outside the value space and had to be coerced up. With that information we can detect if two values in a range both map outside the same value space.
coerce_up means the next valid upper value in the value space will be chosen if the value has to be coerced.
sourcefn inverse_coerce(
&self,
out: RangeInclusive<Internal>
) -> RangeInclusive<External>
fn inverse_coerce(
&self,
out: RangeInclusive<Internal>
) -> RangeInclusive<External>
Inverse of mapping_coerce
.