Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions program-libs/array-map/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ where
self.last_updated_index
}

pub fn get(&self, index: usize) -> Option<&(K, V)> {
pub fn get_by_index(&self, index: usize) -> Option<&(K, V)> {
self.entries.get(index)
}

pub fn get_mut(&mut self, index: usize) -> Option<&mut (K, V)> {
pub fn get_by_index_mut(&mut self, index: usize) -> Option<&mut (K, V)> {
self.entries.get_mut(index)
}

pub fn get_u8(&self, index: u8) -> Option<&(K, V)> {
self.get(index as usize)
pub fn get_by_index_u8(&self, index: u8) -> Option<&(K, V)> {
self.get_by_index(index as usize)
}

pub fn get_mut_u8(&mut self, index: u8) -> Option<&mut (K, V)> {
self.get_mut(index as usize)
pub fn get_by_index_mut_u8(&mut self, index: u8) -> Option<&mut (K, V)> {
self.get_by_index_mut(index as usize)
}

pub fn get_by_key(&self, key: &K) -> Option<&V> {
Expand Down
30 changes: 15 additions & 15 deletions program-libs/array-map/tests/array_map_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn test_insert() {
assert_eq!(idx, 0);
assert_eq!(map.len(), 1);
assert_eq!(map.last_updated_index(), Some(0));
assert_eq!(map.get(0).unwrap().1, "one");
assert_eq!(map.get_by_index(0).unwrap().1, "one");
}

#[test]
Expand Down Expand Up @@ -118,11 +118,11 @@ fn test_get_mut_direct() {

map.insert(1, 100, TestError::Custom).unwrap();

if let Some(entry) = map.get_mut(0) {
if let Some(entry) = map.get_by_index_mut(0) {
entry.1 += 50;
}

assert_eq!(map.get(0).unwrap().1, 150);
assert_eq!(map.get_by_index(0).unwrap().1, 150);
}

#[test]
Expand Down Expand Up @@ -165,13 +165,13 @@ fn test_get_u8() {
.unwrap();

// Test valid indices
assert_eq!(map.get_u8(0).unwrap().1, "one");
assert_eq!(map.get_u8(1).unwrap().1, "two");
assert_eq!(map.get_u8(2).unwrap().1, "three");
assert_eq!(map.get_by_index_u8(0).unwrap().1, "one");
assert_eq!(map.get_by_index_u8(1).unwrap().1, "two");
assert_eq!(map.get_by_index_u8(2).unwrap().1, "three");

// Test out of bounds
assert!(map.get_u8(3).is_none());
assert!(map.get_u8(255).is_none());
assert!(map.get_by_index_u8(3).is_none());
assert!(map.get_by_index_u8(255).is_none());
}

#[test]
Expand All @@ -182,17 +182,17 @@ fn test_get_mut_u8() {
map.insert(2, 200, TestError::Custom).unwrap();
map.insert(3, 300, TestError::Custom).unwrap();

// Modify via get_mut_u8
if let Some(entry) = map.get_mut_u8(1) {
// Modify via get_by_index_mut_u8
if let Some(entry) = map.get_by_index_mut_u8(1) {
entry.1 += 50;
}

// Verify modification
assert_eq!(map.get_u8(1).unwrap().1, 250);
assert_eq!(map.get_u8(0).unwrap().1, 100);
assert_eq!(map.get_u8(2).unwrap().1, 300);
assert_eq!(map.get_by_index_u8(1).unwrap().1, 250);
assert_eq!(map.get_by_index_u8(0).unwrap().1, 100);
assert_eq!(map.get_by_index_u8(2).unwrap().1, 300);

// Test out of bounds
assert!(map.get_mut_u8(3).is_none());
assert!(map.get_mut_u8(255).is_none());
assert!(map.get_by_index_mut_u8(3).is_none());
assert!(map.get_by_index_mut_u8(255).is_none());
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn sum_check_multi_mint(

// Verify all sums are zero
for i in 0..mint_sums.len() {
if let Some((_mint_index, balance)) = mint_sums.get(i) {
if let Some((_mint_index, balance)) = mint_sums.get_by_index(i) {
if *balance != 0 {
return Err(ErrorCode::SumCheckFailed);
}
Expand All @@ -132,7 +132,7 @@ pub fn validate_mint_uniqueness(
let mut seen_pubkeys: ArrayMap<[u8; 32], u8, 5> = ArrayMap::new();

for i in 0..mint_map.len() {
if let Some((mint_index, _balance)) = mint_map.get(i) {
if let Some((mint_index, _balance)) = mint_map.get_by_index(i) {
// Get the mint account pubkey from packed accounts
let mint_account = packed_accounts
.get(*mint_index as usize, "mint")
Expand Down