Skip to content

Commit 08ad6fd

Browse files
committed
Optimize calc24 hashing and deduplication
Use structural equality for expression sets and exact multiset keys for subset pruning in both Rust and C++. Improve expression ownership and move paths, widen cached hashes, and raise the C++ optimization level. Also refresh Cargo feature declarations and rustfmt configuration.
1 parent cfd1001 commit 08ad6fd

7 files changed

Lines changed: 236 additions & 154 deletions

File tree

‎Cargo.toml‎

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
### https://doc.rust-lang.org/cargo/reference/manifest.html
3-
# rustup override set nightly
3+
# Optional for nightly-only experiments: rustup override set nightly
44

55
[package]
66
name = "inrust"
@@ -9,18 +9,19 @@ edition.workspace = true
99
version.workspace = true
1010
license.workspace = true
1111
authors.workspace = true
12-
homepage.workspace = true
13-
repository.workspace = true
12+
repository.workspace = true
13+
homepage.workspace = true
14+
1415
description = "Accumulate knowledge of my study on Rust language"
1516
categories = [ "command-line-utilities", "games", "mathematics" ]
1617
keywords = [ "24-game", "24-solver", "24-puzzle", "24-challenge" ]
1718
exclude = [ "README-DSP.md", "tmp" ] # "tests", "benches", "fuzz"
1819
#publish = [ "crates-io" ] # cargo publish --registry crates-io
1920

20-
#build = "build.rs" # default, build = false
21+
#build = "build.rs" # auto-discovered by default; use `build = false` to disable it
2122

2223
[workspace.package]
23-
edition = "2021" # use 'cargo fix' to fix for compatibility with different Rust edition.
24+
edition = "2021" # use `cargo fix --edition` before migrating to a newer edition
2425
version = "0.3.9"
2526
#readme = "README.md"
2627
license = "MIT OR Apache-2.0"
@@ -54,8 +55,8 @@ cxx = { version = "1.0", optional = true }
5455
dhat = { version = "0.3", optional = true }
5556
pprof = { version = "0.15", features = [ "flamegraph", "criterion" ], optional = true }
5657

57-
gxhash = { version = "3.4", optional = true }
5858
ahash = { version = "0.8", optional = true } # https://github.com/tkaitchuck/aHash
59+
gxhash = { version = "3.4", optional = true }
5960
num-bigint = { version = "0.4", optional = true }
6061
num-rational = { version = "0.4", optional = true }
6162
serde = { version = "1", features = [ "derive" ], optional = true }
@@ -70,9 +71,6 @@ regex = "1.12"
7071
rand = "0.9"
7172
#csv = "1.1"
7273

73-
[lints.rust]
74-
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage_nightly)'] }
75-
7674
[build-dependencies] # used for compiling build script
7775
cc = { version = "1.2", features = [ "parallel" ], optional = true }
7876
cxx-build = { version = "1.0", optional = true }
@@ -81,10 +79,10 @@ chrono = "0.4"
8179

8280
[features]
8381
debug = []
84-
cli = [ "yansi", "rand" ]
85-
cxx = [ "dep:cxx", "cxx-build" ] # implied by optional dependency
86-
default = [ "cc", "cli", "ahash" ] # "gxhash", "cxx", "serde", "num-rational", "num-bigint",
87-
dhat-heap = [ "dhat" ]
82+
cli = [ "dep:yansi", "dep:rand" ]
83+
cxx = [ "dep:cxx", "dep:cxx-build" ] # `dep:` avoids implicit dependency features
84+
default = [ "cc", "cli", "ahash" ] # opt-in alternatives: "gxhash", "cxx", "serde", etc.
85+
dhat-heap = [ "dep:dhat" ]
8886

8987
[[bin]]
9088
name = "inrust"
@@ -93,8 +91,7 @@ required-features = [ "cli" ]
9391
[[bench]]
9492
name = "calc24_bench"
9593
#path = "benches/calc24_bench.rs"
96-
#cargo_bench_support = true
97-
#html_reports = false
94+
# Criterion HTML reports are configured by Criterion, not as `[[bench]]` keys.
9895
harness = false
9996

10097
#[lib]
@@ -109,21 +106,23 @@ opt-level = 1 # Enable a small amount of optimization in debug mode
109106
opt-level = 3 # Enable high optimizations for dependencies, but not for own code.
110107

111108
[profile.release]
112-
codegen-units = 1 # Perform optimizations on all codegen units.
113-
strip = 'debuginfo' # keep 'symbols'
114-
panic = 'abort' # Do not perform backtrace for panic on release builds.
109+
codegen-units = 1 # Optimize the crate as one codegen unit; slower build, potentially faster code.
110+
strip = 'debuginfo' # Remove debug information while retaining symbols where the platform supports it.
111+
panic = 'abort' # Abort instead of unwinding; panic hooks may still print a message/backtrace.
115112
#debug = 'full' # for flamegraph
116113
#opt-level = 3 # default level
117-
lto = 'fat' # true
114+
lto = 'fat' # `true` also selects fat LTO.
118115

