#![deny(missing_docs)]
#![cfg_attr(test, feature(downcast_unchecked))]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "std")]
pub mod simple_executor;
#[cfg(feature = "std")]
pub use simple_executor::SimpleExecutor;
#[cfg(feature = "std")]
pub mod threadpool_executor;
#[cfg(feature = "std")]
pub use threadpool_executor::ThreadPoolExecutor;
#[cfg(feature = "std")]
pub mod threaded_executor;
#[cfg(feature = "std")]
pub use threaded_executor::ThreadedExecutor;
use core::cmp::{Ord, Ordering};
use ncomm_core::node::Node;
#[cfg(feature = "alloc")]
use alloc::{boxed::Box, vec::Vec};
#[cfg(feature = "std")]
use std::{boxed::Box, vec::Vec};
#[cfg(any(feature = "alloc", feature = "std"))]
pub(crate) struct NodeWrapper<ID: PartialEq> {
pub priority: u128,
pub node: Box<dyn Node<ID>>,
}
#[cfg(any(feature = "alloc", feature = "std"))]
impl<ID: PartialEq> NodeWrapper<ID> {
pub fn destroy(self) -> Box<dyn Node<ID>> {
self.node
}
}
#[cfg(any(feature = "alloc", feature = "std"))]
impl<ID: PartialEq> Ord for NodeWrapper<ID> {
fn cmp(&self, other: &Self) -> Ordering {
self.priority.cmp(&other.priority).reverse()
}
}
#[cfg(any(feature = "alloc", feature = "std"))]
impl<ID: PartialEq> PartialOrd for NodeWrapper<ID> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
#[cfg(any(feature = "alloc", feature = "std"))]
impl<ID: PartialEq> PartialEq for NodeWrapper<ID> {
fn eq(&self, other: &Self) -> bool {
self.priority == other.priority
}
}
#[cfg(any(feature = "alloc", feature = "std"))]
impl<ID: PartialEq> Eq for NodeWrapper<ID> {}
#[cfg(any(feature = "alloc", feature = "std"))]
#[inline(always)]
pub(crate) fn insert_into<ID: PartialEq>(vec: &mut Vec<NodeWrapper<ID>>, node: NodeWrapper<ID>) {
match vec.binary_search(&node) {
Ok(idx) => vec.insert(idx + 1, node),
Err(idx) => vec.insert(idx, node),
}
}