Skip to content

Commit

Permalink
Adding inlines.
Browse files Browse the repository at this point in the history
  • Loading branch information
fulmicoton authored Dec 22, 2022
1 parent f4804ce commit 13b89cb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions fastfield_codecs/src/blockwise_linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,18 @@ impl Column for BlockwiseLinearReader {
interpoled_val.wrapping_add(bitpacked_diff)
}

#[inline(always)]
fn min_value(&self) -> u64 {
// The BlockwiseLinearReader assumes a normalized vector.
0u64
}

#[inline(always)]
fn max_value(&self) -> u64 {
self.normalized_header.max_value
}

#[inline(always)]
fn num_vals(&self) -> u32 {
self.normalized_header.num_vals
}
Expand Down
4 changes: 2 additions & 2 deletions fastfield_codecs/src/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ impl Column for LinearReader {
interpoled_val.wrapping_add(bitpacked_diff)
}

#[inline]
#[inline(always)]
fn min_value(&self) -> u64 {
// The LinearReader assumes a normalized vector.
0u64
}

#[inline]
#[inline(always)]
fn max_value(&self) -> u64 {
self.header.max_value
}
Expand Down
15 changes: 15 additions & 0 deletions fastfield_codecs/src/monotonic_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ impl<T> From<T> for StrictlyMonotonicMappingInverter<T> {
impl<From, To, T> StrictlyMonotonicFn<To, From> for StrictlyMonotonicMappingInverter<T>
where T: StrictlyMonotonicFn<From, To>
{
#[inline(always)]
fn mapping(&self, val: To) -> From {
self.orig_mapping.inverse(val)
}

#[inline(always)]
fn inverse(&self, val: From) -> To {
self.orig_mapping.mapping(val)
}
Expand All @@ -83,10 +85,12 @@ impl<External: MonotonicallyMappableToU128, T: MonotonicallyMappableToU128>
StrictlyMonotonicFn<External, u128> for StrictlyMonotonicMappingToInternal<T>
where T: MonotonicallyMappableToU128
{
#[inline(always)]
fn mapping(&self, inp: External) -> u128 {
External::to_u128(inp)
}

#[inline(always)]
fn inverse(&self, out: u128) -> External {
External::from_u128(out)
}
Expand All @@ -96,10 +100,12 @@ impl<External: MonotonicallyMappableToU64, T: MonotonicallyMappableToU64>
StrictlyMonotonicFn<External, u64> for StrictlyMonotonicMappingToInternal<T>
where T: MonotonicallyMappableToU64
{
#[inline(always)]
fn mapping(&self, inp: External) -> u64 {
External::to_u64(inp)
}

#[inline(always)]
fn inverse(&self, out: u64) -> External {
External::from_u64(out)
}
Expand Down Expand Up @@ -127,11 +133,13 @@ impl StrictlyMonotonicMappingToInternalGCDBaseval {
impl<External: MonotonicallyMappableToU64> StrictlyMonotonicFn<External, u64>
for StrictlyMonotonicMappingToInternalGCDBaseval
{
#[inline(always)]
fn mapping(&self, inp: External) -> u64 {
self.gcd_divider
.divide(External::to_u64(inp) - self.min_value)
}

#[inline(always)]
fn inverse(&self, out: u64) -> External {
External::from_u64(self.min_value + out * self.gcd)
}
Expand All @@ -142,6 +150,7 @@ pub(crate) struct StrictlyMonotonicMappingToInternalBaseval {
min_value: u64,
}
impl StrictlyMonotonicMappingToInternalBaseval {
#[inline(always)]
pub(crate) fn new(min_value: u64) -> Self {
Self { min_value }
}
Expand All @@ -150,20 +159,24 @@ impl StrictlyMonotonicMappingToInternalBaseval {
impl<External: MonotonicallyMappableToU64> StrictlyMonotonicFn<External, u64>
for StrictlyMonotonicMappingToInternalBaseval
{
#[inline(always)]
fn mapping(&self, val: External) -> u64 {
External::to_u64(val) - self.min_value
}

#[inline(always)]
fn inverse(&self, val: u64) -> External {
External::from_u64(self.min_value + val)
}
}

impl MonotonicallyMappableToU64 for u64 {
#[inline(always)]
fn to_u64(self) -> u64 {
self
}

#[inline(always)]
fn from_u64(val: u64) -> Self {
val
}
Expand Down Expand Up @@ -196,10 +209,12 @@ impl MonotonicallyMappableToU64 for bool {
// TODO remove me.
// Tantivy should refuse NaN values and work with NotNaN internally.
impl MonotonicallyMappableToU64 for f64 {
#[inline(always)]
fn to_u64(self) -> u64 {
common::f64_to_u64(self)
}

#[inline(always)]
fn from_u64(val: u64) -> Self {
common::u64_to_f64(val)
}
Expand Down
1 change: 1 addition & 0 deletions fastfield_codecs/src/null_index/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ enum SparseCodecBlockVariant {

impl SparseCodecBlockVariant {
/// The number of non-null values that preceeded that block.
#[inline]
fn offset(&self) -> u32 {
match self {
SparseCodecBlockVariant::Empty { offset } => *offset,
Expand Down
1 change: 1 addition & 0 deletions fastfield_codecs/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ pub enum ValueIndexInfo<'a> {
SingleValue(Box<dyn SingleValueIndexInfo + 'a>),
}

// TODO Remove me
impl Default for ValueIndexInfo<'static> {
fn default() -> Self {
struct Dummy {}
Expand Down

0 comments on commit 13b89cb

Please sign in to comment.