Skip to content

Commit 7e3109f

Browse files
Gavin-Niedermanmax-niederman
authored andcommitted
refactor: pseudorandom hashmap keys
1 parent 3bc8588 commit 7e3109f

File tree

1 file changed

+14
-1
lines changed
  • library/std/src/sys/pal/vexos

1 file changed

+14
-1
lines changed

library/std/src/sys/pal/vexos/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub mod thread_local_key;
2121
pub mod time;
2222

2323
use crate::{arch::asm, ptr::{self, addr_of_mut}};
24+
use crate::hash::{DefaultHasher, Hasher};
2425

2526
#[cfg(not(test))]
2627
#[no_mangle]
@@ -87,6 +88,18 @@ pub fn abort_internal() -> ! {
8788
}
8889
}
8990

91+
fn hash_time() -> u64 {
92+
let mut hasher = DefaultHasher::new();
93+
// The closest we can get to a random number is the time since program start
94+
let time = unsafe {
95+
vex_sdk::vexSystemHighResTimeGet()
96+
};
97+
hasher.write_u64(time);
98+
hasher.finish()
99+
}
100+
90101
pub fn hashmap_random_keys() -> (u64, u64) {
91-
(1, 2)
102+
let key1 = hash_time();
103+
let key2 = hash_time();
104+
(key1, key2)
92105
}

0 commit comments

Comments
 (0)