Skip to content

Commit

Permalink
Small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-M-Lucas committed Jul 26, 2024
1 parent 64ca194 commit 2af8522
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 50 deletions.
41 changes: 16 additions & 25 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 4 additions & 25 deletions src/root/unrandom.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::hash::RandomState;
use std::{mem, ptr, slice};
use std::collections::{HashMap, HashSet};

#[inline]
Expand All @@ -16,19 +15,9 @@ pub fn new_hashmap<A, B>() -> HashMap<A, B> {

#[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>())
let r: RandomState = unsafe {
std::mem::transmute([0u8; 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)
}
Expand All @@ -47,19 +36,9 @@ pub fn new_hashset<A>() -> HashSet<A> {

#[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>())
let r: RandomState = unsafe {
std::mem::transmute([0u8; 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)
}

0 comments on commit 2af8522

Please sign in to comment.