1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-19 00:35:11 +00:00

Improve hash function for numbers.

This commit is contained in:
Calvin Rose
2020-12-26 15:38:04 -06:00
parent 7242ee0186
commit b4f242193d
3 changed files with 16 additions and 4 deletions

View File

@@ -2,6 +2,9 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## Unreleased - ??? ## Unreleased - ???
- Importing modules that start with `/` is now the only way to import from project root.
Before, this would import from / on disk.
- Change hash function for numbers.
- Improve error handling of `dofile`. - Improve error handling of `dofile`.
## 1.13.1 - 2020-12-13 ## 1.13.1 - 2020-12-13

View File

@@ -2598,7 +2598,8 @@
(unmarshal image load-image-dict)) (unmarshal image load-image-dict))
(defn- check-. [x] (if (string/has-prefix? "." x) x)) (defn- check-. [x] (if (string/has-prefix? "." x) x))
(defn- not-check-. [x] (unless (string/has-prefix? "." x) x)) (defn- not-check-. [x] (unless (or (string/has-prefix? "/" x) (string/has-prefix? "." x)) x))
(defn- check-/ [x] (if (string/has-prefix? "/" x) x))
(def module/paths (def module/paths
``` ```
@@ -2634,8 +2635,8 @@
(defn- find-prefix (defn- find-prefix
[pre] [pre]
(or (find-index |(and (string? ($ 0)) (string/has-prefix? pre ($ 0))) module/paths) 0)) (or (find-index |(and (string? ($ 0)) (string/has-prefix? pre ($ 0))) module/paths) 0))
(def all-index (find-prefix ":all:")) (def all-index (find-prefix ".:all:"))
(array/insert module/paths all-index [(string ":all:" ext) loader not-check-.]) (array/insert module/paths all-index [(string ".:all:" ext) loader check-/])
(def sys-index (find-prefix ":sys:")) (def sys-index (find-prefix ":sys:"))
(array/insert module/paths sys-index [(string ":sys:/:all:" ext) loader not-check-.]) (array/insert module/paths sys-index [(string ":sys:/:all:" ext) loader not-check-.])
(def curall-index (find-prefix ":cur:/:all:")) (def curall-index (find-prefix ":cur:/:all:"))
@@ -2700,6 +2701,7 @@
(undef mod-filter) (undef mod-filter)
(undef check-.) (undef check-.)
(undef not-check-.) (undef not-check-.)
(undef check-/)
(def module/loading (def module/loading
`Table mapping currently loading modules to true. Used to prevent `Table mapping currently loading modules to true. Used to prevent

View File

@@ -261,6 +261,13 @@ int32_t janet_hash(Janet x) {
case JANET_STRUCT: case JANET_STRUCT:
hash = janet_struct_hash(janet_unwrap_struct(x)); hash = janet_struct_hash(janet_unwrap_struct(x));
break; break;
case JANET_NUMBER: {
uint64_t i = janet_u64(x);
uint32_t lo = (uint32_t)(i & 0xFFFFFFFF);
uint32_t hi = (uint32_t)(i >> 32);
hash = (int32_t)(hi ^ lo);
break;
}
case JANET_ABSTRACT: { case JANET_ABSTRACT: {
JanetAbstract xx = janet_unwrap_abstract(x); JanetAbstract xx = janet_unwrap_abstract(x);
const JanetAbstractType *at = janet_abstract_type(xx); const JanetAbstractType *at = janet_abstract_type(xx);