@@ -2,6 +2,7 @@ use pkcore::PKError;
22use pkcore:: play:: stages:: deal_eval:: DealEval ;
33use pkcore:: prelude:: HoleCards ;
44use pkcore:: util:: terminal:: Terminal ;
5+ use std:: collections:: HashMap ;
56
67/// OK, this makes me sad. My new shiny pkcore library takes over twice as long to run a single calc
78///
@@ -27,14 +28,15 @@ use pkcore::util::terminal::Terminal;
2728/// `A♠ A♥ A♦ A♣`
2829fn main ( ) {
2930 env_logger:: init ( ) ;
31+ let mut cache: HashMap < HoleCards , DealEval > = HashMap :: new ( ) ;
3032 loop {
31- read_input ( ) ;
33+ read_input ( & mut cache ) ;
3234 }
3335}
3436
35- fn read_input ( ) {
37+ fn read_input ( cache : & mut HashMap < HoleCards , DealEval > ) {
3638 match Terminal :: receive_cards_in_twos ( "hole cards> " ) {
37- Ok ( twos) => match work ( twos) {
39+ Ok ( twos) => match work ( twos, cache ) {
3840 Ok ( _) => { }
3941 Err ( e) => println ! ( "{:?}" , e) ,
4042 } ,
@@ -44,18 +46,12 @@ fn read_input() {
4446 }
4547}
4648
47- fn work ( hands : HoleCards ) -> Result < ( ) , PKError > {
49+ fn work ( hands : HoleCards , cache : & mut HashMap < HoleCards , DealEval > ) -> Result < ( ) , PKError > {
4850 let now = std:: time:: Instant :: now ( ) ;
4951
50- let results = DealEval :: new ( hands ) ;
52+ let results = cache . entry ( hands ) . or_insert_with_key ( |h| DealEval :: new ( h . clone ( ) ) ) ;
5153
52- // let case_events = hands.bcm_case_evals()?;
53- // let case_events = hands.bcm_case_evals()?;
54- // let case_events = hands.bcm_rayon_case_evals()?;
55- // let wins = case_events.wins();
56- // let results = WinResults::from_wins(&wins, hands.len());
5754 println ! ( "{results}" ) ;
58-
5955 println ! ( "Elapsed: {:.2?}" , now. elapsed( ) ) ;
6056 Ok ( ( ) )
6157}
0 commit comments