小编3rf*_*fan的帖子

Rust 中 HashMap 的容量(Rust 实践)

我目前正在进行“Rust by Practice”练习。在“Collection Types > HashMap”部分有一个示例:

use std::collections::HashMap;
fn main() {
    let mut map: HashMap<i32, i32> = HashMap::with_capacity(100);
    map.insert(1, 2);
    map.insert(3, 4);
    // Indeed ,the capacity of HashMap is not 100, so we can't compare the equality here.
    assert!(map.capacity() >= 100);
    
    println!("Capacity #1: {}", map.capacity());

    // Shrinks the capacity of the map with a lower limit. It will drop
    // down no lower than the supplied limit while maintaining the internal rules
    // and possibly leaving some space in accordance …
Run Code Online (Sandbox Code Playgroud)

size dictionary hashmap capacity rust

2
推荐指数
1
解决办法
854
查看次数

标签 统计

capacity ×1

dictionary ×1

hashmap ×1

rust ×1

size ×1