diff options
author | Eduardo Julian | 2018-07-11 22:21:23 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-07-11 22:21:23 -0400 |
commit | 81480739f4c5caa468b295eb047e5844d39701ca (patch) | |
tree | c0b95639cd9427f8ecf57220a38b413fb9845145 /stdlib/source | |
parent | f76922dfef6e88db854a27dc17987ccdc9736d6a (diff) |
- Removed "lux text hash" extension.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/data/text.lux | 27 | ||||
-rw-r--r-- | stdlib/source/lux/language/compiler/extension/analysis/common.lux | 1 |
2 files changed, 24 insertions, 4 deletions
diff --git a/stdlib/source/lux/data/text.lux b/stdlib/source/lux/data/text.lux index 6fc05aa9c..6106e434e 100644 --- a/stdlib/source/lux/data/text.lux +++ b/stdlib/source/lux/data/text.lux @@ -8,8 +8,12 @@ [codec (#+ Codec)] hash] [data - [collection [list ("list/" Fold<List>)]] - [maybe]]]) + [bit] + [maybe] + [collection + [list ("list/" Fold<List>)]]] + [language + [host]]]) (def: #export (size x) (-> Text Nat) @@ -166,7 +170,24 @@ (def: eq Equivalence<Text>) (def: (hash input) - ("lux text hash" input))) + (`` (for {(~~ (static host.jvm)) + (|> input + (: (primitive "java.lang.String" [])) + "jvm invokevirtual:java.lang.String:hashCode:" + "jvm convert int-to-long" + (:coerce Nat))} + ## Platform-independent default. + (let [length ("lux text size" input)] + (loop [idx +0 + hash +0] + (if (n/< length idx) + (let [char (|> idx ("lux text char" input) (maybe.default +0))] + (recur (inc idx) + (|> hash + (bit.left-shift +5) + (n/- hash) + (n/+ char)))) + hash))))))) (def: #export concat (-> (List Text) Text) diff --git a/stdlib/source/lux/language/compiler/extension/analysis/common.lux b/stdlib/source/lux/language/compiler/extension/analysis/common.lux index 1a377ec14..0dac69ced 100644 --- a/stdlib/source/lux/language/compiler/extension/analysis/common.lux +++ b/stdlib/source/lux/language/compiler/extension/analysis/common.lux @@ -204,7 +204,6 @@ (///bundle.install "concat" (binary Text Text Text)) (///bundle.install "index" (trinary Text Text Nat (type (Maybe Nat)))) (///bundle.install "size" (unary Text Nat)) - (///bundle.install "hash" (unary Text Nat)) (///bundle.install "char" (binary Text Nat (type (Maybe Nat)))) (///bundle.install "clip" (trinary Text Nat Nat (type (Maybe Text)))) ))) |