aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-spdx-licenses/src/lib.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-03 11:55:03 +0900
committernsfisis <nsfisis@gmail.com>2026-05-03 11:55:03 +0900
commitae1aa6540761e54a76b8f7984cf93cd3a0d011d0 (patch)
treef111e1c73977f0bffb6323b03f4210269b43b297 /crates/mozart-spdx-licenses/src/lib.rs
parent30ae6c869adc7f3cb87a4d63edd6d0cda89d571d (diff)
downloadphp-mozart-ae1aa6540761e54a76b8f7984cf93cd3a0d011d0.tar.gz
php-mozart-ae1aa6540761e54a76b8f7984cf93cd3a0d011d0.tar.zst
php-mozart-ae1aa6540761e54a76b8f7984cf93cd3a0d011d0.zip
refactor: switch internal maps/sets from HashMap to IndexMap
Adopt indexmap workspace-wide so iteration order is deterministic and follows insertion order. The non-deterministic order of std HashMap otherwise leaks into resolver decisions when multiple valid solutions exist (e.g. cyclic require pairs under prefer-lowest), making behavior flaky and divergent from Composer's PHP-array semantics. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart-spdx-licenses/src/lib.rs')
-rw-r--r--crates/mozart-spdx-licenses/src/lib.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/crates/mozart-spdx-licenses/src/lib.rs b/crates/mozart-spdx-licenses/src/lib.rs
index 81fa329..668270f 100644
--- a/crates/mozart-spdx-licenses/src/lib.rs
+++ b/crates/mozart-spdx-licenses/src/lib.rs
@@ -1,4 +1,4 @@
-use std::collections::HashMap;
+use indexmap::IndexMap;
use std::sync::LazyLock;
include!(concat!(env!("OUT_DIR"), "/spdx_data.rs"));
@@ -21,16 +21,16 @@ pub struct ExceptionInfo {
/// SPDX license database with expression validation.
pub struct SpdxLicenses {
- licenses: HashMap<&'static str, LicenseInfo>,
- exceptions: HashMap<&'static str, ExceptionInfo>,
- name_to_id: HashMap<&'static str, &'static str>,
+ licenses: IndexMap<&'static str, LicenseInfo>,
+ exceptions: IndexMap<&'static str, ExceptionInfo>,
+ name_to_id: IndexMap<&'static str, &'static str>,
}
impl SpdxLicenses {
/// Build the license database from generated data.
pub fn new() -> Self {
- let mut licenses = HashMap::with_capacity(LICENSES.len());
- let mut name_to_id = HashMap::with_capacity(LICENSES.len());
+ let mut licenses = IndexMap::with_capacity(LICENSES.len());
+ let mut name_to_id = IndexMap::with_capacity(LICENSES.len());
for &(lower, id, full_name, osi, deprecated) in LICENSES {
licenses.insert(
lower,
@@ -44,7 +44,7 @@ impl SpdxLicenses {
name_to_id.insert(full_name, id);
}
- let mut exceptions = HashMap::with_capacity(EXCEPTIONS.len());
+ let mut exceptions = IndexMap::with_capacity(EXCEPTIONS.len());
for &(lower, id, full_name) in EXCEPTIONS {
exceptions.insert(
lower,