MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / normalize_set

Function normalize_set

compiler/tests/vm.rs:27–39  ·  view source on GitHub ↗

Sets iterate in hash order, so canonicalize a set/frozenset line by sorting its elements. Assumes scalar elements with no nested ", ". Non-sets pass through. */

(line: &str)

Source from the content-addressed store, hash-verified

25 /* Sets iterate in hash order, so canonicalize a set/frozenset line by sorting
26 its elements. Assumes scalar elements with no nested ", ". Non-sets pass through. */
27 fn normalize_set(line: &str) -> String {
28 let (prefix, inner, suffix) = if let Some(i) =
29 line.strip_prefix("frozenset({").and_then(|r| r.strip_suffix("})")) {
30 ("frozenset({", i, "})")
31 } else if line.starts_with('{') && line.ends_with('}') && line.len() > 2 && !line.contains(": ") {
32 ("{", &line[1..line.len() - 1], "}")
33 } else {
34 return line.to_string();
35 };
36 let mut elems: Vec<&str> = inner.split(", ").collect();
37 elems.sort_unstable();
38 format!("{}{}{}", prefix, elems.join(", "), suffix)
39 }
40
41 // Apply set normalization line-by-line so both sides compare order-independent.
42 fn normalize(lines: &[String]) -> Vec<String> {

Callers 1

normalizeFunction · 0.85

Calls 3

collectMethod · 0.80
lenMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected