[−][src]Struct nakamoto_test::BITCOIN_HEADERS
Methods from Deref<Target = NonEmpty<BlockHeader>>
pub const fn is_empty(&self) -> bool
[src]
Always returns false.
pub const fn first(&self) -> &T
[src]
Get the first element. Never fails.
pub fn tail(&self) -> &[T]ⓘ
[src]
Get the possibly-empty tail of the list.
use nonempty::NonEmpty; let non_empty = NonEmpty::new(42); assert_eq!(non_empty.tail(), &[]); let non_empty = NonEmpty::from((1, vec![4, 2, 3])); assert_eq!(non_empty.tail(), &[4, 2, 3]);
pub fn len(&self) -> usize
[src]
Get the length of the list.
pub fn last(&self) -> &T
[src]
Get the last element. Never fails.
pub fn contains(&self, x: &T) -> bool where
T: PartialEq<T>,
[src]
T: PartialEq<T>,
Check whether an element is contained in the list.
use nonempty::NonEmpty; let mut l = NonEmpty::from((42, vec![36, 58])); assert!(l.contains(&42)); assert!(!l.contains(&101));
pub fn get(&self, index: usize) -> Option<&T>
[src]
Get an element by index.
pub fn iter(&'a self) -> impl Iterator<Item = &'a T> + 'a
[src]
use nonempty::NonEmpty; let mut l = NonEmpty::from((42, vec![36, 58])); let mut l_iter = l.iter(); assert_eq!(l_iter.next(), Some(&42)); assert_eq!(l_iter.next(), Some(&36)); assert_eq!(l_iter.next(), Some(&58)); assert_eq!(l_iter.next(), None);
pub fn split_first(&self) -> (&T, &[T])
[src]
Deconstruct a NonEmpty
into its head and tail.
This operation never fails since we are guranteed
to have a head element.
Example Use
use nonempty::NonEmpty; let mut non_empty = NonEmpty::from((1, vec![2, 3, 4, 5])); // Guaranteed to have the head and we also get the tail. assert_eq!(non_empty.split_first(), (&1, &[2, 3, 4, 5][..])); let non_empty = NonEmpty::new(1); // Guaranteed to have the head element. assert_eq!(non_empty.split_first(), (&1, &[][..]));
pub fn split(&self) -> (&T, &[T], &T)
[src]
Deconstruct a NonEmpty
into its first, last, and
middle elements, in that order.
If there is only one element then first == last.
Example Use
use nonempty::NonEmpty; let mut non_empty = NonEmpty::from((1, vec![2, 3, 4, 5])); // Guaranteed to have the last element and the elements // preceding it. assert_eq!(non_empty.split(), (&1, &[2, 3, 4][..], &5)); let non_empty = NonEmpty::new(1); // Guaranteed to have the last element. assert_eq!(non_empty.split(), (&1, &[][..], &1));
pub fn binary_search(&self, x: &T) -> Result<usize, usize> where
T: Ord,
[src]
T: Ord,
Binary searches this sorted non-empty vector for a given element.
If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned.
If the value is not found then Result::Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.
Examples
use nonempty::NonEmpty; let non_empty = NonEmpty::from((0, vec![1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55])); assert_eq!(non_empty.binary_search(&0), Ok(0)); assert_eq!(non_empty.binary_search(&13), Ok(9)); assert_eq!(non_empty.binary_search(&4), Err(7)); assert_eq!(non_empty.binary_search(&100), Err(13)); let r = non_empty.binary_search(&1); assert!(match r { Ok(1..=4) => true, _ => false, });
If you want to insert an item to a sorted non-empty vector, while maintaining sort order:
use nonempty::NonEmpty; let mut non_empty = NonEmpty::from((0, vec![1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55])); let num = 42; let idx = non_empty.binary_search(&num).unwrap_or_else(|x| x); non_empty.insert(idx, num); assert_eq!(non_empty, NonEmpty::from((0, vec![1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55])));
pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize> where
F: FnMut(&'a T) -> Ordering,
[src]
F: FnMut(&'a T) -> Ordering,
Binary searches this sorted non-empty with a comparator function.
The comparator function should implement an order consistent with the sort order of the underlying slice, returning an order code that indicates whether its argument is Less, Equal or Greater the desired target.
If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned. If the value is not found then Result::Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.
Examples
Looks up a series of four elements. The first is found, with a uniquely determined position; the second and third are not found; the fourth could match any position in [1,4].
use nonempty::NonEmpty; let non_empty = NonEmpty::from((0, vec![1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55])); let seek = 0; assert_eq!(non_empty.binary_search_by(|probe| probe.cmp(&seek)), Ok(0)); let seek = 13; assert_eq!(non_empty.binary_search_by(|probe| probe.cmp(&seek)), Ok(9)); let seek = 4; assert_eq!(non_empty.binary_search_by(|probe| probe.cmp(&seek)), Err(7)); let seek = 100; assert_eq!(non_empty.binary_search_by(|probe| probe.cmp(&seek)), Err(13)); let seek = 1; let r = non_empty.binary_search_by(|probe| probe.cmp(&seek)); assert!(match r { Ok(1..=4) => true, _ => false, });
pub fn binary_search_by_key<'a, B, F>(
&'a self,
b: &B,
f: F
) -> Result<usize, usize> where
F: FnMut(&'a T) -> B,
B: Ord,
[src]
&'a self,
b: &B,
f: F
) -> Result<usize, usize> where
F: FnMut(&'a T) -> B,
B: Ord,
Binary searches this sorted non-empty vector with a key extraction function.
Assumes that the vector is sorted by the key.
If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned. If the value is not found then Result::Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.
Examples
Looks up a series of four elements in a non-empty vector of pairs sorted by their second elements. The first is found, with a uniquely determined position; the second and third are not found; the fourth could match any position in [1, 4].
use nonempty::NonEmpty; let non_empty = NonEmpty::from(( (0, 0), vec![(2, 1), (4, 1), (5, 1), (3, 1), (1, 2), (2, 3), (4, 5), (5, 8), (3, 13), (1, 21), (2, 34), (4, 55)] )); assert_eq!(non_empty.binary_search_by_key(&0, |&(a,b)| b), Ok(0)); assert_eq!(non_empty.binary_search_by_key(&13, |&(a,b)| b), Ok(9)); assert_eq!(non_empty.binary_search_by_key(&4, |&(a,b)| b), Err(7)); assert_eq!(non_empty.binary_search_by_key(&100, |&(a,b)| b), Err(13)); let r = non_empty.binary_search_by_key(&1, |&(a,b)| b); assert!(match r { Ok(1..=4) => true, _ => false, });
pub fn maximum(&self) -> &T where
T: Ord,
[src]
T: Ord,
Returns the maximum element in the non-empty vector.
This will return the first item in the vector if the tail is empty.
Examples
use nonempty::NonEmpty; let non_empty = NonEmpty::new(42); assert_eq!(non_empty.maximum(), &42); let non_empty = NonEmpty::from((1, vec![-34, 42, 76, 4, 5])); assert_eq!(non_empty.maximum(), &76);
pub fn minimum(&self) -> &T where
T: Ord,
[src]
T: Ord,
Returns the minimum element in the non-empty vector.
This will return the first item in the vector if the tail is empty.
Examples
use nonempty::NonEmpty; let non_empty = NonEmpty::new(42); assert_eq!(non_empty.minimum(), &42); let non_empty = NonEmpty::from((1, vec![-34, 42, 76, 4, 5])); assert_eq!(non_empty.minimum(), &-34);
pub fn maximum_by<F>(&self, compare: F) -> &T where
F: Fn(&T, &T) -> Ordering,
[src]
F: Fn(&T, &T) -> Ordering,
Returns the element that gives the maximum value with respect to the specified comparison function.
This will return the first item in the vector if the tail is empty.
Examples
use nonempty::NonEmpty; let non_empty = NonEmpty::new((0, 42)); assert_eq!(non_empty.maximum_by(|(k, _), (l, _)| k.cmp(l)), &(0, 42)); let non_empty = NonEmpty::from(((2, 1), vec![(2, -34), (4, 42), (0, 76), (1, 4), (3, 5)])); assert_eq!(non_empty.maximum_by(|(k, _), (l, _)| k.cmp(l)), &(4, 42));
pub fn minimum_by<F>(&self, compare: F) -> &T where
F: Fn(&T, &T) -> Ordering,
[src]
F: Fn(&T, &T) -> Ordering,
Returns the element that gives the minimum value with respect to the specified comparison function.
This will return the first item in the vector if the tail is empty.
use nonempty::NonEmpty; let non_empty = NonEmpty::new((0, 42)); assert_eq!(non_empty.minimum_by(|(k, _), (l, _)| k.cmp(l)), &(0, 42)); let non_empty = NonEmpty::from(((2, 1), vec![(2, -34), (4, 42), (0, 76), (1, 4), (3, 5)])); assert_eq!(non_empty.minimum_by(|(k, _), (l, _)| k.cmp(l)), &(0, 76));
pub fn maximum_by_key<U, F>(&self, f: F) -> &T where
F: Fn(&T) -> &U,
U: Ord,
[src]
F: Fn(&T) -> &U,
U: Ord,
Returns the element that gives the maximum value with respect to the specified function.
This will return the first item in the vector if the tail is empty.
Examples
use nonempty::NonEmpty; let non_empty = NonEmpty::new((0, 42)); assert_eq!(non_empty.maximum_by_key(|(k, _)| k), &(0, 42)); let non_empty = NonEmpty::from(((2, 1), vec![(2, -34), (4, 42), (0, 76), (1, 4), (3, 5)])); assert_eq!(non_empty.maximum_by_key(|(k, _)| k), &(4, 42));
pub fn minimum_by_key<U, F>(&self, f: F) -> &T where
F: Fn(&T) -> &U,
U: Ord,
[src]
F: Fn(&T) -> &U,
U: Ord,
Returns the element that gives the minimum value with respect to the specified function.
This will return the first item in the vector if the tail is empty.
Examples
use nonempty::NonEmpty; let non_empty = NonEmpty::new((0, 42)); assert_eq!(non_empty.minimum_by_key(|(k, _)| k), &(0, 42)); let non_empty = NonEmpty::from(((2, 1), vec![(2, -34), (4, 42), (0, 76), (1, 4), (3, 5)])); assert_eq!(non_empty.minimum_by_key(|(k, _)| k), &(0, 76));
Trait Implementations
impl Deref for BITCOIN_HEADERS
[src]
type Target = NonEmpty<BlockHeader>
The resulting type after dereferencing.
pub fn deref(&self) -> &NonEmpty<BlockHeader>
[src]
impl LazyStatic for BITCOIN_HEADERS
[src]
pub fn initialize(lazy: &Self)
[src]
Auto Trait Implementations
impl RefUnwindSafe for BITCOIN_HEADERS
[src]
impl Send for BITCOIN_HEADERS
[src]
impl Sync for BITCOIN_HEADERS
[src]
impl Unpin for BITCOIN_HEADERS
[src]
impl UnwindSafe for BITCOIN_HEADERS
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,