Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/naga/src/arena/   (Firefox Browser Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 2 kB image not shown  

Quelle  handlevec.rs

  Sprache: Rust
 

//! The [`HandleVec`] type and associated definitions.

use super::handle::Handle;

use std::marker::PhantomData;
use std::ops;

/// A [`Vec`] indexed by [`Handle`]s.
///
/// A `HandleVec<T, U>` is a [`Vec<U>`] indexed by values of type `Handle<T>`,
/// rather than `usize`.
///
/// Rather than a `push` method, `HandleVec` has an [`insert`] method, analogous
/// to [`HashMap::insert`], that requires you to provide the handle at which the
/// new value should appear. However, since `HandleVec` only supports insertion
/// at the end, the given handle's index must be equal to the the `HandleVec`'s
/// current length; otherwise, the insertion will panic.
///
/// [`insert`]: HandleVec::insert
/// [`HashMap::insert`]: std::collections::HashMap::insert
#[derive(Debug)]
pub(cratestruct HandleVec<T, U> {
    inner: Vec<U>,
    as_keys: PhantomData<T>,
}

impl<T, U> Default for HandleVec<T, U> {
    fn default() -> Self {
        Self {
            inner: vec![],
            as_keys: PhantomData,
        }
    }
}

#[allow(dead_code)]
impl<T, U> HandleVec<T, U> {
    pub(crateconst fn new() -> Self {
        Self {
            inner: vec![],
            as_keys: PhantomData,
        }
    }

    pub(cratefn with_capacity(capacity: usize) -> Self {
        Self {
            inner: Vec::with_capacity(capacity),
            as_keys: PhantomData,
        }
    }

    pub(cratefn len(&self) -> usize {
        self.inner.len()
    }

    /// Insert a mapping from `handle` to `value`.
    ///
    /// Unlike a [`HashMap`], a `HandleVec` can only have new entries inserted at
    /// the end, like [`Vec::push`]. So the index of `handle` must equal
    /// [`self.len()`].
    ///
    /// [`HashMap`]: std::collections::HashMap
    /// [`self.len()`]: HandleVec::len
    pub(cratefn insert(&mut self, handle: Handle<T>, value: U) {
        assert_eq!(handle.index(), self.inner.len());
        self.inner.push(value);
    }

    pub(cratefn get(&self, handle: Handle<T>) -> Option<&U> {
        self.inner.get(handle.index())
    }

    pub(cratefn clear(&mut self) {
        self.inner.clear()
    }

    pub(cratefn resize(&mut self, len: usize, fill: U)
    where
        U: Clone,
    {
        self.inner.resize(len, fill);
    }

    pub(cratefn iter(&self) -> impl Iterator<Item = &U> {
        self.inner.iter()
    }

    pub(cratefn iter_mut(&mut self) -> impl Iterator<Item = &='color:red'>mut U> {
        self.inner.iter_mut()
    }
}

impl<T, U> ops::Index<Handle<T>> for HandleVec<T, U> {
    type Output = U;

    fn index(&self, handle: Handle<T>) -> &Self::Output {
        &self.inner[handle.index()]
    }
}

impl<T, U> ops::IndexMut<Handle<T>> for HandleVec<T, U> {
    fn index_mut(&mut self, handle: Handle<T>) -> &mut Self::Output {
        &mut self.inner[handle.index()]
    }
}

Messung V0.5 in Prozent
C=77 H=97 G=87

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet am  2026-06-18) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.