pub fn add_dependency<J: IntoJob<C, E> + PartialEq>(&mut self, job: J) -> Result<(), Error<E>> {
        // This is where the magic happens. This method performs a *partial* topological sort (aka
        // "dependency resolution" or "dependency ordering") of `job` and all its dependencies. We
        // say *partial* because instead of a complete ordering of jobs this implementation produces
        // a "ready queue" (`self.ready`) containing only the jobs which are currently ready to run.
        //
        // The reason for this difference is that it simplifies the implementation of parallel job
        // scheduling. When the scheduler has capacity to run a new job, the next one is simply
        // pulled from the ready queue without needing to iterate over the full list of jobs to
        // check dependencies.

        // If this job is already part of the job plan, get its index and add it
        // as a dependency of the current parent.
        if let Some(idx) = self.index_of(&job) {
            if self.ancestors.contains(&idx) {
                return Err(Error::Cycle);
            }

            self.jobs[idx].dependents.insert(self.current_parent);
            self.jobs[self.current_parent].dependencies.insert(idx);
            return Ok(());
        }

        // If we haven't seen this job before, add an entry for it. Then call plan() recursively to
        // get its dependencies and other job information.

        let idx = self.jobs.len();
        let job = Rc::new(job);
        self.jobs.push(PlanBuilderEntry {
            job: job.clone(),
            dependencies: HashSet::new(),
            dependents: HashSet::from_iter(vec![self.current_parent]),
        });
        self.jobs[self.current_parent].dependencies.insert(idx);

        self.ancestors.insert(idx);
        let prev_parent = mem::replace(&mut self.current_parent, idx);
        job.plan(self)?;
        self.current_parent = prev_parent;
        self.ancestors.remove(&idx);

        if self.jobs[idx].dependencies.is_empty() {
            self.ready.push(idx);
        }

        Ok(())
    }
/// Adds `job` to the job plan as a dependency of the current job.
Adds `job` to the job plan as a dependency of the current job.
Adds ` job ` to the job plan as a dependency of the current job .
pub fn add_dependency<J: IntoJob<C, E> + PartialEq>(&mut self, job: J) -> Result<(), Error<E>> {
        // This is where the magic happens. This method performs a *partial* topological sort (aka
        // "dependency resolution" or "dependency ordering") of `job` and all its dependencies. We
        // say *partial* because instead of a complete ordering of jobs this implementation produces
        // a "ready queue" (`self.ready`) containing only the jobs which are currently ready to run.
        //
        // The reason for this difference is that it simplifies the implementation of parallel job
        // scheduling. When the scheduler has capacity to run a new job, the next one is simply
        // pulled from the ready queue without needing to iterate over the full list of jobs to
        // check dependencies.
        // If this job is already part of the job plan, get its index and add it
        // as a dependency of the current parent.
        if let Some(idx) = self.index_of(&job) {
            if self.ancestors.contains(&idx) {
                return Err(Error::Cycle);
            }
            self.jobs[idx].dependents.insert(self.current_parent);
            self.jobs[self.current_parent].dependencies.insert(idx);
            return Ok(());
        }
        // If we haven't seen this job before, add an entry for it. Then call plan() recursively to
        // get its dependencies and other job information.
        let idx = self.jobs.len();
        let job = Rc::new(job);
        self.jobs.push(PlanBuilderEntry {
            job: job.clone(),
            dependencies: HashSet::new(),
            dependents: HashSet::from_iter(vec![self.current_parent]),
        });
        self.jobs[self.current_parent].dependencies.insert(idx);
        self.ancestors.insert(idx);
        let prev_parent = mem::replace(&mut self.current_parent, idx);
        job.plan(self)?;
        self.current_parent = prev_parent;
        self.ancestors.remove(&idx);
        if self.jobs[idx].dependencies.is_empty() {
            self.ready.push(idx);
        }
        Ok(())
    }
pub fn add_dependency < J : IntoJob < C , E > + PartialEq > ( & mut self , job : J ) -> Result < ( ) , Error < E > > { // This is where the magic happens. This method performs a *partial* topological sort (aka // "dependency resolution" or "dependency ordering") of `job` and all its dependencies. We // say *partial* because instead of a complete ordering of jobs this implementation produces // a "ready queue" (`self.ready`) containing only the jobs which are currently ready to run. // // The reason for this difference is that it simplifies the implementation of parallel job // scheduling. When the scheduler has capacity to run a new job, the next one is simply // pulled from the ready queue without needing to iterate over the full list of jobs to // check dependencies. // If this job is already part of the job plan, get its index and add it // as a dependency of the current parent. if let Some ( idx ) = self . index_of ( & job ) { if self . ancestors . contains ( & idx ) { return Err ( Error :: Cycle ) ; } self . jobs [ idx ] . dependents . insert ( self . current_parent ) ; self . jobs [ self . current_parent ] . dependencies . insert ( idx ) ; return Ok ( ( ) ) ; } // If we haven't seen this job before, add an entry for it. Then call plan() recursively to // get its dependencies and other job information. let idx = self . jobs . len ( ) ; let job = Rc :: new ( job ) ; self . jobs . push ( PlanBuilderEntry { job : job . clone ( ) , dependencies : HashSet :: new ( ) , dependents : HashSet :: from_iter ( vec ! [ self current_parent ] ) , } ) ; self . jobs [ self . current_parent ] . dependencies . insert ( idx ) ; self . ancestors . insert ( idx ) ; let prev_parent = mem :: replace ( & mut self . current_parent , idx ) ; job . plan ( self ) ? ; self . current_parent = prev_parent ; self . ancestors . remove ( & idx ) ; if self . jobs [ idx ] . dependencies . is_empty ( ) { self . ready . push ( idx ) ; } Ok ( ( ) ) }
Adds `job` to the job plan as a dependency of the current job.
Adds ` job ` to the job plan as a dependency of the current job .
&mut self
job
J