本文簡要介紹rust語言中 std::collections::hash_map::HashMap.shrink_to
的用法。
用法
pub fn shrink_to(&mut self, min_capacity: usize)
使用下限縮小Map的容量。它將下降不低於提供的限製,同時保持內部規則並可能根據調整大小策略留下一些空間。
如果當前容量小於下限,則為no-op。
例子
use std::collections::HashMap;
let mut map: HashMap<i32, i32> = HashMap::with_capacity(100);
map.insert(1, 2);
map.insert(3, 4);
assert!(map.capacity() >= 100);
map.shrink_to(10);
assert!(map.capacity() >= 10);
map.shrink_to(0);
assert!(map.capacity() >= 2);
相關用法
- Rust HashMap.shrink_to_fit用法及代碼示例
- Rust HashMap.get用法及代碼示例
- Rust HashMap.try_insert用法及代碼示例
- Rust HashMap.keys用法及代碼示例
- Rust HashMap.iter用法及代碼示例
- Rust HashMap.iter_mut用法及代碼示例
- Rust HashMap.retain用法及代碼示例
- Rust HashMap.with_capacity_and_hasher用法及代碼示例
- Rust HashMap.clear用法及代碼示例
- Rust HashMap.reserve用法及代碼示例
- Rust HashMap.with_hasher用法及代碼示例
- Rust HashMap.into_keys用法及代碼示例
- Rust HashMap.into_values用法及代碼示例
- Rust HashMap.get_mut用法及代碼示例
- Rust HashMap.is_empty用法及代碼示例
- Rust HashMap.drain用法及代碼示例
- Rust HashMap.drain_filter用法及代碼示例
- Rust HashMap.len用法及代碼示例
- Rust HashMap.remove用法及代碼示例
- Rust HashMap.insert用法及代碼示例
- Rust HashMap.entry用法及代碼示例
- Rust HashMap.capacity用法及代碼示例
- Rust HashMap.contains_key用法及代碼示例
- Rust HashMap.values用法及代碼示例
- Rust HashMap.values_mut用法及代碼示例
注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 std::collections::hash_map::HashMap.shrink_to。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。