You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Q16. Which example correctly uses std::collections::HashMap's Entry API to populate counts?
use std::collections::HashMap;fnmain(){letmut counts = HashMap::new();let text = "LinkedIn Learning";for c in text.chars(){// Complete this block}println!("{:?}", counts);}
[ ]
for c in text.chars(){ifletSome(count) = &mut counts.get(&c){
counts.insert(c,*count + 1);}else{
counts.insert(c,1);};}
[x]
for c in text.chars(){let count = counts.entry(c).or_insert(0);*count += 1;}
[ ]
for c in text.chars(){let count = counts.entry(c);*count += 1;}
[ ]
for c in text.chars(){
counts.entry(c).or_insert(0).map(|x| x + 1);}
Q17. Which fragment does not incur memory allocations while writing to a "file" (represented by a Vec)?
use std::collections::HashMap;fnmain() -> Result<(),Box<dyn std::error::Error>>{letmut v = Vec::<u8>::new();let a = "LinkedIn";let b = 123;let c = '🧀';// replace this lineprintln!("{:?}", v);Ok(())}
Q27. Your application requires a single copy of some data type T to be held in memory that can be accessed by multiple threads. What is the thread-safe wrapper type?