pub struct Doubling<V> { /* private fields */ }Expand description
ダブリング
§Examples
use doubling::{Doubling, Transition, Value};
#[derive(Debug, PartialEq)]
struct Sum(i64);
impl Value for Sum {
fn op(&self, other: &Self) -> Self {
Sum(self.0 + other.0)
}
}
struct E {
to: usize,
value: i64,
}
// 0, 1, 2, 0, 1, 2, ...
let n = 3;
let to = vec![
E { to: 1, value: 1 },
E { to: 2, value: 10 },
E { to: 0, value: 100 },
];
let doubling = Doubling::new(n, 100, |i| {
let e = &to[i];
Transition::new(e.to, Sum(e.value))
});
assert_eq!(
doubling.fold(0, 4, Sum(0), |acc, t| Sum(acc.0 + t.value.0)),
// 0 -> 1 -> 2 -> 0 -> 1
Sum(1 + 10 + 100 + 1)
);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<V> Freeze for Doubling<V>
impl<V> RefUnwindSafe for Doubling<V>where
V: RefUnwindSafe,
impl<V> Send for Doubling<V>where
V: Send,
impl<V> Sync for Doubling<V>where
V: Sync,
impl<V> Unpin for Doubling<V>where
V: Unpin,
impl<V> UnsafeUnpin for Doubling<V>
impl<V> UnwindSafe for Doubling<V>where
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more