#[repr(C)]pub struct hkArray<T, A: SelflessAllocator = TESGlobalAlloc> { /* private fields */ }
Expand description
A dynamic array container C++’s hkArray
, backed by a custom allocator.
§Example
use commonlibsse_ng::re::hkArray::hkArray;
let mut array = hkArray::<i32>::new();
array.push(1);
array.push(2);
assert_eq!(array.len(), 2);
assert_eq!(array[0], 1);
Note: The default allocator (SkyrimAllocator
) only works in-game.
For examples outside of the game, use RustAllocator
.
Implementations§
Source§impl<T, A> hkArray<T, A>where
A: SelflessAllocator,
impl<T, A> hkArray<T, A>where
A: SelflessAllocator,
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new empty array.
§Example
use commonlibsse_ng::re::hkArray::hkArray;
let array: hkArray<u32> = hkArray::new();
assert!(array.is_empty());
pub fn with_capacity(capacity: i32) -> Self
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the number of elements in the array.
§Example
use commonlibsse_ng::re::hkArray::hkArray;
let array = hkArray::<u32>::new();
assert_eq!(array.len(), 0);
Sourcepub const fn capacity(&self) -> i32
pub const fn capacity(&self) -> i32
Returns the capacity of the array.
§Example
use commonlibsse_ng::re::hkArray::hkArray;
let array = hkArray::<u32>::new();
assert_eq!(array.capacity(), 0);
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Checks if the array is empty.
§Example
use commonlibsse_ng::re::hkArray::hkArray;
let array = hkArray::<u32>::new();
assert!(array.is_empty());
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.
§Example
use commonlibsse_ng::re::hkArray::hkArray;
let mut array = hkArray::<i32>::new();
array.push(1);
assert_eq!(array.pop(), Some(1));
assert_eq!(array.pop(), None);
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.
§Example
use commonlibsse_ng::re::hkArray::hkArray;
let mut array = hkArray::<i32>::new();
array.push(42);
assert_eq!(array.get(0), Some(&42));
assert_eq!(array.get(1), None);
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.
§Example
use commonlibsse_ng::re::hkArray::hkArray;
let mut array = hkArray::<i32>::new();
array.push(10);
if let Some(x) = array.get_mut(0) {
*x += 1;
}
assert_eq!(array[0], 11);
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the array, removing all elements but preserving the capacity.
§Examples
use commonlibsse_ng::re::BSTArray::{BSTArray};
let mut array = BSTArray::<i32>::with_capacity(10);
array.push(1);
array.push(2);
assert_eq!(array.len(), 2);
array.clear();
assert_eq!(array.len(), 0);
assert_eq!(array.capacity(), 10); // Capacity is preserved
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::hkArray;
let mut array = hkArray::<i32>::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::hkArray;
let mut array = hkArray::<i32>::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::hkArray;
let mut array = hkArray::<i32>::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.
Sourcepub const fn iter(&self) -> hkArrayRefIterator<'_, T, A> ⓘ
pub const fn iter(&self) -> hkArrayRefIterator<'_, T, A> ⓘ
Return iterator
Sourcepub const fn as_mut_slice(&mut self) -> &mut [T]
pub const fn as_mut_slice(&mut self) -> &mut [T]
Return mutable slice.
Source§impl<T, A> hkArray<T, A>where
T: Clone,
A: SelflessAllocator,
impl<T, A> hkArray<T, A>where
T: Clone,
A: SelflessAllocator,
Sourcepub fn resize(&mut self, count: i32, value: T)
pub fn resize(&mut self, count: i32, value: T)
Resizes the array to the specified length, filling new elements with the given value.
§Panics
Panics if count
is negative or exceeds the maximum allowed capacity.
§Example
use commonlibsse_ng::re::hkArray::hkArray;
let mut array = hkArray::<u32>::new();
array.resize(3, 7);
assert_eq!(array.len(), 3);
assert_eq!(array[0], 7);