From 0646608a58bc7a307e8ff1aeca58b68a779abbf1 Mon Sep 17 00:00:00 2001 From: 10gic <2391796+10gic@users.noreply.github.com> Date: Mon, 2 Sep 2024 18:37:15 +0800 Subject: [PATCH] Replace all instances of HashMap with BTreeMap --- .../tw_ton_sdk/src/boc/boc_to_raw_boc.rs | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/rust/frameworks/tw_ton_sdk/src/boc/boc_to_raw_boc.rs b/rust/frameworks/tw_ton_sdk/src/boc/boc_to_raw_boc.rs index 04f634d8014..c3f4e3d60e0 100644 --- a/rust/frameworks/tw_ton_sdk/src/boc/boc_to_raw_boc.rs +++ b/rust/frameworks/tw_ton_sdk/src/boc/boc_to_raw_boc.rs @@ -10,12 +10,12 @@ use crate::cell::{Cell, CellArc}; use crate::error::{CellErrorType, CellResult}; use std::cell::RefCell; use std::collections::BTreeMap; -use std::collections::HashMap; use std::sync::Arc; use tw_coin_entry::error::prelude::{OrTWError, ResultContext}; use tw_hash::H256; type IndexedCellRef = RefCell; +type CellsByHash = BTreeMap; #[derive(Debug, Clone)] struct IndexedCell { @@ -48,7 +48,7 @@ pub(crate) fn convert_to_raw_boc(boc: &BagOfCells) -> CellResult }) } -fn build_and_verify_index(roots: &[CellArc]) -> HashMap { +fn build_and_verify_index(roots: &[CellArc]) -> CellsByHash { let mut current_cells: Vec<_> = roots.iter().map(Arc::clone).collect(); let mut new_hash_index = 0; @@ -101,13 +101,10 @@ fn build_and_verify_index(roots: &[CellArc]) -> HashMap { } } - cells_by_hash.into_iter().collect() + cells_by_hash } -fn root_indices( - roots: &[CellArc], - cells_dict: &HashMap, -) -> CellResult> { +fn root_indices(roots: &[CellArc], cells_dict: &CellsByHash) -> CellResult> { roots .iter() .map(|root_cell| root_cell.cell_hash()) @@ -127,17 +124,14 @@ fn root_indices( fn raw_cells_from_cells( cells: impl Iterator, - cells_by_hash: &HashMap, + cells_by_hash: &CellsByHash, ) -> CellResult> { cells .map(|cell| raw_cell_from_cell(&cell, cells_by_hash)) .collect() } -fn raw_cell_from_cell( - cell: &Cell, - cells_by_hash: &HashMap, -) -> CellResult { +fn raw_cell_from_cell(cell: &Cell, cells_by_hash: &CellsByHash) -> CellResult { raw_cell_reference_indices(cell, cells_by_hash).map(|reference_indices| { RawCell::new( cell.data().to_vec(), @@ -149,10 +143,7 @@ fn raw_cell_from_cell( }) } -fn raw_cell_reference_indices( - cell: &Cell, - cells_by_hash: &HashMap, -) -> CellResult> { +fn raw_cell_reference_indices(cell: &Cell, cells_by_hash: &CellsByHash) -> CellResult> { cell.references() .iter() .map(|cell| {