<commit_before>use std::hash;
use std::hash::Hash;
use std::int::MAX;
use std::num::Int;

/// Our fixed-point loop needs a way of hashing the "current state" (type `St`).
/// The details of what states are and how they relate need not be revealed.
/// We hide all of these details in a "state system" (type `Sys`).
/// `next` checks for unstepped states to become the "current state".
/// `step` updates the system at the "current state".
trait Step {
    type St : Hash ;
    type Sys ;
    fn step (st:Self::St, sys:Self::Sys) -> Self::Sys ;
    fn next (sys:Self::Sys) -> Option<Self::St> ;
}

trait Fp<S:Step> {
    fn work_tree (left_lev:int, sys:S::Sys, parent_lev:int) -> S::Sys ;
    fn fp ( st:S::Sys ) -> S::Sys ;
}

struct FpS;

impl<S:Step> Fp<S> for FpS {
    
    fn work_tree (left_lev:int, sys:S::Sys, parent_lev:int) -> S::Sys {

        panic!("!");
        // let nxt = Step::next(sys) ;
        // match nxt {
        //     None => sys,
        //     Some(st) => {
        //         let st_lev = Int::trailing_zeros(hash::hash(&st)) as int ;
        //         if ( left_lev <= st_lev &&
        //              st_lev   <= parent_lev )
        //         {
        //             let sys = Step::step(st, sys) ;
        //             let sys = Fp::work_tree ( -1,     sys, st_lev );
        //             let sys = Fp::work_tree ( st_lev, sys, parent_lev );
        //             sys
        //         }
        //         else {
        //             sys
        //         }
        //     }
        // }
        
    }
    
    fn fp (sys:S::Sys) -> S::Sys {
        //Fp::work_tree (-1, sys, MAX );
        panic!("!");
    }
}<commit_msg>fixed type issues in balfp; learning more about traits in Rust<commit_after>use std::hash;
use std::hash::Hash;
use std::int::MAX;
use std::num::Int;
use std::result::Result;

trait FpFn {
    // Fixed-point Function.
    //
    /// The Self type need not be stateful at all.
    ///
    /// Instead, a FpFn exposes its state (abstractly) to the loop
    /// that contains it.  There are two parts:
    //
    ///  - The loop iteration's current state (type `St`)
    //
    ///  - Any "meta-state" needed to explore the space of states
    ///  (type `Sys`)
    //
    /// Our fixed-point loop needs a way of hashing the "current
    /// state" (type `St`).  The details of what states are and how
    /// they relate need not be revealed.  We hide all of these
    /// details in a "state system" (type `Sys`).  `next` checks for
    /// unstepped states to become the "current state", or returns Err
    /// if no unexplored states exist.  `step` updates the system at
    /// the "current state".
    
    type St : Hash ;
    type Sys ;
    fn step (self:& Self, st:Self::St, sys:Self::Sys) -> Self::Sys ;
    fn next (self:& Self, sys:Self::Sys) -> Result<(Self::St, Self::Sys), Self::Sys> ;
}

trait FpLp<F:FpFn> {
    fn work_tree (self:&Self, f:&F, left_lev:int, sys:F::Sys, parent_lev:int) -> F::Sys {
        let nxt = f.next(sys) ;
        match nxt {
            Err(sys) => sys,
            Ok((st,sys)) => {
                let st_lev = Int::trailing_zeros(hash::hash(&st)) as int ;
                if ( left_lev <= st_lev &&
                     st_lev   <= parent_lev )
                {
                    let sys : F::Sys = f.step(st, sys) ;
                    let sys : F::Sys = self.work_tree (f, -1,     sys, st_lev );
                    let sys : F::Sys = self.work_tree (f, st_lev, sys, parent_lev );
                    sys
                }
                else {
                    sys
                }
            }
        }    
    }    
    fn compute (self:&Self, f:&F, sys:F::Sys) -> F::Sys {
        self.work_tree (f, -1, sys, MAX )
    }
}
{'fraction_non_alphanumeric': 0.15431769722814498, 'fraction_numerical': 0.0010660980810234541, 'mean_word_length': 1.595435684647303, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3042568', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1216, 'n_words': 368}