pub fn new<P : AsRef<path::Path>>(filename: P, root_bits: u8) -> Result<HashStore, HashStoreError> {
        let file_name = filename.as_ref();
        if !file_name.exists() {
            // create path
            if let Some(dir) = file_name.parent() {
                fs::create_dir_all(dir)?;
            };

            // create new file
            let hdr = header::Header::new(root_bits);
            let mut f = fs::File::create(&file_name)?;

            header::Header::write(&mut f, &hdr)?;

            let root_count = 1 << root_bits;
            f.set_len(mem::size_of::<header::Header>() as u64 + root_count * 8)?;
        }

        // open 2 handles
        let mut rw_file   = fs::OpenOptions::new().read(true).write(true).open(&file_name)?;
        let mmap_file     = fs::OpenOptions::new().read(true).write(true).open(&file_name)?;
        let append_file   = fs::OpenOptions::new().append(true).open(&file_name)?;

        // verify header
        let hdr = header::Header::read(&mut rw_file)?;
        let root_count = 1 << hdr.root_bits;

        if !hdr.is_correct_fileid() {
            return Err(HashStoreError::InvalidMagicFileId);
        }
        if hdr.root_bits != root_bits {
            return Err(HashStoreError::InvalidRootBits);
        }

        // setup memmap
        let mut mmap = memmap::Mmap::open_with_offset(
             &mmap_file,
            memmap::Protection::ReadWrite,
            0,
            mem::size_of::<header::Header>() + 8 * root_count
        )?;



        let u64_ptr = mmap.mut_ptr() as *mut atomic::AtomicU64;
        let u64_slice = unsafe { ::std::slice::from_raw_parts(u64_ptr, root_count + header::header_size_u64()) };

        // split our memmap in the root hash-table and stats
        let root = &u64_slice[header::header_size_u64()..];
        let stats = &u64_slice[header::stats_offset_u64()..header::header_size_u64()];
        let extrema = &u64_slice[header::extrema_offset_u64()..header::stats_offset_u64()];

        Ok(HashStore {
            _mmap: mmap,
            root: root,
            stats: stats,
            extrema: extrema,
            rw_file: rw_file,
            append_file: append_file,
            root_bits: root_bits,
        })
    }
/// Creates or opens a hashstore
///
/// `root_bits` is the number of bits of each key that are used for the root hash table
///
Creates or opens a hashstore
`root_bits` is the number of bits of each key that are used for the root hash table
Creates or opens a hashstore ` root_bits ` is the number of bits of each key that are used for the root hash table
pub fn new<P : AsRef<path::Path>>(filename: P, root_bits: u8) -> Result<HashStore, HashStoreError> {
        let file_name = filename.as_ref();
        if !file_name.exists() {
            // create path
            if let Some(dir) = file_name.parent() {
                fs::create_dir_all(dir)?;
            };
            // create new file
            let hdr = header::Header::new(root_bits);
            let mut f = fs::File::create(&file_name)?;
            header::Header::write(&mut f, &hdr)?;
            let root_count = 1 << root_bits;
            f.set_len(mem::size_of::<header::Header>() as u64 + root_count * 8)?;
        }
        // open 2 handles
        let mut rw_file   = fs::OpenOptions::new().read(true).write(true).open(&file_name)?;
        let mmap_file     = fs::OpenOptions::new().read(true).write(true).open(&file_name)?;
        let append_file   = fs::OpenOptions::new().append(true).open(&file_name)?;
        // verify header
        let hdr = header::Header::read(&mut rw_file)?;
        let root_count = 1 << hdr.root_bits;
        if !hdr.is_correct_fileid() {
            return Err(HashStoreError::InvalidMagicFileId);
        }
        if hdr.root_bits != root_bits {
            return Err(HashStoreError::InvalidRootBits);
        }
        // setup memmap
        let mut mmap = memmap::Mmap::open_with_offset(
             &mmap_file,
            memmap::Protection::ReadWrite,
            0,
            mem::size_of::<header::Header>() + 8 * root_count
        )?;
        let u64_ptr = mmap.mut_ptr() as *mut atomic::AtomicU64;
        let u64_slice = unsafe { ::std::slice::from_raw_parts(u64_ptr, root_count + header::header_size_u64()) };
        // split our memmap in the root hash-table and stats
        let root = &u64_slice[header::header_size_u64()..];
        let stats = &u64_slice[header::stats_offset_u64()..header::header_size_u64()];
        let extrema = &u64_slice[header::extrema_offset_u64()..header::stats_offset_u64()];
        Ok(HashStore {
            _mmap: mmap,
            root: root,
            stats: stats,
            extrema: extrema,
            rw_file: rw_file,
            append_file: append_file,
            root_bits: root_bits,
        })
    }
pub fn new < P : AsRef < path :: Path > > ( filename : P , root_bits : u8 ) -> Result < HashStore , HashStoreError > { let file_name = filename . as_ref ( ) ; if ! file_name . exists ( ) { // create path if let Some ( dir ) = file_name . parent ( ) { fs :: create_dir_all ( dir ) ? ; } ; // create new file let hdr = header :: Header :: new ( root_bits ) ; let mut f = fs :: File :: create ( & file_name ) ? ; header :: Header :: write ( & mut f , & hdr ) ? ; let root_count = 1 << root_bits ; f . set_len ( mem :: size_of :: < header :: Header > ( ) as u64 + root_count * 8 ) ? ; } // open 2 handles let mut rw_file = fs :: OpenOptions :: new ( ) . read ( true ) . write ( true ) . open ( & file_name ) ? ; let mmap_file = fs :: OpenOptions :: new ( ) . read ( true ) . write ( true ) . open ( & file_name ) ? ; let append_file = fs :: OpenOptions :: new ( ) . append ( true ) . open ( & file_name ) ? ; // verify header let hdr = header :: Header :: read ( & mut rw_file ) ? ; let root_count = 1 << hdr . root_bits ; if ! hdr . is_correct_fileid ( ) { return Err ( HashStoreError :: InvalidMagicFileId ) ; } if hdr . root_bits != root_bits { return Err ( HashStoreError :: InvalidRootBits ) ; } // setup memmap let mut mmap = memmap :: Mmap :: open_with_offset ( & mmap_file , memmap :: Protection :: ReadWrite , 0 , mem :: size_of :: < header :: Header > ( ) + 8 * root_count ) ? ; let u64_ptr = mmap . mut_ptr ( ) as * mut atomic :: AtomicU64 ; let u64_slice = unsafe { :: std :: slice :: from_raw_parts ( u64_ptr , root_count + header :: header_size_u64 ( ) ) } ; // split our memmap in the root hash-table and stats let root = & u64_slice [ header :: header_size_u64 ( ) .. ] ; let stats = & u64_slice [ header :: stats_offset_u64 ( ) .. header :: header_size_u64 ( ) ] ; let extrema = & u64_slice [ header :: extrema_offset_u64 ( ) .. header :: stats_offset_u64 ( ) ] ; Ok ( HashStore { _mmap : mmap , root : root , stats : stats , extrema : extrema , rw_file : rw_file , append_file : append_file , root_bits : root_bits , } ) }
Creates or opens a hashstore
`root_bits` is the number of bits of each key that are used for the root hash table
Creates or opens a hashstore ` root_bits ` is the number of bits of each key that are used for the root hash table
filename
P
root_bits
u8
filename
P
root_bits
u8