pub struct DedupVec<T, const ON: bool = true>where
Self: AsDedupVec,{ /* private fields */ }Expand description
Deduplicated vector.
-
If ON is true, then the vector keeps sorted and deduplicated status. It means the vector will conduct sorting and binary search whenever you insert or remove items into or from the vector. In this case,
Vecis used as data container. -
If ON is false, on the other hand, the vector acts differently according to build mode.
- debug mode : Vector will panic when duplication detected.
SetValueListis used as data container in this case. The container keeps insertion order. - release mode : Vector does nothing to keep the deduplicated status.
Clients must keep the status on their code. In this case,
Vecis used as data container.
- debug mode : Vector will panic when duplication detected.
§How to determine ON
If sorting is not a burden to you, and you’re going to insert/remove items
in any orders, then set ON to true. The vector will keep the deduplicated
status always.
If you can guarantee the deduplicated status on your own, then set ON to
false. The vector will warn you if the guarantee has been broken in debug
mode. In release mode, there won’t be any additional operations to avoid
performance penalty.
Trait Implementations§
Source§impl<T> AsDedupVec for DedupVec<T, true>where
T: Ord,
impl<T> AsDedupVec for DedupVec<T, true>where
T: Ord,
Source§fn new() -> Self
fn new() -> Self
Creates a new empty vector.
The vector will automatically sort and deduplicate items for you due to
ON = true.
§Examples
use my_ecs::ds::{AsDedupVec, DedupVec};
let mut v = DedupVec::<i32, true>::new();Source§fn len(&self) -> usize
fn len(&self) -> usize
Returns number of items.
§Examples
use my_ecs::ds::{AsDedupVec, DedupVec};
let mut v = DedupVec::<_, true>::new();
v.push(0);
assert_eq!(v.len(), 1);Source§fn contains(&self, value: &Self::Item) -> bool
fn contains(&self, value: &Self::Item) -> bool
Returns true if the vector contains the given value.
§Examples
use my_ecs::ds::{AsDedupVec, DedupVec};
let mut v = DedupVec::<_, true>::new();
v.push(0);
assert!(v.contains(&0));Source§fn push(&mut self, value: Self::Item)
fn push(&mut self, value: Self::Item)
Appends the given value to the end of the vector.
The vector will automatically sort and deduplicate items for you due to
ON = true.
§Examples
use my_ecs::ds::{AsDedupVec, DedupVec};
let mut v = DedupVec::<_, true>::new();
v.push(0);
v.push(0);
v.push(2);
v.push(1);
let dedup = v.iter().cloned().collect::<Vec<_>>();
assert_eq!(dedup, [0, 1, 2]);Source§fn remove(&mut self, value: &Self::Item) -> Option<Self::Item>
fn remove(&mut self, value: &Self::Item) -> Option<Self::Item>
Removes an item that is equal to the given value from the vector.
The vector will automatically sort and deduplicate items for you due to
ON = true.
§Examples
use my_ecs::ds::{AsDedupVec, DedupVec};
let mut v = DedupVec::<_, true>::new();
v.push(0);
v.push(2);
v.push(1);
v.remove(&1);
let dedup = v.iter().cloned().collect::<Vec<_>>();
assert_eq!(dedup, [0, 2]);Source§fn extend(&mut self, iter: impl IntoIterator<Item = Self::Item>)
fn extend(&mut self, iter: impl IntoIterator<Item = Self::Item>)
Extends the vector with the given iterator.
The vector will automatically sort and deduplicate items for you due to
ON = true.
§Examples
use my_ecs::ds::{AsDedupVec, DedupVec};
let mut v = DedupVec::<_, true>::new();
v.extend([0, 2, 1]);
let dedup = v.iter().cloned().collect::<Vec<_>>();
assert_eq!(dedup, [0, 1, 2]);Source§impl<T> AsDedupVec for DedupVec<T, false>
impl<T> AsDedupVec for DedupVec<T, false>
Source§fn new() -> Self
fn new() -> Self
Creates a new empty vector.
The vector won’t do anything to keep the deduplicated status, but it
panics when you insert duplicate item into the vector in debug mode due
to ON = false.
§Examples
use my_ecs::ds::{AsDedupVec, DedupVec};
let mut v = DedupVec::<i32, false>::new();Source§fn len(&self) -> usize
fn len(&self) -> usize
Returns number of items.
§Examples
use my_ecs::ds::{AsDedupVec, DedupVec};
let mut v = DedupVec::<_, false>::new();
v.push(0);
assert_eq!(v.len(), 1);Source§fn contains(&self, value: &Self::Item) -> bool
fn contains(&self, value: &Self::Item) -> bool
Returns true if the vector contains the given value.
§Examples
use my_ecs::ds::{AsDedupVec, DedupVec};
let mut v = DedupVec::<_, false>::new();
v.push(0);
assert!(v.contains(&0));Source§fn push(&mut self, value: Self::Item)
fn push(&mut self, value: Self::Item)
Appends the given value to the end of the vector.
The vector won’t do anything to keep the deduplicated status, but it
panics when you insert duplicate item into the vector in debug mode due
to ON = false.
§Examples
use my_ecs::ds::{AsDedupVec, DedupVec};
let mut v = DedupVec::<_, false>::new();
v.push(0);
v.push(2);
v.push(1);
let dedup = v.iter().cloned().collect::<Vec<_>>();
assert_eq!(dedup, [0, 2, 1]);Source§fn remove(&mut self, value: &Self::Item) -> Option<Self::Item>
fn remove(&mut self, value: &Self::Item) -> Option<Self::Item>
Removes an item that is equal to the given value from the vector.
The vector won’t do anything to keep the deduplicated status, but it
panics when you insert duplicate item into the vector in debug mode due
to ON = false.
§Examples
use my_ecs::ds::{AsDedupVec, DedupVec};
let mut v = DedupVec::<_, false>::new();
v.push(0);
v.push(1);
v.push(2);
v.remove(&1);
let dedup = v.iter().cloned().collect::<Vec<_>>();
assert_eq!(dedup, [0, 2]);Source§fn extend(&mut self, iter: impl IntoIterator<Item = Self::Item>)
fn extend(&mut self, iter: impl IntoIterator<Item = Self::Item>)
Extends the vector with the given iterator.
The vector won’t do anything to keep the deduplicated status, but it
panics when you insert duplicate item into the vector in debug mode due
to ON = false.
§Examples
use my_ecs::ds::{AsDedupVec, DedupVec};
let mut v = DedupVec::<_, false>::new();
v.extend([0, 2, 1]);
let dedup = v.iter().cloned().collect::<Vec<_>>();
assert_eq!(dedup, [0, 2, 1]);Source§fn iter(&self) -> impl Iterator<Item = &Self::Item>
fn iter(&self) -> impl Iterator<Item = &Self::Item>
Returns an iterator visiting all items in the vector.
§Examples
use my_ecs::ds::{AsDedupVec, DedupVec};
let mut v = DedupVec::<_, false>::new();
v.push(0);
v.push(1);
for x in v.iter() {
println!("{x}");
}Source§type Container = SetValueList<T, RandomState>
type Container = SetValueList<T, RandomState>
Auto Trait Implementations§
impl<T, const ON: bool = true> !Freeze for DedupVec<T, ON>
impl<T, const ON: bool = true> !RefUnwindSafe for DedupVec<T, ON>
impl<T, const ON: bool = true> !Send for DedupVec<T, ON>
impl<T, const ON: bool = true> !Sync for DedupVec<T, ON>
impl<T, const ON: bool = true> !Unpin for DedupVec<T, ON>
impl<T, const ON: bool = true> !UnwindSafe for DedupVec<T, ON>
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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