diff --git a/julia/PolyCube.jl b/julia/PolyCube.jl index 9ce692b..21a1b4f 100644 --- a/julia/PolyCube.jl +++ b/julia/PolyCube.jl @@ -23,20 +23,29 @@ function _calculate_oriented_differences(cubes::Vector{Coord}) n_cubes = length(cubes) reorientation = Vector{Coord}(undef, n_cubes) oriented_differences = Vector{Vector{Coord}}(undef, n_orientations) - for i ∈ 1:n_orientations + + sort!(cubes) + _compute_differences!(oriented_differences, cubes, 1) + + for i ∈ 2:n_orientations for j ∈ 1:n_cubes reorientation[j] = orient_tuple(cubes[j], i) end sort!(reorientation) - reference_cube = reorientation[1] - oriented_differences[i] = Vector{Coord}(undef, n_cubes-1) - for j ∈ 1:n_cubes-1 - oriented_differences[i][j] = reference_cube - reorientation[j+1] - end + _compute_differences!(oriented_differences, reorientation, i) end return oriented_differences end +function _compute_differences!(oriented_differences::Vector{Vector{Coord}}, reorientation::Vector{Coord}, i::Int) + n_cubes = length(reorientation) + reference_cube = reorientation[1] + oriented_differences[i] = Vector{Coord}(undef, n_cubes-1) + for j ∈ 1:n_cubes-1 + oriented_differences[i][j] = reference_cube - reorientation[j+1] + end +end + function generate_children(pcube::PolyCube, n_max::Int) cubes = pcube.cubes allowed_growth = n_max - length(cubes) diff --git a/test_results b/test_results deleted file mode 100644 index 1dc848c..0000000 --- a/test_results +++ /dev/null @@ -1,12 +0,0 @@ -=====|main|===== -BenchmarkTools.Trial: 36 samples with 1 evaluation. - Range (min … max): 131.581 ms … 159.500 ms ┊ GC (min … max): 0.00% … 3.94% - Time (median): 137.621 ms ┊ GC (median): 0.00% - Time (mean ± σ): 140.185 ms ± 7.360 ms ┊ GC (mean ± σ): 1.12% ± 1.50% - - ▃▃▃ █ █ ▃ ▃ ▃ ▃ - ▇███▁▇▁▁█▇█▇▇█▁█▁▁▁▇▇▇█▁▁▇▇▁▁▁▇▁▇▁▁▁▁▁█▁▁▁▇▁▁▁▁▁▁▁▇▁▁▁▁▁▁▁▇▁▇ ▁ - 132 ms Histogram: frequency by time 160 ms < - - Memory estimate: 16.63 MiB, allocs estimate: 371299. -