Use U32HasherState for HashSet
This commit is contained in:
		
							parent
							
								
									a71f931d9f
								
							
						
					
					
						commit
						5d48ae1eec
					
				| @ -1,4 +1,7 @@ | ||||
| use crate::thread_transaction::ThreadTransaction; | ||||
| use crate::{ | ||||
|     thread_transaction::ThreadTransaction, | ||||
|     u32_hasher_types::{u32hashset_new, U32HasherState}, | ||||
| }; | ||||
| use std::{ | ||||
|     cmp::Ordering, | ||||
|     collections::HashSet, | ||||
| @ -17,8 +20,8 @@ pub struct AuditTransaction { | ||||
|     pub dependency_rate: f64, | ||||
|     pub inputs: Vec<u32>, | ||||
|     pub relatives_set_flag: bool, | ||||
|     pub ancestors: HashSet<u32>, | ||||
|     pub children: HashSet<u32>, | ||||
|     pub ancestors: HashSet<u32, U32HasherState>, | ||||
|     pub children: HashSet<u32, U32HasherState>, | ||||
|     pub ancestor_fee: u64, | ||||
|     pub ancestor_weight: u32, | ||||
|     pub ancestor_sigops: u32, | ||||
| @ -76,8 +79,8 @@ impl AuditTransaction { | ||||
|             dependency_rate: f64::INFINITY, | ||||
|             inputs: tx.inputs.clone(), | ||||
|             relatives_set_flag: false, | ||||
|             ancestors: HashSet::new(), | ||||
|             children: HashSet::new(), | ||||
|             ancestors: u32hashset_new(), | ||||
|             children: u32hashset_new(), | ||||
|             ancestor_fee: tx.fee, | ||||
|             ancestor_weight: tx.weight, | ||||
|             ancestor_sigops: tx.sigops, | ||||
| @ -107,7 +110,7 @@ impl AuditTransaction { | ||||
|     #[inline] | ||||
|     pub fn set_ancestors( | ||||
|         &mut self, | ||||
|         ancestors: HashSet<u32>, | ||||
|         ancestors: HashSet<u32, U32HasherState>, | ||||
|         total_fee: u64, | ||||
|         total_weight: u32, | ||||
|         total_sigops: u32, | ||||
|  | ||||
| @ -6,7 +6,9 @@ use std::{ | ||||
| 
 | ||||
| use crate::{ | ||||
|     audit_transaction::AuditTransaction, | ||||
|     u32_hasher_types::{u32hashmap_with_capacity, u32priority_queue_with_capacity, U32HasherState}, | ||||
|     u32_hasher_types::{ | ||||
|         u32hashmap_with_capacity, u32hashset_new, u32priority_queue_with_capacity, U32HasherState, | ||||
|     }, | ||||
|     GbtResult, ThreadTransactionsMap, STARTING_CAPACITY, | ||||
| }; | ||||
| 
 | ||||
| @ -217,7 +219,7 @@ pub fn gbt(mempool: &mut ThreadTransactionsMap) -> Option<GbtResult> { | ||||
| } | ||||
| 
 | ||||
| fn set_relatives(txid: u32, audit_pool: &mut AuditPool) { | ||||
|     let mut parents: HashSet<u32> = HashSet::new(); | ||||
|     let mut parents: HashSet<u32, U32HasherState> = u32hashset_new(); | ||||
|     if let Some(tx) = audit_pool.get(&txid) { | ||||
|         if tx.relatives_set_flag { | ||||
|             return; | ||||
| @ -229,7 +231,7 @@ fn set_relatives(txid: u32, audit_pool: &mut AuditPool) { | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     let mut ancestors: HashSet<u32> = HashSet::new(); | ||||
|     let mut ancestors: HashSet<u32, U32HasherState> = u32hashset_new(); | ||||
|     for parent_id in &parents { | ||||
|         set_relatives(*parent_id, audit_pool); | ||||
| 
 | ||||
| @ -268,7 +270,7 @@ fn update_descendants( | ||||
|     modified: &mut ModifiedQueue, | ||||
|     cluster_rate: f64, | ||||
| ) { | ||||
|     let mut visited: HashSet<u32> = HashSet::new(); | ||||
|     let mut visited: HashSet<u32, U32HasherState> = u32hashset_new(); | ||||
|     let mut descendant_stack: Vec<u32> = Vec::new(); | ||||
|     let root_fee: u64; | ||||
|     let root_weight: u32; | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| use priority_queue::PriorityQueue; | ||||
| use std::{ | ||||
|     collections::HashMap, | ||||
|     collections::{HashMap, HashSet}, | ||||
|     hash::{BuildHasher, Hasher}, | ||||
| }; | ||||
| 
 | ||||
| @ -16,7 +16,13 @@ pub fn u32priority_queue_with_capacity<V: Ord>( | ||||
|     PriorityQueue::with_capacity_and_hasher(capacity, U32HasherState(())) | ||||
| } | ||||
| 
 | ||||
| /// This is the only way to create a `HashSet` with the `U32HasherState`
 | ||||
| pub fn u32hashset_new() -> HashSet<u32, U32HasherState> { | ||||
|     HashSet::with_hasher(U32HasherState(())) | ||||
| } | ||||
| 
 | ||||
| /// A private unit type is contained so no one can make an instance of it.
 | ||||
| #[derive(Clone)] | ||||
| pub struct U32HasherState(()); | ||||
| 
 | ||||
| impl BuildHasher for U32HasherState { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user