Skip to content

Feature Request: key_watermark() API #113

@rib

Description

@rib

I'm currently using Slabs as part of a Mesh data structure for vertices, edges, loops + faces (based on the design of Blender's BMesh API) and as part of that I'm looking to have secondary vectors of data that are indexed with keys from the slab.

I'm looking to store ancillary attributes (these may be per-vertex, or per-edge etc) within Vec vectors where I'd really like to avoid any memory overhead per value (meshes can be pretty huge), and the corresponding Slab (e.g. vertex slab for a per-vertex attribute) would be the authority on what keys are valid for indexing into those vectors.

To make this work I'd like to be able to maintain the attribute vector lengths according to the length of the Slab entries vector as a simple way of ensuring that all possible slab keys will be valid for indexing in to these attribute vectors.

To not be confused with querying the length of the slab as the number of current values, 'key_watermark' seems like it could get across what it is that I'd like to query here; like this...

    /// Return the current length of entry storage
    ///
    /// This is always larger than all currently valid keys and less than or
    /// equal to the current capacity.
    ///
    /// This may be useful for maintaining secondary data within vectors that
    /// use the same keys as a primary Slab.
    ///
    /// # Examples
    ///
    /// ```
    /// # use slab::*;
    /// let mut slab = Slab::with_capacity(10);
    ///
    /// for i in 0..4 {
    ///     slab.insert(i);
    /// }
    ///
    /// slab.remove(0);
    /// slab.remove(3);
    /// assert_eq!(slab.key_watermark(), 4);
    /// ```
    pub fn key_watermark(&self) -> usize {
        self.entries.len()
    }

I can look at creating a pull request if something like this sounds reasonable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions