Skip to content

Commit

Permalink
refactor!: delete force_ variants internals in favor of wrapping re…
Browse files Browse the repository at this point in the history
…gular impl (#277)

* update 2D

* update 3D

* fix tests
  • Loading branch information
imrn99 authored Feb 10, 2025
1 parent 46e79c0 commit a32a24c
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 778 deletions.
2 changes: 2 additions & 0 deletions honeycomb-core/src/attributes/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ impl AttrStorageManager {
}
}

#[allow(unused)]
/// Merge variants.
impl AttrStorageManager {
// attribute-agnostic regular
Expand Down Expand Up @@ -627,6 +628,7 @@ impl AttrStorageManager {
*/
}

#[allow(unused)]
/// Split variants.
impl AttrStorageManager {
// attribute-agnostic regular
Expand Down
10 changes: 5 additions & 5 deletions honeycomb-core/src/cmap/dim2/sews/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod two;
use crate::{
cmap::{CMap2, DartIdType, SewError},
prelude::CoordsFloat,
stm::{Transaction, TransactionClosureResult},
stm::{atomically_with_err, Transaction, TransactionClosureResult},
};

/// # **Sew implementations**
Expand Down Expand Up @@ -122,8 +122,8 @@ impl<T: CoordsFloat> CMap2<T> {
assert!(I < 3);
assert_ne!(I, 0);
match I {
1 => self.force_one_sew(ld, rd),
2 => self.force_two_sew(ld, rd),
1 => atomically_with_err(|trans| self.one_sew(trans, ld, rd)),
2 => atomically_with_err(|trans| self.two_sew(trans, ld, rd)),
_ => unreachable!(),
}
}
Expand All @@ -138,8 +138,8 @@ impl<T: CoordsFloat> CMap2<T> {
assert!(I < 3);
assert_ne!(I, 0);
match I {
1 => self.force_one_unsew(ld),
2 => self.force_two_unsew(ld),
1 => atomically_with_err(|trans| self.one_unsew(trans, ld)),
2 => atomically_with_err(|trans| self.two_unsew(trans, ld)),
_ => unreachable!(),
}
}
Expand Down
70 changes: 2 additions & 68 deletions honeycomb-core/src/cmap/dim2/sews/one.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::stm::{atomically_with_err, try_or_coerce, Transaction, TransactionClosureResult};
use crate::stm::{try_or_coerce, Transaction, TransactionClosureResult};

use crate::{
attributes::UnknownAttributeStorage,
Expand All @@ -7,7 +7,7 @@ use crate::{
};

#[doc(hidden)]
/// 1-sews
/// **1-(un)sews internals**
impl<T: CoordsFloat> CMap2<T> {
/// 1-sew transactional implementation.
pub(super) fn one_sew(
Expand Down Expand Up @@ -51,47 +51,6 @@ impl<T: CoordsFloat> CMap2<T> {
Ok(())
}

/// 1-sew implementation.
pub(super) fn force_one_sew(
&self,
lhs_dart_id: DartIdType,
rhs_dart_id: DartIdType,
) -> Result<(), SewError> {
atomically_with_err(|trans| {
let b2lhs_dart_id = self.betas[(2, lhs_dart_id)].read(trans)?;
if b2lhs_dart_id == NULL_DART_ID {
try_or_coerce!(
self.betas.one_link_core(trans, lhs_dart_id, rhs_dart_id),
SewError
);
} else {
let b2lhs_vid_old = self.vertex_id_transac(trans, b2lhs_dart_id)?;
let rhs_vid_old = self.vertex_id_transac(trans, rhs_dart_id)?;

try_or_coerce!(
self.betas.one_link_core(trans, lhs_dart_id, rhs_dart_id),
SewError
);

let new_vid = self.vertex_id_transac(trans, rhs_dart_id)?;

self.vertices
.merge(trans, new_vid, b2lhs_vid_old, rhs_vid_old)?;
self.attributes.merge_vertex_attributes(
trans,
new_vid,
b2lhs_vid_old,
rhs_vid_old,
)?;
}
Ok(())
})
}
}

#[doc(hidden)]
/// 1-unsews
impl<T: CoordsFloat> CMap2<T> {
/// 1-unsew transactional implementation.
pub(super) fn one_unsew(
&self,
Expand Down Expand Up @@ -124,29 +83,4 @@ impl<T: CoordsFloat> CMap2<T> {
}
Ok(())
}

/// 1-unsew implementation.
pub(super) fn force_one_unsew(&self, lhs_dart_id: DartIdType) -> Result<(), SewError> {
atomically_with_err(|trans| {
let b2lhs_dart_id = self.betas[(2, lhs_dart_id)].read(trans)?;
if b2lhs_dart_id == NULL_DART_ID {
try_or_coerce!(self.betas.one_unlink_core(trans, lhs_dart_id), SewError);
} else {
// fetch IDs before topology update
let rhs_dart_id = self.betas[(1, lhs_dart_id)].read(trans)?;
let vid_old = self.vertex_id_transac(trans, rhs_dart_id)?;
// update the topology
try_or_coerce!(self.betas.one_unlink_core(trans, lhs_dart_id), SewError);
// split vertices & attributes from the old ID to the new ones
let (new_lhs, new_rhs) = (
self.vertex_id_transac(trans, b2lhs_dart_id)?,
self.vertex_id_transac(trans, rhs_dart_id)?,
);
self.vertices.split(trans, new_lhs, new_rhs, vid_old)?;
self.attributes
.split_vertex_attributes(trans, new_lhs, new_rhs, vid_old)?;
}
Ok(())
})
}
}
Loading

0 comments on commit a32a24c

Please sign in to comment.