Skip to content

Commit

Permalink
refactor cell alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoranYi committed Nov 8, 2022
1 parent 06189c9 commit 0770b0f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions runtime/src/cache_hash_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ pub type EntryType = CalculateHashIntermediate;
pub type SavedType = Vec<Vec<EntryType>>;
pub type SavedTypeSlice = [Vec<EntryType>];

const CELL_SIZE: usize = std::mem::size_of::<EntryType>();
const CELL_ALIGNMENT: usize = std::mem::align_of::<EntryType>();

#[repr(C)]
pub struct Header {
count: usize,
_align: [u8; CELL_ALIGNMENT - std::mem::size_of::<usize>()],
}

const HEADER_SIZE: usize = std::mem::size_of::<Header>();
const CELL_SIZE: usize = std::mem::size_of::<EntryType>();

pub(crate) struct CacheHashDataFile<const CELL_SIZE: usize, const HEADER_SIZE: usize> {
mmap: MmapMut,
Expand Down Expand Up @@ -87,7 +89,7 @@ impl<const CELL_SIZE: usize, const HEADER_SIZE: usize> CacheHashDataFile<CELL_SI
/// return byte offset of entry 'ix' into a slice which contains a header and at least ix elements
fn get_element_offset_byte(&self, ix: u64) -> usize {
let start = (ix as usize) * CELL_SIZE + HEADER_SIZE;
debug_assert_eq!(start % std::mem::align_of::<EntryType>(), 0);
debug_assert_eq!(start % CELL_ALIGNMENT, 0);
start
}

Expand Down

0 comments on commit 0770b0f

Please sign in to comment.