From 81480739f4c5caa468b295eb047e5844d39701ca Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 11 Jul 2018 22:21:23 -0400 Subject: - Removed "lux text hash" extension. --- stdlib/source/lux/data/text.lux | 27 +++++++++++++++++++--- .../compiler/extension/analysis/common.lux | 1 - 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'stdlib/source') 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)]] - [maybe]]]) + [bit] + [maybe] + [collection + [list ("list/" Fold)]]] + [language + [host]]]) (def: #export (size x) (-> Text Nat) @@ -166,7 +170,24 @@ (def: eq Equivalence) (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)))) ))) -- cgit v1.2.3