summaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
Diffstat (limited to 'std')
-rw-r--r--std/core.zc2
-rw-r--r--std/map.zc3
-rw-r--r--std/set.zc3
-rw-r--r--std/time.zc9
4 files changed, 15 insertions, 2 deletions
diff --git a/std/core.zc b/std/core.zc
index daf6a96..bfa82ea 100644
--- a/std/core.zc
+++ b/std/core.zc
@@ -4,3 +4,5 @@ include <string.h>
include <stdio.h>
include <stdbool.h>
include <stdarg.h>
+
+var __zen_hash_seed: usize = 14695981039346656037; \ No newline at end of file
diff --git a/std/map.zc b/std/map.zc
index cd54f3d..a7bae69 100644
--- a/std/map.zc
+++ b/std/map.zc
@@ -3,8 +3,9 @@ import "./core.zc"
import "./option.zc"
raw {
+ extern size_t __zen_hash_seed;
size_t _map_hash_str(const char* str) {
- size_t hash = 14695981039346656037UL;
+ size_t hash = __zen_hash_seed;
while (*str) {
hash ^= (unsigned char)*str++;
hash *= 1099511628211UL;
diff --git a/std/set.zc b/std/set.zc
index b5a2e58..1de43ac 100644
--- a/std/set.zc
+++ b/std/set.zc
@@ -3,8 +3,9 @@ import "./core.zc"
import "./option.zc"
raw {
+ extern size_t __zen_hash_seed;
size_t _set_hash(const void* data, size_t len) {
- size_t hash = 14695981039346656037UL;
+ size_t hash = __zen_hash_seed;
const unsigned char* bytes = (const unsigned char*)data;
for (size_t i = 0; i < len; i++) {
hash ^= bytes[i];
diff --git a/std/time.zc b/std/time.zc
index 72e611a..1191821 100644
--- a/std/time.zc
+++ b/std/time.zc
@@ -29,7 +29,16 @@ impl Duration {
struct Time {}
+extern size_t __zen_hash_seed;
+
impl Time {
+ fn randomize_hash() {
+ raw {
+ srand(time(NULL));
+ __zen_hash_seed ^= (size_t)rand();
+ }
+ }
+
fn now() -> U64 {
return _time_now_impl();
}