Struct Portfolio

Source
pub struct Portfolio<T: Eq + Hash>(/* private fields */);
Expand description

A sparse collection of weighted elements where zero-valued entries are excluded. Used for efficiently representing portfolios, groups, and other weighted collections.

Implementations§

Source§

impl<T: Eq + Hash> Portfolio<T>

Source

pub fn into_iter(self) -> impl Iterator<Item = (T, f64)>

A consuming iterator for the key-value pairs Returns only non-zero weighted pairs.

Source

pub fn iter(&self) -> impl Iterator<Item = (&T, &f64)>

A by-reference iterator for the key-value pairs Returns only non-zero weighted pairs.

Source

pub fn keys(&self) -> impl Iterator<Item = &T>

Iterate over the keys with non-zero values

Source

pub fn retain<F: Fn(&T, &f64) -> bool>(&mut self, f: F)

Remove keys based on some criteria This allows filtering the sparse vector with a custom function.

Source

pub fn len(&self) -> usize

The number of key-value pairs. (After a call to .simplify(), equivalent to an L0 norm)

Source

pub fn get<Q: ?Sized + Hash + Equivalent<T>>(&self, key: &Q) -> Option<f64>

Get the value associated to the key, or None if zero or missing

Source

pub fn validate(&self) -> bool

Is this an economically valid portfolio? Checks that all weights are finite values.

Trait Implementations§

Source§

impl<T: Debug + Eq + Hash> Debug for Portfolio<T>

Source§

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

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

impl<T: Eq + Hash> Default for Portfolio<T>

Source§

fn default() -> Self

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

impl<T: Eq + Hash + Ord> FromIterator<(T, f64)> for Portfolio<T>

Source§

fn from_iter<U: IntoIterator<Item = (T, f64)>>(iter: U) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Portfolio<T>

§

impl<T> RefUnwindSafe for Portfolio<T>
where T: RefUnwindSafe,

§

impl<T> Send for Portfolio<T>
where T: Send,

§

impl<T> Sync for Portfolio<T>
where T: Sync,

§

impl<T> Unpin for Portfolio<T>
where T: Unpin,

§

impl<T> UnwindSafe for Portfolio<T>
where T: 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.

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.