parallel_frontier 0.1.1

Queue-like frontier for breath-first visits on graphs that supports constant-time concurrent pushes and parallel iteration
Documentation
/*
 * SPDX-FileCopyrightText: 2025 Tommaso Fontana
 * SPDX-FileCopyrightText: 2025 Luca Cappelletti
 *
 * SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
 */

use crate::*;
use rayon::iter::{ParallelIterator, plumbing::bridge_unindexed};

pub struct FrontierParIter<'a, T> {
    pub(crate) father: &'a Frontier<'a, T>,
}

impl<'a, T> FrontierParIter<'a, T> {
    pub fn new(father: &'a Frontier<T>) -> Self {
        FrontierParIter { father }
    }
}

impl<'a, T: Send + Sync> ParallelIterator for FrontierParIter<'a, T> {
    type Item = &'a T;

    fn drive_unindexed<C>(self, consumer: C) -> C::Result
    where
        C: rayon::iter::plumbing::UnindexedConsumer<Self::Item>,
    {
        bridge_unindexed(FrontierIter::new(self.father), consumer)
    }

    fn opt_len(&self) -> Option<usize> {
        None
    }
}