Struct midenc_hir::OrderedArenaMap
source · pub struct OrderedArenaMap<K: EntityRef, V> { /* private fields */ }Expand description
OrderedArenaMap is an extension of ArenaMap that provides for arbitrary ordering of keys/values
This is done using an intrusive linked list alongside an ArenaMap. The list is used to link one key/value pair to the next, so any ordering you wish to implement is possible. This is particularly useful for layout of blocks in a function, or instructions within blocks, as you can precisely position them relative to other blocks/instructions.
Because the linked list is intrusive, it is virtually free in terms of space, but comes with the standard overhead for traversals. That said, there are a couple of niceties that give it good overall performance:
- It is a doubly-linked list, so you can traverse equally efficiently front-to-back or back-to-front,
- It has O(1) indexing; given a key, we can directly obtain a reference to a node, and with that, obtain a cursor over the list starting at that node.
Implementations§
source§impl<K: EntityRef, V> OrderedArenaMap<K, V>
impl<K: EntityRef, V> OrderedArenaMap<K, V>
pub fn new() -> Self
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this OrderedArenaMap is empty
sourcepub fn contains(&self, key: K) -> bool
pub fn contains(&self, key: K) -> bool
Returns true if this map contains the given key and its value has been linked
sourcepub fn get(&self, key: K) -> Option<&V>
pub fn get(&self, key: K) -> Option<&V>
Returns a reference to the value associated with the given key, if present and linked
sourcepub fn get_mut(&mut self, key: K) -> Option<&mut V>
pub fn get_mut(&mut self, key: K) -> Option<&mut V>
Returns a mutable reference to the value associated with the given key, if present and linked
sourcepub fn append(&mut self, key: K, value: V)
pub fn append(&mut self, key: K, value: V)
Used with create when ready to associate data with the allocated key, linking it in to the
end of the list
sourcepub fn insert_before(&mut self, key: K, before: K, value: V)
pub fn insert_before(&mut self, key: K, before: K, value: V)
Like append, but inserts the node before before in the list
NOTE: This function will panic if before is not present in the list
sourcepub fn insert_after(&mut self, key: K, after: K, value: V)
pub fn insert_after(&mut self, key: K, after: K, value: V)
Like append, but inserts the node after after in the list
NOTE: This function will panic if after is not present in the list
sourcepub fn push_after(&mut self, after: K, value: V) -> K
pub fn push_after(&mut self, after: K, value: V) -> K
Like push, but inserts the node after after in the list
NOTE: This function will panic if after is not present in the list
sourcepub fn remove(&mut self, key: K)
pub fn remove(&mut self, key: K)
Unlinks the value associated with the given key from this map
NOTE: Removal does not result in deallocation of the underlying data, this happens when the map is dropped. To perform early garbage collection, you can clone the map, and drop the original.
sourcepub fn first(&self) -> Option<&LayoutNode<K, V>>
pub fn first(&self) -> Option<&LayoutNode<K, V>>
Returns the first node in the map
sourcepub fn last(&self) -> Option<&LayoutNode<K, V>>
pub fn last(&self) -> Option<&LayoutNode<K, V>>
Returns the last node in the map
sourcepub fn cursor(&self) -> Cursor<'_, LayoutAdapter<K, V>>
pub fn cursor(&self) -> Cursor<'_, LayoutAdapter<K, V>>
Returns a cursor which can be used to traverse the map in order (front to back)
sourcepub fn cursor_mut(&mut self) -> CursorMut<'_, LayoutAdapter<K, V>>
pub fn cursor_mut(&mut self) -> CursorMut<'_, LayoutAdapter<K, V>>
Returns a cursor which can be used to traverse the map mutably, in order (front to back)
sourcepub fn cursor_at(&self, key: K) -> Cursor<'_, LayoutAdapter<K, V>>
pub fn cursor_at(&self, key: K) -> Cursor<'_, LayoutAdapter<K, V>>
Returns a cursor which can be used to traverse the map in order (front to back), starting at the key given.
sourcepub fn cursor_mut_at(&mut self, key: K) -> CursorMut<'_, LayoutAdapter<K, V>>
pub fn cursor_mut_at(&mut self, key: K) -> CursorMut<'_, LayoutAdapter<K, V>>
Returns a cursor which can be used to traverse the map mutably, in order (front to back), starting at the key given.
sourcepub fn iter(&self) -> OrderedArenaMapIter<'_, K, V>
pub fn iter(&self) -> OrderedArenaMapIter<'_, K, V>
Returns an iterator over the key/value pairs in the map.
The iterator is double-ended, so can be used to traverse the map front-to-back, or back-to-front
Trait Implementations§
source§impl<K: EntityRef, V> Default for OrderedArenaMap<K, V>
impl<K: EntityRef, V> Default for OrderedArenaMap<K, V>
source§impl<K: EntityRef, V> Drop for OrderedArenaMap<K, V>
impl<K: EntityRef, V> Drop for OrderedArenaMap<K, V>
source§impl<K: EntityRef, V> Index<K> for OrderedArenaMap<K, V>
impl<K: EntityRef, V> Index<K> for OrderedArenaMap<K, V>
Auto Trait Implementations§
impl<K, V> !Freeze for OrderedArenaMap<K, V>
impl<K, V> !RefUnwindSafe for OrderedArenaMap<K, V>
impl<K, V> !Send for OrderedArenaMap<K, V>
impl<K, V> !Sync for OrderedArenaMap<K, V>
impl<K, V> Unpin for OrderedArenaMap<K, V>
impl<K, V> !UnwindSafe for OrderedArenaMap<K, V>
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§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>
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>
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 moresource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moresource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more