1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-25 07:50:27 +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.
## 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`.
## 1.13.1 - 2020-12-13

View File

@ -815,7 +815,7 @@
(sort-help a lo right by)
(sort-help a left hi by))
a)
(defn sort
"Sort an array in-place. Uses quick-sort and is not a stable sort."
[a &opt by]
@ -2598,7 +2598,8 @@
(unmarshal image load-image-dict))
(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
```
@ -2634,8 +2635,8 @@
(defn- find-prefix
[pre]
(or (find-index |(and (string? ($ 0)) (string/has-prefix? pre ($ 0))) module/paths) 0))
(def all-index (find-prefix ":all:"))
(array/insert module/paths all-index [(string ":all:" ext) loader not-check-.])
(def all-index (find-prefix ".:all:"))
(array/insert module/paths all-index [(string ".:all:" ext) loader check-/])
(def sys-index (find-prefix ":sys:"))
(array/insert module/paths sys-index [(string ":sys:/:all:" ext) loader not-check-.])
(def curall-index (find-prefix ":cur:/:all:"))
@ -2700,6 +2701,7 @@
(undef mod-filter)
(undef check-.)
(undef not-check-.)
(undef check-/)
(def module/loading
`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:
hash = janet_struct_hash(janet_unwrap_struct(x));
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: {
JanetAbstract xx = janet_unwrap_abstract(x);
const JanetAbstractType *at = janet_abstract_type(xx);