Skip to content

Commit

Permalink
Remove the packed_kpuzzle arg from .apply_transformation(…).
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarron committed Aug 23, 2023
1 parent 59d8204 commit a98834f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 30 deletions.
11 changes: 3 additions & 8 deletions examples/cpp_port/packed/packed_kstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,20 @@ impl PackedKState {

// Adapted from https://github.com/cubing/cubing.rs/blob/b737c6a36528e9984b45b29f9449a9a330c272fb/src/kpuzzle/state.rs#L31-L82
// TODO: dedup the implementation (but avoid runtime overhead for the shared abstraction).
pub fn apply_transformation(
&self,
packed_kpuzzle: &PackedKPuzzle,
transformation: &PackedKTransformation,
) -> PackedKState {
pub fn apply_transformation(&self, transformation: &PackedKTransformation) -> PackedKState {
let mut new_state = PackedKState::new(self.packed_kpuzzle.clone());
self.apply_transformation_into(packed_kpuzzle, transformation, &mut new_state);
self.apply_transformation_into(transformation, &mut new_state);
new_state
}

// Adapted from https://github.com/cubing/cubing.rs/blob/b737c6a36528e9984b45b29f9449a9a330c272fb/src/kpuzzle/state.rs#L31-L82
// TODO: dedup the implementation (but avoid runtime overhead for the shared abstraction).
pub fn apply_transformation_into(
&self,
packed_kpuzzle: &PackedKPuzzle,
transformation: &PackedKTransformation,
into_state: &mut PackedKState,
) {
for orbit_info in &packed_kpuzzle.data.orbit_iteration_info {
for orbit_info in &self.packed_kpuzzle.data.orbit_iteration_info {
// TODO: optimization when either value is the identity.
for i in 0..orbit_info.num_pieces {
let transformation_idx = transformation.get_piece_or_permutation(orbit_info, i);
Expand Down
28 changes: 6 additions & 22 deletions examples/test-cpp_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,8 @@ fn test_packed(num_moves: usize) {
let mut other = packed_kpuzzle.start_state();
let start = Instant::now();
for i in (0..num_moves).step_by(2) {
current.apply_transformation_into(
&packed_kpuzzle,
&move_transformations[i % 18],
&mut other,
);
other.apply_transformation_into(
&packed_kpuzzle,
&move_transformations[(i + 1) % 18],
&mut current,
);
current.apply_transformation_into(&move_transformations[i % 18], &mut other);
other.apply_transformation_into(&move_transformations[(i + 1) % 18], &mut current);
}
if PRINT_FINAL_STATE {
println!("{:?}", current.byte_slice());
Expand All @@ -78,7 +70,7 @@ fn test_packed(num_moves: usize) {
let mut state = packed_kpuzzle.start_state();
let start = Instant::now();
for i in 0..num_moves {
state = state.apply_transformation(&packed_kpuzzle, &move_transformations[i % 18]);
state = state.apply_transformation(&move_transformations[i % 18]);
}
if PRINT_FINAL_STATE {
println!("{:?}", state.byte_slice());
Expand All @@ -98,17 +90,9 @@ fn test_packed(num_moves: usize) {
let mut other = packed_kpuzzle.start_state();
let start = Instant::now();
for i in (0..num_moves).step_by(2) {
current.apply_transformation_into(
&packed_kpuzzle,
&move_transformations[i % 18],
&mut other,
);
current.apply_transformation_into(&move_transformations[i % 18], &mut other);
_ = current.hash();
other.apply_transformation_into(
&packed_kpuzzle,
&move_transformations[(i + 1) % 18],
&mut current,
);
other.apply_transformation_into(&move_transformations[(i + 1) % 18], &mut current);
_ = other.hash();
}
if PRINT_FINAL_STATE {
Expand All @@ -128,7 +112,7 @@ fn test_packed(num_moves: usize) {
let mut state = packed_kpuzzle.start_state();
let start = Instant::now();
for i in 0..num_moves {
state = state.apply_transformation(&packed_kpuzzle, &move_transformations[i % 18]);
state = state.apply_transformation(&move_transformations[i % 18]);
// _ = state.hash()
}
if PRINT_FINAL_STATE {
Expand Down

0 comments on commit a98834f

Please sign in to comment.