cargo::util

Struct DependencyQueue

source
pub struct DependencyQueue<N: Hash + Eq, E: Hash + Eq, V> {
    dep_map: HashMap<N, (HashSet<(N, E)>, V)>,
    reverse_dep_map: HashMap<N, HashMap<E, HashSet<N>>>,
    priority: HashMap<N, usize>,
    cost: HashMap<N, usize>,
}

Fields§

§dep_map: HashMap<N, (HashSet<(N, E)>, V)>

A list of all known keys to build.

The value of the hash map is list of dependencies which still need to be built before the package can be built. Note that the set is dynamically updated as more dependencies are built.

§reverse_dep_map: HashMap<N, HashMap<E, HashSet<N>>>

A reverse mapping of a package to all packages that depend on that package.

This map is statically known and does not get updated throughout the lifecycle of the DependencyQueue.

This is sort of like a HashMap<(N, E), HashSet<N>> map, but more easily indexable with just an N

§priority: HashMap<N, usize>

The relative priority of this package. Higher values should be scheduled sooner.

§cost: HashMap<N, usize>

An expected cost for building this package. Used to determine priority.

Implementations§

source§

impl<N: Hash + Eq, E: Hash + Eq, V> DependencyQueue<N, E, V>

source

pub fn new() -> DependencyQueue<N, E, V>

Creates a new dependency queue with 0 packages.

source§

impl<N: Hash + Eq + Clone, E: Eq + Hash + Clone, V> DependencyQueue<N, E, V>

source

pub fn queue( &mut self, key: N, value: V, dependencies: impl IntoIterator<Item = (N, E)>, cost: usize, )

Adds a new node and its dependencies to this queue.

The key specified is a new node in the dependency graph, and the node depend on all the dependencies iterated by dependencies. Each dependency is a node/edge pair, where edges can be thought of as productions from nodes (aka if it’s just () it’s just waiting for the node to finish).

An optional value can also be associated with key which is reclaimed when the node is ready to go.

The cost parameter can be used to hint at the relative cost of building this node. This implementation does not care about the units of this value, so the calling code is free to use whatever they’d like. In general, higher cost nodes are expected to take longer to build.

source

pub fn queue_finished(&mut self)

All nodes have been added, calculate some internal metadata and prepare for dequeue.

source

pub fn dequeue(&mut self) -> Option<(N, V, usize)>

Dequeues a package that is ready to be built.

A package is ready to be built when it has 0 un-built dependencies. If None is returned then no packages are ready to be built.

source

pub fn is_empty(&self) -> bool

Returns true if there are remaining packages to be built.

source

pub fn len(&self) -> usize

Returns the number of remaining packages to be built.

source

pub fn finish(&mut self, node: &N, edge: &E) -> Vec<&N>

Indicate that something has finished.

Calling this function indicates that the node has produced edge. All remaining work items which only depend on this node/edge pair are now candidates to start their job.

Returns the nodes that are now allowed to be dequeued as a result of finishing this node.

Trait Implementations§

source§

impl<N: Debug + Hash + Eq, E: Debug + Hash + Eq, V: Debug> Debug for DependencyQueue<N, E, V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<N: Hash + Eq, E: Hash + Eq, V> Default for DependencyQueue<N, E, V>

source§

fn default() -> DependencyQueue<N, E, V>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<N, E, V> Freeze for DependencyQueue<N, E, V>

§

impl<N, E, V> RefUnwindSafe for DependencyQueue<N, E, V>

§

impl<N, E, V> Send for DependencyQueue<N, E, V>
where N: Send, V: Send, E: Send,

§

impl<N, E, V> Sync for DependencyQueue<N, E, V>
where N: Sync, V: Sync, E: Sync,

§

impl<N, E, V> Unpin for DependencyQueue<N, E, V>
where N: Unpin, V: Unpin, E: Unpin,

§

impl<N, E, V> UnwindSafe for DependencyQueue<N, E, V>
where N: UnwindSafe, V: UnwindSafe, E: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 192 bytes