-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a specialized varint + bitpacking scheme for DepGraph encoding
- Loading branch information
Showing
8 changed files
with
358 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use crate::dep_graph::DepNodeIndex; | ||
use smallvec::SmallVec; | ||
use std::hash::{Hash, Hasher}; | ||
use std::ops::Deref; | ||
|
||
#[derive(Default, Debug)] | ||
pub struct EdgesVec { | ||
max: u32, | ||
edges: SmallVec<[DepNodeIndex; EdgesVec::INLINE_CAPACITY]>, | ||
} | ||
|
||
impl Hash for EdgesVec { | ||
#[inline] | ||
fn hash<H: Hasher>(&self, hasher: &mut H) { | ||
Hash::hash(&self.edges, hasher) | ||
} | ||
} | ||
|
||
impl EdgesVec { | ||
pub const INLINE_CAPACITY: usize = 8; | ||
|
||
#[inline] | ||
pub fn new() -> Self { | ||
Self::default() | ||
} | ||
|
||
#[inline] | ||
pub fn push(&mut self, edge: DepNodeIndex) { | ||
self.max = self.max.max(edge.as_u32()); | ||
self.edges.push(edge); | ||
} | ||
|
||
#[inline] | ||
pub fn max_index(&self) -> u32 { | ||
self.max | ||
} | ||
} | ||
|
||
impl Deref for EdgesVec { | ||
type Target = [DepNodeIndex]; | ||
|
||
#[inline] | ||
fn deref(&self) -> &Self::Target { | ||
self.edges.as_slice() | ||
} | ||
} | ||
|
||
impl FromIterator<DepNodeIndex> for EdgesVec { | ||
#[inline] | ||
fn from_iter<T>(iter: T) -> Self | ||
where | ||
T: IntoIterator<Item = DepNodeIndex>, | ||
{ | ||
let mut vec = EdgesVec::new(); | ||
for index in iter { | ||
vec.push(index) | ||
} | ||
vec | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.