Skip to content

Commit 828cfbf

Browse files
committed
use hashmap instead of vector to store config table
1 parent 2540453 commit 828cfbf

4 files changed

Lines changed: 11 additions & 12 deletions

File tree

examples/examples/receiver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ fn main() {
1212

1313
// Subscribe to "data1"
1414
let _sub_data1 = session
15-
.declare_subscriber("UserDefined/test/data1")
15+
.declare_subscriber("system/emergency/hazard_status")
1616
.callback(|sample| {
17-
handle_sample("UserDefined/test/data1", sample.payload().to_bytes());
17+
handle_sample("system/emergency/hazard_status", sample.payload().to_bytes());
1818
})
1919
.background()
2020
.wait()

examples/examples/sender.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn main() {
1515

1616
// Publisher 1: user-specified priority
1717
let pub1 = session
18-
.declare_publisher("UserDefined/test/data1")
18+
.declare_publisher("system/emergency/hazard_status")
1919
.congestion_control(CongestionControl::Block)
2020
.priority(user_priority)
2121
.express(express)

zenoh/src/api/session.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,15 +1234,18 @@ pub struct TopicInfo {
12341234
pub bandwidth: String,
12351235
}
12361236

1237-
pub static TOPIC_TABLE: OnceCell<Vec<TopicInfo>> = OnceCell::new();
1237+
pub static TOPIC_TABLE: OnceCell<HashMap<String, TopicInfo>> = OnceCell::new();
12381238

1239-
fn read_topic_table(path: &str) -> Vec<TopicInfo> {
1239+
fn read_topic_table(path: &str) -> HashMap<String, TopicInfo> {
12401240
let mut rdr = csv::ReaderBuilder::new()
12411241
.has_headers(false)
12421242
.from_path(path)
12431243
.expect("Cannot open CSV");
12441244
rdr.deserialize()
1245-
.map(|res| res.expect("CSV parse error"))
1245+
.map(|res| {
1246+
let info: TopicInfo = res.expect("CSV parse error");
1247+
(info.topic.clone(), info)
1248+
})
12461249
.collect()
12471250
}
12481251

zenoh/src/net/routing/dispatcher/pubsub.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,9 @@ pub fn route_data(
304304
let flow_name = format!("{}{}", prefix.expr(), wire_expr.suffix.as_ref());
305305

306306
if let Some(table) = TOPIC_TABLE.get() {
307-
for info in table {
308-
if info.topic == flow_name {
309-
println!("Match: {:?}", info);
310-
}
307+
if let Some(info) = table.get(&flow_name) {
308+
tracing::debug!("Match: {:?}", info);
311309
}
312-
} else {
313-
println!("TOPIC_TABLE not initialized");
314310
}
315311

316312
tracing::trace!(

0 commit comments

Comments
 (0)