From 12d3eaa53c3578ecb9dfa20e5270dc9d5db58659 Mon Sep 17 00:00:00 2001 From: Shayne Fletcher Date: Wed, 3 Dec 2025 15:46:50 -0800 Subject: [PATCH] : host: simplify map to set (#2044) Summary: this is a small simplification: the spawned procs' `ChannelAddr`s already live in `router: DialMailboxRouter`, so keeping a `HashMap` in `procs` was redundant. switching `procs` to a `HashSet` makes it clear that its only responsibility is guarding against duplicate proc names; routing remains the router's job. Differential Revision: D88300708 --- hyperactor/src/host.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hyperactor/src/host.rs b/hyperactor/src/host.rs index 5c15089fb..53ca07e4f 100644 --- a/hyperactor/src/host.rs +++ b/hyperactor/src/host.rs @@ -41,6 +41,7 @@ //! ``` use std::collections::HashMap; +use std::collections::HashSet; use std::fmt; use std::marker::PhantomData; use std::str::FromStr; @@ -121,7 +122,7 @@ pub enum HostError { /// routing, as described in this module's documentation. #[derive(Debug)] pub struct Host { - procs: HashMap, + procs: HashSet, frontend_addr: ChannelAddr, backend_addr: ChannelAddr, router: DialMailboxRouter, @@ -159,7 +160,7 @@ impl Host { ); let host = Host { - procs: HashMap::new(), + procs: HashSet::new(), frontend_addr, backend_addr, router, @@ -203,7 +204,7 @@ impl Host { name: String, config: M::Config, ) -> Result<(ProcId, ActorRef>), HostError> { - if self.procs.contains_key(&name) { + if self.procs.contains(&name) { return Err(HostError::ProcExists(name)); } @@ -250,7 +251,7 @@ impl Host { })?; self.router.bind(proc_id.clone().into(), addr.clone()); - self.procs.insert(name, addr); + self.procs.insert(name); Ok((proc_id, agent_ref)) } @@ -1190,7 +1191,6 @@ pub mod testing { use crate::Context; use crate::Handler; use crate::OncePortRef; - use crate::RemoteSpawn; /// Just a simple actor, available in both the bootstrap binary as well as /// hyperactor tests. @@ -1555,7 +1555,7 @@ mod tests { let (pid, agent) = host.spawn("ok".into(), ()).await.expect("must succeed"); assert_eq!(agent.actor_id().proc_id(), &pid); - assert!(host.procs.contains_key("ok")); + assert!(host.procs.contains("ok")); } #[tokio::test]