File tree Expand file tree Collapse file tree 6 files changed +14
-18
lines changed
Expand file tree Collapse file tree 6 files changed +14
-18
lines changed Original file line number Diff line number Diff line change 66//! resistant but slower hashing algorithm. [`FxHasher`] is much faster (between 2x to 5x from my testing).
77use std:: collections:: { HashMap , HashSet } ;
88use std:: hash:: { BuildHasher , Hash , Hasher } ;
9- use std:: ops:: BitXor as _;
109
1110/// Type alias for [`HashSet`] using [`FxHasher`].
1211pub type FastSet < T > = HashSet < T , BuildFxHasher > ;
@@ -92,7 +91,7 @@ pub struct FxHasher {
9291impl FxHasher {
9392 #[ inline]
9493 fn add ( & mut self , i : u64 ) {
95- self . hash = self . hash . rotate_left ( 5 ) . bitxor ( i) . wrapping_mul ( K ) ;
94+ self . hash = ( self . hash . rotate_left ( 5 ) ^ i) . wrapping_mul ( K ) ;
9695 }
9796}
9897
Original file line number Diff line number Diff line change @@ -297,8 +297,7 @@ pub mod simd {
297297 m : Simd < u32 , N > ,
298298 s : u32 ,
299299 k : u32 ,
300- ) -> Simd < u32 , N >
301- where {
300+ ) -> Simd < u32 , N > {
302301 let f = b ^ c ^ d;
303302 common ( f, a, b, m, s, k)
304303 }
@@ -312,8 +311,7 @@ where {
312311 m : Simd < u32 , N > ,
313312 s : u32 ,
314313 k : u32 ,
315- ) -> Simd < u32 , N >
316- where {
314+ ) -> Simd < u32 , N > {
317315 let f = c ^ ( b | !d) ;
318316 common ( f, a, b, m, s, k)
319317 }
@@ -326,8 +324,7 @@ where {
326324 m : Simd < u32 , N > ,
327325 s : u32 ,
328326 k : u32 ,
329- ) -> Simd < u32 , N >
330- where {
327+ ) -> Simd < u32 , N > {
331328 let k = Simd :: splat ( k) ;
332329 let first = f + a + k + m;
333330 let second = ( first << s) | ( first >> ( 32 - s) ) ;
Original file line number Diff line number Diff line change @@ -12,15 +12,15 @@ totally-real-room-200[decoy]";
1212// order regardless of the order of skipped letters. Go with the looser interpretation, since
1313// it gives slightly faster code, and no one has reported an input file where it fails. However,
1414// when there is more than one higher-frequency letter, both should be in the checksum.
15- const EXAMPLE2 : & str = "\
15+ const SECOND_EXAMPLE : & str = "\
1616 a-b-c-d-e-f-g-h-001[bcdef]
1717aa-bb-c-d-e-f-g-h-002[acdef]" ;
1818
1919#[ test]
2020fn part1_test ( ) {
2121 let input = parse ( EXAMPLE ) ;
2222 assert_eq ! ( part1( & input) , 1514 ) ;
23- let input = parse ( EXAMPLE2 ) ;
23+ let input = parse ( SECOND_EXAMPLE ) ;
2424 assert_eq ! ( part1( & input) , 1 ) ;
2525}
2626
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ const EXAMPLE: &str = "\
111121037: 9 7 18 13
1212292: 11 6 16 20" ;
1313
14- const EXAMPLE2 : & str = "\
14+ const SECOND_EXAMPLE : & str = "\
1515 190: 10 19
161611174: 15 8 9 79 74
1717729: 6 6 7 37 650" ;
@@ -20,14 +20,14 @@ const EXAMPLE2: &str = "\
2020fn part1_test ( ) {
2121 let input = parse ( EXAMPLE ) ;
2222 assert_eq ! ( part1( & input) , 3749 ) ;
23- let input2 = parse ( EXAMPLE2 ) ;
23+ let input2 = parse ( SECOND_EXAMPLE ) ;
2424 assert_eq ! ( part1( & input2) , 190 ) ;
2525}
2626
2727#[ test]
2828fn part2_test ( ) {
2929 let input = parse ( EXAMPLE ) ;
3030 assert_eq ! ( part2( & input) , 11387 ) ;
31- let input2 = parse ( EXAMPLE2 ) ;
31+ let input2 = parse ( SECOND_EXAMPLE ) ;
3232 assert_eq ! ( part2( & input2) , 11364 ) ;
3333}
Original file line number Diff line number Diff line change @@ -57,5 +57,5 @@ fn part1_test() {
5757
5858#[ test]
5959fn part2_test ( ) {
60- // No test
60+ // No example data
6161}
Original file line number Diff line number Diff line change 11use aoc:: year2025:: day11:: * ;
22
3- const EXAMPLE_ONE : & str = "\
3+ const FIRST_EXAMPLE : & str = "\
44 aaa: you hhh
55you: bbb ccc
66bbb: ddd eee
@@ -12,7 +12,7 @@ ggg: out
1212hhh: ccc fff iii
1313iii: out" ;
1414
15- const EXAMPLE_TWO : & str = "\
15+ const SECOND_EXAMPLE : & str = "\
1616 svr: aaa bbb
1717aaa: fft
1818fft: ccc
@@ -29,12 +29,12 @@ hhh: out";
2929
3030#[ test]
3131fn part1_test ( ) {
32- let input = parse ( EXAMPLE_ONE ) ;
32+ let input = parse ( FIRST_EXAMPLE ) ;
3333 assert_eq ! ( part1( & input) , 5 ) ;
3434}
3535
3636#[ test]
3737fn part2_test ( ) {
38- let input = parse ( EXAMPLE_TWO ) ;
38+ let input = parse ( SECOND_EXAMPLE ) ;
3939 assert_eq ! ( part2( & input) , 2 ) ;
4040}
You can’t perform that action at this time.
0 commit comments