Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 38 additions & 44 deletions ext/crates/sseq/src/bigraded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,73 @@ use std::cmp::Ordering::*;

use once::OnceBiVec;

use crate::coordinates::Bidegree;

pub struct DenseBigradedModule {
dimensions: OnceBiVec<OnceBiVec<usize>>,
min_y: i32,
}

impl DenseBigradedModule {
pub fn new(min_x: i32, min_y: i32) -> Self {
let dimensions = OnceBiVec::new(min_x);
dimensions.push(OnceBiVec::new(min_y));
Self { dimensions, min_y }
}

pub const fn min_x(&self) -> i32 {
self.dimensions.min_degree()
}

pub const fn min_y(&self) -> i32 {
self.min_y
pub fn new(min: Bidegree) -> Self {
let dimensions = OnceBiVec::new(min.x());
dimensions.push(OnceBiVec::new(min.y()));
Self {
dimensions,
min_y: min.y(),
}
}

pub fn max_x(&self) -> i32 {
self.dimensions.max_degree()
pub const fn min(&self) -> Bidegree {
Bidegree::x_y(self.dimensions.min_degree(), self.min_y)
}

pub fn max_y(&self) -> i32 {
self.dimensions
.iter()
.map(OnceBiVec::max_degree)
.max()
.unwrap_or_else(|| self.min_y())
pub fn max(&self) -> Bidegree {
Bidegree::x_y(
self.dimensions.max_degree(),
self.dimensions
.iter()
.map(OnceBiVec::max_degree)
.max()
.unwrap_or(self.min_y),
)
}

pub fn range(&self, x: i32) -> std::ops::Range<i32> {
self.dimensions[x].range()
}

pub fn defined(&self, x: i32, y: i32) -> bool {
self.dimensions.get(x).is_some() && self.dimensions[x].get(y).is_some()
pub fn defined(&self, b: Bidegree) -> bool {
self.dimensions.get(b.x()).is_some() && self.dimensions[b.x()].get(b.y()).is_some()
}

/// This can only be set when bidegrees to the left and bottom of (x, y) have been set.
pub fn set_dimension(&self, x: i32, y: i32, dim: usize) {
/// This can only be set when bidegrees to the left and bottom of `b` have been set.
pub fn set_dimension(&self, b: Bidegree, dim: usize) {
assert!(
x <= self.dimensions.len(),
"Cannot set dimension at ({}, {}) before ({}, {}).",
x,
y,
x - 1,
y
b.x() <= self.dimensions.len(),
"Cannot set dimension at {b} before {b_minus_1x}.",
b_minus_1x = b - Bidegree::x_y(1, 0)
);
if x == self.dimensions.len() {
if b.x() == self.dimensions.len() {
self.dimensions
.push_checked(OnceBiVec::new(self.min_y()), x);
.push_checked(OnceBiVec::new(self.min().y()), b.x());
}
match y.cmp(&self.dimensions[x].len()) {
Less => panic!("Already set dimension at ({x}, {y})"),
Equal => self.dimensions[x].push_checked(dim, y),
match b.y().cmp(&self.dimensions[b.x()].len()) {
Less => panic!("Already set dimension at {b}"),
Equal => self.dimensions[b.x()].push_checked(dim, b.y()),
Greater => panic!(
"Cannot set dimension at ({}, {}) before ({}, {})",
x,
y,
x,
y - 1
"Cannot set dimension at {b} before {b_minus_1y}",
b_minus_1y = b - Bidegree::x_y(0, 1)
),
}
}

/// The dimension in a bidegree, None if not yet defined
pub fn get_dimension(&self, x: i32, y: i32) -> Option<usize> {
Some(*self.dimensions.get(x)?.get(y)?)
pub fn get_dimension(&self, b: Bidegree) -> Option<usize> {
Some(*self.dimensions.get(b.x())?.get(b.y())?)
}

pub fn dimension(&self, x: i32, y: i32) -> usize {
self.get_dimension(x, y).unwrap()
pub fn dimension(&self, b: Bidegree) -> usize {
self.get_dimension(b).unwrap()
}
}
12 changes: 12 additions & 0 deletions ext/crates/sseq/src/coordinates/bidegree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ impl Bidegree {
Self { n, s }
}

pub const fn x_y(x: i32, y: i32) -> Self {
Self::n_s(x, y)
}

pub const fn zero() -> Self {
Self { n: 0, s: 0 }
}
Expand All @@ -47,6 +51,14 @@ impl Bidegree {
self.n
}

pub fn x(&self) -> i32 {
self.n()
}

pub fn y(&self) -> i32 {
self.s()
}

/// Returns difference as a bidegree if the difference in homological degrees is nonnegative,
/// otherwise returns None.
pub fn try_subtract(&self, smaller: Self) -> Option<Self> {
Expand Down
8 changes: 8 additions & 0 deletions ext/crates/sseq/src/coordinates/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ impl BidegreeElement {
self.degree.n()
}

pub fn x(&self) -> i32 {
self.degree.x()
}

pub fn y(&self) -> i32 {
self.degree.y()
}

pub fn vec(&self) -> FpSlice<'_> {
self.vec.as_slice()
}
Expand Down
Loading