/// Initialize a new dependency graph writer with the given
/// set of sorted hashes.
///
/// # Panics
///
/// - If the list of hashes is empty.
/// - If the given list of hashes is not sorted or deduplicated.
Initialize a new dependency graph writer with the given
set of sorted hashes.
Initialize a new dependency graph writer with the given set of sorted hashes .
pub fn new(sorted_hashes: Vec<u64>) -> std::io::Result<Self> {
        let num_hashes: u32 = sorted_hashes.len().try_into().unwrap();
        // The indexer starts right after the header
        let indexer_offset = 4 * 2;
        // Lookup table offset is on page boundary, after indexer
        let mut lookup_table_offset = indexer_offset + 8 + num_hashes * 8;
        if lookup_table_offset & (PAGE_ALIGN - 1) != 0 {
            lookup_table_offset += PAGE_ALIGN;
            lookup_table_offset &= !(PAGE_ALIGN - 1);
        }
        // Next set offset is on page boundary, after look up table
        let mut next_set_offset = lookup_table_offset + num_hashes * 4;
        if next_set_offset & (PAGE_ALIGN - 1) != 0 {
            next_set_offset += PAGE_ALIGN;
            next_set_offset &= !(PAGE_ALIGN - 1);
        }
        // Check sorted
        let mut hashes_iter = sorted_hashes.iter();
        let mut prev_hash = hashes_iter.next();
        for h in hashes_iter {
            if h <= prev_hash.unwrap() {
                panic!("hashes not sorted: {} <= {}", h, prev_hash.unwrap());
            }
            prev_hash = Some(h);
        }
        // Indexer!
        let indexer = ShardedIndexerWriter::new();
        sorted_hashes.par_iter().enumerate().for_each(|(i, h)| {
            indexer.insert(*h, HashIndex(i as u32));
        });
        Ok(DepGraphWriter {
            state: DepGraphWriterState {
                indexer_offset,
                lookup_table_offset,
                next_set_offset,
                sorted_hashes,
                indexer: indexer.into_read_only(),
                lookup_table: ShardedLookupTable::new(vec![]),
            },
            phase: Phase1AllocateHashSets,
        })
    }
pub fn new ( sorted_hashes : Vec < u64 > ) -> std :: io :: Result < Self > { let num_hashes : u32 = sorted_hashes . len ( ) . try_into ( ) . unwrap ( ) ; // The indexer starts right after the header let indexer_offset = 4 * 2 ; // Lookup table offset is on page boundary, after indexer let mut lookup_table_offset = indexer_offset + 8 + num_hashes * 8 ; if lookup_table_offset & ( PAGE_ALIGN - 1 ) != 0 { lookup_table_offset += PAGE_ALIGN ; lookup_table_offset &= ! ( PAGE_ALIGN - 1 ) ; } // Next set offset is on page boundary, after look up table let mut next_set_offset = lookup_table_offset + num_hashes * 4 ; if next_set_offset & ( PAGE_ALIGN - 1 ) != 0 { next_set_offset += PAGE_ALIGN ; next_set_offset &= ! ( PAGE_ALIGN - 1 ) ; } // Check sorted let mut hashes_iter = sorted_hashes . iter ( ) ; let mut prev_hash = hashes_iter . next ( ) ; for h in hashes_iter { if h <= prev_hash . unwrap ( ) { panic ! ( " " h prev_hash unwrap ( ) ) ; } prev_hash = Some ( h ) ; } // Indexer! let indexer = ShardedIndexerWriter :: new ( ) ; sorted_hashes . par_iter ( ) . enumerate ( ) . for_each ( | ( i , h ) | { indexer . insert ( * h , HashIndex ( i as u32 ) ) ; } ) ; Ok ( DepGraphWriter { state : DepGraphWriterState { indexer_offset , lookup_table_offset , next_set_offset , sorted_hashes , indexer : indexer . into_read_only ( ) , lookup_table : ShardedLookupTable :: new ( vec ! [ ] ) , } , phase : Phase1AllocateHashSets , } ) }
Initialize a new dependency graph writer with the given
set of sorted hashes.
Initialize a new dependency graph writer with the given set of sorted hashes .
sorted_hashes
Vec<u64>
panics
If the list of hashes is empty.
If the given list of hashes is not sorted or deduplicated.
If the list of hashes is empty . If the given list of hashes is not sorted or deduplicated .