Skip to content

Commit

Permalink
Replace all instances of HashMap with BTreeMap
Browse files Browse the repository at this point in the history
  • Loading branch information
10gic committed Sep 2, 2024
1 parent 9f0e5cb commit 0646608
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions rust/frameworks/tw_ton_sdk/src/boc/boc_to_raw_boc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IndexedCell>;
type CellsByHash = BTreeMap<H256, IndexedCellRef>;

#[derive(Debug, Clone)]
struct IndexedCell {
Expand Down Expand Up @@ -48,7 +48,7 @@ pub(crate) fn convert_to_raw_boc(boc: &BagOfCells) -> CellResult<RawBagOfCells>
})
}

fn build_and_verify_index(roots: &[CellArc]) -> HashMap<H256, IndexedCellRef> {
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;

Expand Down Expand Up @@ -101,13 +101,10 @@ fn build_and_verify_index(roots: &[CellArc]) -> HashMap<H256, IndexedCellRef> {
}
}

cells_by_hash.into_iter().collect()
cells_by_hash
}

fn root_indices(
roots: &[CellArc],
cells_dict: &HashMap<H256, IndexedCellRef>,
) -> CellResult<Vec<usize>> {
fn root_indices(roots: &[CellArc], cells_dict: &CellsByHash) -> CellResult<Vec<usize>> {
roots
.iter()
.map(|root_cell| root_cell.cell_hash())
Expand All @@ -127,17 +124,14 @@ fn root_indices(

fn raw_cells_from_cells(
cells: impl Iterator<Item = CellArc>,
cells_by_hash: &HashMap<H256, IndexedCellRef>,
cells_by_hash: &CellsByHash,
) -> CellResult<Vec<RawCell>> {
cells
.map(|cell| raw_cell_from_cell(&cell, cells_by_hash))
.collect()
}

fn raw_cell_from_cell(
cell: &Cell,
cells_by_hash: &HashMap<H256, IndexedCellRef>,
) -> CellResult<RawCell> {
fn raw_cell_from_cell(cell: &Cell, cells_by_hash: &CellsByHash) -> CellResult<RawCell> {
raw_cell_reference_indices(cell, cells_by_hash).map(|reference_indices| {
RawCell::new(
cell.data().to_vec(),
Expand All @@ -149,10 +143,7 @@ fn raw_cell_from_cell(
})
}

fn raw_cell_reference_indices(
cell: &Cell,
cells_by_hash: &HashMap<H256, IndexedCellRef>,
) -> CellResult<Vec<usize>> {
fn raw_cell_reference_indices(cell: &Cell, cells_by_hash: &CellsByHash) -> CellResult<Vec<usize>> {
cell.references()
.iter()
.map(|cell| {
Expand Down

0 comments on commit 0646608

Please sign in to comment.