struct TopKHashTable<ID: KeyType> {
map: RawTable<HashTableItem<ID>>,
limit: usize,
}Expand description
A custom wrapper around hashbrown::RawTable that:
- limits the number of entries to the top K
- Allocates a capacity greater than top K to maintain a low-fill factor and prevent resizing
- Tracks indexes to allow corresponding heap to refer to entries by index vs hash
- Catches resize events to allow the corresponding heap to update it’s indexes
Fields§
§map: RawTable<HashTableItem<ID>>§limit: usizeImplementations§
Source§impl<ID: KeyType> TopKHashTable<ID>
impl<ID: KeyType> TopKHashTable<ID>
pub fn new(limit: usize, capacity: usize) -> Self
pub fn find(&self, hash: u64, eq: impl FnMut(&ID) -> bool) -> Option<usize>
pub unsafe fn heap_idx_at(&self, map_idx: usize) -> usize
pub unsafe fn remove_if_full(&mut self, replace_idx: usize) -> usize
unsafe fn update_heap_idx(&mut self, mapper: &[(usize, usize)])
pub fn insert( &mut self, hash: u64, id: ID, heap_idx: usize, mapper: &mut Vec<(usize, usize)>, ) -> usize
pub fn len(&self) -> usize
pub unsafe fn take_all(&mut self, idxs: Vec<usize>) -> Vec<ID>
Auto Trait Implementations§
impl<ID> Freeze for TopKHashTable<ID>
impl<ID> RefUnwindSafe for TopKHashTable<ID>where
ID: RefUnwindSafe,
impl<ID> Send for TopKHashTable<ID>where
ID: Send,
impl<ID> Sync for TopKHashTable<ID>where
ID: Sync,
impl<ID> Unpin for TopKHashTable<ID>where
ID: Unpin,
impl<ID> UnwindSafe for TopKHashTable<ID>where
ID: UnwindSafe,
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more