Skip to content

Commit 885b305

Browse files
: host: simplify map to set
Summary: this is a small simplification: the spawned procs' `ChannelAddr`s already live in `router: DialMailboxRouter`, so keeping a `HashMap<String, ChannelAddr>` in `procs` was redundant. switching `procs` to a `HashSet<String>` makes it clear that its only responsibility is guarding against duplicate proc names; routing remains the router's job. Differential Revision: D88300708
1 parent 58ab3c3 commit 885b305

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

hyperactor/src/host.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
//! ```
4242
4343
use std::collections::HashMap;
44+
use std::collections::HashSet;
4445
use std::fmt;
4546
use std::marker::PhantomData;
4647
use std::str::FromStr;
@@ -121,7 +122,7 @@ pub enum HostError {
121122
/// routing, as described in this module's documentation.
122123
#[derive(Debug)]
123124
pub struct Host<M> {
124-
procs: HashMap<String, ChannelAddr>,
125+
procs: HashSet<String>,
125126
frontend_addr: ChannelAddr,
126127
backend_addr: ChannelAddr,
127128
router: DialMailboxRouter,
@@ -159,7 +160,7 @@ impl<M: ProcManager> Host<M> {
159160
);
160161

161162
let host = Host {
162-
procs: HashMap::new(),
163+
procs: HashSet::new(),
163164
frontend_addr,
164165
backend_addr,
165166
router,
@@ -203,7 +204,7 @@ impl<M: ProcManager> Host<M> {
203204
name: String,
204205
config: M::Config,
205206
) -> Result<(ProcId, ActorRef<ManagerAgent<M>>), HostError> {
206-
if self.procs.contains_key(&name) {
207+
if self.procs.contains(&name) {
207208
return Err(HostError::ProcExists(name));
208209
}
209210

@@ -250,7 +251,7 @@ impl<M: ProcManager> Host<M> {
250251
})?;
251252

252253
self.router.bind(proc_id.clone().into(), addr.clone());
253-
self.procs.insert(name, addr);
254+
self.procs.insert(name);
254255

255256
Ok((proc_id, agent_ref))
256257
}
@@ -1555,7 +1556,7 @@ mod tests {
15551556

15561557
let (pid, agent) = host.spawn("ok".into(), ()).await.expect("must succeed");
15571558
assert_eq!(agent.actor_id().proc_id(), &pid);
1558-
assert!(host.procs.contains_key("ok"));
1559+
assert!(host.procs.contains("ok"));
15591560
}
15601561

15611562
#[tokio::test]

0 commit comments

Comments
 (0)