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 - .../compiler/analysis/procedure/common.lux | 2 -- 3 files changed, 24 insertions(+), 6 deletions(-) (limited to 'stdlib') 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)))) ))) diff --git a/stdlib/test/test/lux/language/compiler/analysis/procedure/common.lux b/stdlib/test/test/lux/language/compiler/analysis/procedure/common.lux index 9b51084fe..1f7021039 100644 --- a/stdlib/test/test/lux/language/compiler/analysis/procedure/common.lux +++ b/stdlib/test/test/lux/language/compiler/analysis/procedure/common.lux @@ -161,8 +161,6 @@ (check-success+ "lux text index" (list subjectC paramC fromC) (type (Maybe Nat)))) (test "Can query the size/length of a text." (check-success+ "lux text size" (list subjectC) Nat)) - (test "Can calculate a hash code for text." - (check-success+ "lux text hash" (list subjectC) Nat)) (test "Can obtain the character code of a text at a given index." (check-success+ "lux text char" (list subjectC fromC) (type (Maybe Nat)))) (test "Can clip a piece of text between 2 indices." -- cgit v1.2.3