Skip to main content

BusinessDayGrid

Struct BusinessDayGrid 

pub(crate) struct BusinessDayGrid {
    start: NaiveDate,
    days: u32,
    business: Vec<u64>,
    prefix: Vec<u32>,
}
Expand description

Day-number-indexed business-day classification over a fixed date horizon: a bitset (one bit per day, set ⇔ business day) plus a per-word prefix sum making “business days in [0, i)” a lookup-and-popcount. Immutable after construction; ~4.6 KB of bits plus ~2.3 KB of prefix per century calendar.

Fields§

§start: NaiveDate§days: u32

Number of days covered, starting at start.

§business: Vec<u64>

Bit i (word i / 64, bit i % 64) set ⇔ day i is a business day.

§prefix: Vec<u32>

prefix[w] = number of business days in words [0, w).

Implementations§

§

impl BusinessDayGrid

pub(crate) fn build( start: NaiveDate, days: u32, is_business: impl FnMut(NaiveDate) -> bool, ) -> Self

Builds the grid for [start, start + days) from a per-day classifier.

pub(crate) fn start(&self) -> NaiveDate

The grid’s first covered day.

pub(crate) fn end_exclusive(&self) -> NaiveDate

The first day after the covered horizon.

pub(crate) fn day_index(&self, date: NaiveDate) -> Option<u32>

The day index of date, or None outside the horizon.

pub(crate) fn is_business(&self, idx: u32) -> bool

Whether day idx (in range) is a business day.

pub(crate) fn rank(&self, idx: u32) -> i64

Number of business days among days [0, idx); idx may equal days.

pub(crate) fn count_in_horizon(&self, from: NaiveDate, to: NaiveDate) -> i64

Number of business days in the half-open date range [from, to) intersected with the horizon (from <= to).

Trait Implementations§

§

impl Clone for BusinessDayGrid

§

fn clone(&self) -> BusinessDayGrid

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for BusinessDayGrid

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.