119116
#cargo build -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort
120117

121118
#[profile.release-lto] # customized profile
122119
#inherits = "release"
123120

121+
[lints.rust]
122+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage_nightly)'] }
123+
124124
[workspace]
125125
members = [] #"inperse", "indiox", #"fuzz",
126126
#"inyew", "inyew/src-tauri", #"inslint", "inegui",
127127
#exclude = [ "indsp", "inbevy", "inwasm", "cortex-m" ]
128-
#resolver = "2" # default for 2021 edition?
129-
128+
#resolver = "2" # Match edition 2021 dependency-feature resolution explicitly.

‎benches/calc24_bench.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn bench_24calc(c: &mut Criterion) {
2323
let nums = nums.into_iter().map(|n| n.into()).collect::<Vec<_>>();
2424
let (goal, mut cnt) = (goal.into(), 0);
2525

26-
for algo in [ DynProg, Construct ] { // XXX: SplitSet, Inplace,
26+
for algo in [ DynProg, SplitSet, Inplace, Construct ] { // XXX:
2727
let mut bench_closure = |algo, cxx: &str| {
2828
group.bench_function(format!("{cxx}{algo:?}"), |b| b.iter(|| {
2929
if cxx.is_empty() { cnt = calc24_coll(&goal, &nums, algo).len(); } else {

‎build.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn main() { // https://doc.rust-lang.org/stable/cargo/reference/build-script
2020

2121
#[cfg(any(feature = "cc", feature = "cxx"))] { calc24_file.set_extension("cpp");
2222
build.cpp(true).flag("-std=c++20").flag("-Wno-misleading-indentation")
23-
.opt_level(2).define("NDEBUG", None).file(&calc24_file).compile("calc24");
23+
.opt_level(3).define("NDEBUG", None).file(&calc24_file).compile("calc24");
2424

2525
println!("cargo:rerun-if-changed={}", calc24_file.display());
2626
println!("cargo:rerun-if-changed={}", calc24_file.with_extension("h").display());

‎indiox/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ version = "0.1.6"
1616
[dependencies]
1717
dioxus = { version = "0.7" } #, features = [ "fullstack", "router" ]
1818

19-
web-sys = { version = "=0.3.78", features = [ 'Window', 'Document',
19+
web-sys = { version = "0.3", features = [ 'Window', 'Document',
2020
'HtmlInputElement', 'HtmlCollection', #'HtmlCanvasElement', 'CanvasRenderingContext2d'
2121
] } # XXX: failed to build on macOS for web-sys v0.3.79~82 and wasm-bindgen v0.2.102~105
2222

‎rustfmt.toml‎

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,47 @@
33
# rustfmt --print-config default # rustfmt --print-config current rustfmt.toml
44

55
unstable_features = true
6-
edition = "2021"
7-
version = "Two"
6+
style_edition = "2024"
7+
#edition = "2024"
8+
9+
#ignore = ["/"] # Skip formatting files
10+
11+
use_small_heuristics = "Max"
12+
max_width = 96
13+
14+
#array_width = 80
15+
#chain_width = 80
16+
#fn_call_width = 80
17+
#struct_lit_width = 80
18+
#attr_fn_like_width = 80
19+
#struct_variant_width = 80
20+
#single_line_if_else_max_width = 80
21+
#single_line_let_else_max_width = 80
22+
23+
short_array_element_width_threshold = 32
24+
#enum_discrim_align_threshold = 32
25+
#struct_field_align_threshold = 32
26+
inline_attribute_width = 96
27+
comment_width = 96
28+
829
binop_separator = "Back"
930
fn_params_layout = "Compressed"
1031
brace_style = "PreferSameLine"
32+
imports_granularity = "Crate" # "Module"
33+
group_imports = "StdExternalCrate"
34+
#imports_indent = "Visual"
35+
#indent_style = "Visual"
36+
1137
condense_wildcard_suffixes = true
1238
format_code_in_doc_comments = true
1339
format_macro_matchers = true
40+
format_macro_bodies = false
1441
format_strings = true
1542
fn_single_line = true
16-
#imports_indent = "Visual"
17-
#indent_style = "Visual"
43+
wrap_comments = true
1844
match_arm_blocks = false
1945
where_single_line = true
2046
overflow_delimited_expr = true
2147
use_field_init_shorthand = true
2248
normalize_doc_attributes = true
23-
imports_granularity = "Module"
24-
group_imports = "StdExternalCrate"
25-
short_array_element_width_threshold = 20
26-
enum_discrim_align_threshold = 20
27-
inline_attribute_width = 80
28-
struct_lit_width = 50
2949

0 commit comments

Comments
 (0)