pub struct AllOne { /* private fields */ }
Expand description
双向链表 + 两个 HashMap
本实现使用 NonNull
封装裸指针,需要注意在删除节点或者 Drop 整个结构的时候需要用
Box::from_raw()
来释放内存。
keys: HashMap<String, u32>
记录该数据结构内所有的 key 对应的值,以便用 O(1) 的时间查找 keyindex: HashMap<u32, NonNull<Node>>
记录该数据结构内所有 key 的值(作为 key)在链表结构里对应的节点的指针
Implementations§
Source§impl AllOne
&self
means the method takes an immutable reference.
If you need a mutable reference, change it to &mut self
instead.
impl AllOne
&self
means the method takes an immutable reference.
If you need a mutable reference, change it to &mut self
instead.
Sourcepub fn inc(&mut self, key: String)
pub fn inc(&mut self, key: String)
Inserts a new key
Sourcepub fn dec(&mut self, key: String)
pub fn dec(&mut self, key: String)
Decrements an existing key by 1. If Key’s value is 1, remove it from the data structure.
Sourcepub fn get_max_key(&self) -> String
pub fn get_max_key(&self) -> String
Returns one of the keys with maximal value.
Sourcepub fn get_min_key(&self) -> String
pub fn get_min_key(&self) -> String
Returns one of the keys with Minimal value.
Trait Implementations§
impl Send for AllOne
impl Sync for AllOne
Auto Trait Implementations§
impl Freeze for AllOne
impl RefUnwindSafe for AllOne
impl Unpin for AllOne
impl UnwindSafe for AllOne
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more