-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert-M-Lucas
committed
Jul 26, 2024
1 parent
33fd1f0
commit 64ca194
Showing
12 changed files
with
123 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
use std::collections::HashMap; | ||
use std::{mem, ptr, slice}; | ||
use std::hash::RandomState; | ||
|
||
mod root; | ||
|
||
|
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
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,65 @@ | ||
use std::hash::RandomState; | ||
use std::{mem, ptr, slice}; | ||
use std::collections::{HashMap, HashSet}; | ||
|
||
#[inline] | ||
pub fn new_hashmap<A, B>() -> HashMap<A, B> { | ||
#[cfg(debug_assertions)] | ||
{ | ||
unrandom_hashmap() | ||
} | ||
#[cfg(not(debug_assertions))] | ||
{ | ||
HashMap::new() | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn unrandom_hashmap<A, B>() -> HashMap<A, B> { | ||
let mut r = RandomState::new(); | ||
let p: *mut RandomState = &mut r; | ||
let p: *mut u8 = p as *mut u8; | ||
let s: &mut [u8] = unsafe { | ||
slice::from_raw_parts_mut(p, mem::size_of::<RandomState>()) | ||
}; | ||
unsafe { | ||
for s in &mut *s { | ||
let p: *const u8 = s; | ||
let p: *mut u8 = p as *mut u8; | ||
ptr::write_volatile(p, 0u8); | ||
} | ||
} | ||
|
||
HashMap::with_hasher(r) | ||
} | ||
|
||
#[inline] | ||
pub fn new_hashset<A>() -> HashSet<A> { | ||
#[cfg(debug_assertions)] | ||
{ | ||
unrandom_hashset() | ||
} | ||
#[cfg(not(debug_assertions))] | ||
{ | ||
HashSet::new() | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn unrandom_hashset<A>() -> HashSet<A> { | ||
let mut r = RandomState::new(); | ||
let p: *mut RandomState = &mut r; | ||
let p: *mut u8 = p as *mut u8; | ||
let s: &mut [u8] = unsafe { | ||
slice::from_raw_parts_mut(p, mem::size_of::<RandomState>()) | ||
}; | ||
unsafe { | ||
for s in &mut *s { | ||
let p: *const u8 = s; | ||
let p: *mut u8 = p as *mut u8; | ||
ptr::write_volatile(p, 0u8); | ||
} | ||
} | ||
|
||
HashSet::with_hasher(r) | ||
} |