Compare dashmaps

This commit is contained in:
Ara Sadoyan
2025-03-12 13:11:49 +01:00
parent d559db65b5
commit df2df53f7d
2 changed files with 2 additions and 9 deletions

View File

@@ -2,7 +2,7 @@ use crate::utils::tools::*;
use std::collections::HashSet; use std::collections::HashSet;
use tokio::sync::RwLockReadGuard; use tokio::sync::RwLockReadGuard;
#[allow(dead_code)] // #[allow(dead_code)]
pub fn dm(map1: &RwLockReadGuard<UpstreamMap>, map2: &UpstreamMap) -> bool { pub fn dm(map1: &RwLockReadGuard<UpstreamMap>, map2: &UpstreamMap) -> bool {
if map1.len() != map2.len() { if map1.len() != map2.len() {
return false; // Different number of keys return false; // Different number of keys
@@ -22,7 +22,7 @@ pub fn dm(map1: &RwLockReadGuard<UpstreamMap>, map2: &UpstreamMap) -> bool {
} }
true true
} }
// #[allow(dead_code)] #[allow(dead_code)]
pub fn dam(map1: &UpstresmDashMap, map2: &UpstresmDashMap) -> bool { pub fn dam(map1: &UpstresmDashMap, map2: &UpstresmDashMap) -> bool {
// Step 1: Check if both maps have the same keys // Step 1: Check if both maps have the same keys
let keys1: HashSet<_> = map1.iter().map(|entry| entry.key().clone()).collect(); let keys1: HashSet<_> = map1.iter().map(|entry| entry.key().clone()).collect();

View File

@@ -153,7 +153,6 @@ pub fn build_upstreams(d: &str, kind: &str) -> UpstreamMap {
pub fn build_upstreams2(d: &str, kind: &str) -> UpstresmDashMap { pub fn build_upstreams2(d: &str, kind: &str) -> UpstresmDashMap {
let upstreams: UpstresmDashMap = DashMap::new(); let upstreams: UpstresmDashMap = DashMap::new();
let hopar: UpstresmDashMap = DashMap::new();
let mut contents = d.to_string(); let mut contents = d.to_string();
match kind { match kind {
"filepath" => { "filepath" => {
@@ -210,12 +209,6 @@ pub fn build_upstreams2(d: &str, kind: &str) -> UpstresmDashMap {
.or_insert_with(|| (Vec::new(), AtomicUsize::new(0))) .or_insert_with(|| (Vec::new(), AtomicUsize::new(0)))
.0 .0
.push((ip.to_string(), port, ssl, proto.to_string())); .push((ip.to_string(), port, ssl, proto.to_string()));
let entry = hopar.entry(hostname.to_string()).or_insert_with(DashMap::new);
entry
.entry(path.to_string())
.or_insert_with(|| (Vec::new(), AtomicUsize::new(0)))
.0
.push((ip.to_string(), port, ssl, proto.to_string()));
} }
// println!("\n\nResult ===> {} <===\n\n", dam(&hopar, &upstreams)); // println!("\n\nResult ===> {} <===\n\n", dam(&hopar, &upstreams));
// println!("{:?}", hopar); // println!("{:?}", hopar);