#[repr(C)]pub struct hkArrayBase<T, A: SelflessAllocator = TESGlobalAlloc> { /* private fields */ }
Expand description
Represents a base class for a dynamic array of type T
.
Implementations§
Source§impl<T, A> hkArrayBase<T, A>where
A: SelflessAllocator,
impl<T, A> hkArrayBase<T, A>where
A: SelflessAllocator,
pub const fn new() -> Self
Sourcepub const fn as_ptr(&self) -> *mut T
pub const fn as_ptr(&self) -> *mut T
Returns a raw pointer to the array data.
- Equivalent C++ method:
data
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the size of the array.
Not bytes_count. Return N
of T * N
pub fn with_capacity(capacity: i32) -> Self
Sourcepub fn reserve(&mut self, new_capacity: i32)
pub fn reserve(&mut self, new_capacity: i32)
Reserves memory for the array to hold new capacity elements.
§Panics
Sourcepub fn push(&mut self, value: T)
pub fn push(&mut self, value: T)
Pushes a new element to the end of the array.
- Equivalent C++ method:
push_back
Sourcepub const fn pop(&mut self) -> Option<T>
pub const fn pop(&mut self) -> Option<T>
Removes the last element from the array and returns it, or None
if it’s empty.
Sourcepub const fn get(&self, index: usize) -> Option<&T>
pub const fn get(&self, index: usize) -> Option<&T>
Returns a reference to the element at the given index, if it exists.
Sourcepub const fn get_mut(&mut self, index: usize) -> Option<&mut T>
pub const fn get_mut(&mut self, index: usize) -> Option<&mut T>
Returns a mutable reference to the element at the given index, if it exists.
pub const fn iter(&self) -> hkArrayRefIterator<'_, T, A> ⓘ
pub const fn as_slice(&self) -> &[T]
pub const fn as_mut_slice(&mut self) -> &mut [T]
Sourcepub fn contains(&self, value: &T) -> boolwhere
T: PartialEq,
pub fn contains(&self, value: &T) -> boolwhere
T: PartialEq,
Checks if the array contains the given element.
Returns true
if the element is present in the array, and false
otherwise.
§Examples
use commonlibsse_ng::re::hkArray::hkArrayBase;
use stdx::alloc::Global;
let mut array = hkArrayBase::<i32, Global>::with_capacity(10);
array.push(1);
array.push(2);
assert!(array.contains(&1));
assert!(!array.contains(&3));
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the elements that satisfy the predicate.
This method takes a closure that accepts an element of the array and returns a boolean.
Elements for which the closure returns true
will be kept, while elements for which
it returns false
will be removed.
§Examples
use commonlibsse_ng::re::hkArray::hkArrayBase;
use stdx::alloc::Global;
let mut array = hkArrayBase::<i32, Global>::with_capacity(10);
array.push(1);
array.push(2);
array.push(3);
array.retain(|&x| x > 1);
assert_eq!(array.len(), 2);
assert!(array.contains(&2));
assert!(array.contains(&3));
Sourcepub fn drain<R>(&mut self, range: R) -> hkArrayDrain<'_, T, A> ⓘwhere
R: RangeBounds<usize>,
pub fn drain<R>(&mut self, range: R) -> hkArrayDrain<'_, T, A> ⓘwhere
R: RangeBounds<usize>,
Removes a range of elements from the array, returning them as a vector.
This method removes the elements within the specified range and returns them as
a Vec<T>
. The range must be within the bounds of the array.
§Examples
use commonlibsse_ng::re::hkArray::hkArrayBase;
use stdx::alloc::Global;
let mut array = hkArrayBase::<i32, Global>::with_capacity(10);
array.push(1);
array.push(2);
array.push(3);
array.push(4);
array.push(5);
let drained = array.drain(0..2);
assert_eq!(drained.collect::<Vec<_>>(), vec![1, 2]);
assert_eq!(array.len(), 3);
assert_eq!(array[0], 3);
assert_eq!(array[1], 4);
assert_eq!(array[2], 5);
§Panics
Panics if the range is out of bounds.
Source§impl<T, A> hkArrayBase<T, A>where
T: Clone,
A: SelflessAllocator,
impl<T, A> hkArrayBase<T, A>where
T: Clone,
A: SelflessAllocator,
Trait Implementations§
Source§impl<T: Clone, A: SelflessAllocator> Clone for hkArrayBase<T, A>
impl<T: Clone, A: SelflessAllocator> Clone for hkArrayBase<T, A>
Source§impl<T: Debug, A: SelflessAllocator> Debug for hkArrayBase<T, A>
impl<T: Debug, A: SelflessAllocator> Debug for hkArrayBase<T, A>
Source§impl<T, A> Default for hkArrayBase<T, A>where
A: SelflessAllocator,
impl<T, A> Default for hkArrayBase<T, A>where
A: SelflessAllocator,
Source§impl<T, A> Drop for hkArrayBase<T, A>where
A: SelflessAllocator,
impl<T, A> Drop for hkArrayBase<T, A>where
A: SelflessAllocator,
Source§impl<T, A> Extend<T> for hkArrayBase<T, A>where
A: SelflessAllocator,
impl<T, A> Extend<T> for hkArrayBase<T, A>where
A: SelflessAllocator,
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)