mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-06 20:29:10 -07:00
computer: fix coarse lazy indexes
This commit is contained in:
@@ -115,7 +115,7 @@ impl FromCoarserIndex<WeekIndex> for DateIndex {
|
||||
} else if coarser == 1 {
|
||||
1
|
||||
} else {
|
||||
4 + (coarser - 1) * 7
|
||||
4 + (coarser - 2) * 7
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ impl FromCoarserIndex<WeekIndex> for DateIndex {
|
||||
} else if coarser == 1 {
|
||||
3
|
||||
} else {
|
||||
3 + coarser * 7
|
||||
3 + (coarser - 1) * 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::{fmt::Debug, ops::Add};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Add, AddAssign, Div},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
@@ -63,6 +66,27 @@ impl Add<usize> for DecadeIndex {
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<DecadeIndex> for DecadeIndex {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self::from(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for DecadeIndex {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = Self(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<usize> for DecadeIndex {
|
||||
type Output = Self;
|
||||
fn div(self, _: usize) -> Self::Output {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DateIndex> for DecadeIndex {
|
||||
fn from(value: DateIndex) -> Self {
|
||||
Self::from(Date::from(value))
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::{fmt::Debug, ops::Add};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Add, AddAssign, Div},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
@@ -57,6 +60,27 @@ impl Add<usize> for MonthIndex {
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<MonthIndex> for MonthIndex {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self::from(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for MonthIndex {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = Self(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<usize> for MonthIndex {
|
||||
type Output = Self;
|
||||
fn div(self, _: usize) -> Self::Output {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DateIndex> for MonthIndex {
|
||||
fn from(value: DateIndex) -> Self {
|
||||
Self::from(Date::from(value))
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::{fmt::Debug, ops::Add};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Add, AddAssign, Div},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
@@ -57,6 +60,27 @@ impl Add<usize> for QuarterIndex {
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<QuarterIndex> for QuarterIndex {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self::from(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for QuarterIndex {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = Self(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<usize> for QuarterIndex {
|
||||
type Output = Self;
|
||||
fn div(self, _: usize) -> Self::Output {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MonthIndex> for QuarterIndex {
|
||||
fn from(value: MonthIndex) -> Self {
|
||||
Self((usize::from(value) / 3) as u16)
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::{fmt::Debug, ops::Add};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Add, AddAssign, Div},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
@@ -57,6 +60,27 @@ impl Add<usize> for SemesterIndex {
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<SemesterIndex> for SemesterIndex {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self::from(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for SemesterIndex {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = Self(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<usize> for SemesterIndex {
|
||||
type Output = Self;
|
||||
fn div(self, _: usize) -> Self::Output {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MonthIndex> for SemesterIndex {
|
||||
fn from(value: MonthIndex) -> Self {
|
||||
Self((usize::from(value) / 6) as u16)
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::{fmt::Debug, ops::Add};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Add, AddAssign, Div},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
@@ -49,6 +52,27 @@ impl From<WeekIndex> for usize {
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<WeekIndex> for WeekIndex {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self::from(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for WeekIndex {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = Self(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<usize> for WeekIndex {
|
||||
type Output = Self;
|
||||
fn div(self, _: usize) -> Self::Output {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<usize> for WeekIndex {
|
||||
type Output = Self;
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::{fmt::Debug, ops::Add};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Add, AddAssign, Div},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
@@ -51,6 +54,27 @@ impl Add<usize> for YearIndex {
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<YearIndex> for YearIndex {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self::from(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for YearIndex {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = Self(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<usize> for YearIndex {
|
||||
type Output = Self;
|
||||
fn div(self, _: usize) -> Self::Output {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DateIndex> for YearIndex {
|
||||
fn from(value: DateIndex) -> Self {
|
||||
Self::from(Date::from(value))
|
||||
|
||||
Reference in New Issue
Block a user