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 | |
parent | f76922dfef6e88db854a27dc17987ccdc9736d6a (diff) |
- Removed "lux text hash" extension.
17 files changed, 27 insertions, 69 deletions
diff --git a/luxc/src/lux/analyser/proc/common.clj b/luxc/src/lux/analyser/proc/common.clj index 4d2f40277..359fcb314 100644 --- a/luxc/src/lux/analyser/proc/common.clj +++ b/luxc/src/lux/analyser/proc/common.clj @@ -84,7 +84,6 @@ (&/|list))))))) ^:private analyse-text-size "size" - ^:private analyse-text-hash "hash" ) (defn ^:private analyse-text-char [analyse exo-type ?values] @@ -425,7 +424,6 @@ "lux text clip" (analyse-text-clip analyse exo-type ?values) "lux text index" (analyse-text-index analyse exo-type ?values) "lux text size" (analyse-text-size analyse exo-type ?values) - "lux text hash" (analyse-text-hash analyse exo-type ?values) "lux text char" (analyse-text-char analyse exo-type ?values) "lux array new" (analyse-array-new analyse exo-type ?values) diff --git a/luxc/src/lux/compiler/jvm/proc/common.clj b/luxc/src/lux/compiler/jvm/proc/common.clj index 244e7baa8..3b490ebb6 100644 --- a/luxc/src/lux/compiler/jvm/proc/common.clj +++ b/luxc/src/lux/compiler/jvm/proc/common.clj @@ -405,7 +405,6 @@ (return nil))) ^:private compile-text-size "java/lang/String" "length" - ^:private compile-text-hash "java/lang/Object" "hashCode" ) (defn ^:private compile-text-char [compile ?values special-args] @@ -626,7 +625,6 @@ "clip" (compile-text-clip compile ?values special-args) "index" (compile-text-index compile ?values special-args) "size" (compile-text-size compile ?values special-args) - "hash" (compile-text-hash compile ?values special-args) "char" (compile-text-char compile ?values special-args) ) diff --git a/new-luxc/source/luxc/lang/translation/common-lisp/procedure/common.jvm.lux b/new-luxc/source/luxc/lang/translation/common-lisp/procedure/common.jvm.lux index e1ba0494a..8148bf0c6 100644 --- a/new-luxc/source/luxc/lang/translation/common-lisp/procedure/common.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/common-lisp/procedure/common.jvm.lux @@ -311,7 +311,6 @@ (install "concat" (binary text//concat)) (install "index" (trinary text//index)) (install "size" (unary _.length)) - (install "hash" (unary _.sxhash/1)) (install "char" (binary text//char)) (install "clip" (trinary text//clip)) ))) diff --git a/new-luxc/source/luxc/lang/translation/js/procedure/common.jvm.lux b/new-luxc/source/luxc/lang/translation/js/procedure/common.jvm.lux index cdaa22eee..a2b30390d 100644 --- a/new-luxc/source/luxc/lang/translation/js/procedure/common.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/js/procedure/common.jvm.lux @@ -255,7 +255,6 @@ [int//to-frac runtimeT.int//to-number] [frac//to-int runtimeT.int//from-number] - [text//hash runtimeT.text//hash] ) (def: (int//char inputJS) @@ -440,7 +439,6 @@ (install "concat" (binary text//concat)) (install "index" (trinary text//index)) (install "size" (unary text//size)) - (install "hash" (unary text//hash)) (install "char" (binary text//char)) (install "clip" (trinary text//clip)) ))) diff --git a/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux b/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux index 267a3e637..9840bba1f 100644 --- a/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux @@ -591,21 +591,11 @@ "}") "})")) -(runtime: text//hash "textHash" - (format "(function " @ "(input) {" - "var hash = 0;" - (format "for(var i = 0; i < input.length; i++) {" - "hash = (((hash << 5) - hash) + input.charCodeAt(i)) & 0xFFFFFFFF;" - "}") - "return " int//from-number "(hash);" - "})")) - (def: runtime//text Runtime (format __text//index __text//clip - __text//char - __text//hash)) + __text//char)) (runtime: array//get "arrayGet" (format "(function " @ "(arr,idx) {" diff --git a/new-luxc/source/luxc/lang/translation/jvm/procedure/common.jvm.lux b/new-luxc/source/luxc/lang/translation/jvm/procedure/common.jvm.lux index 10b8cb75d..527ec4f2d 100644 --- a/new-luxc/source/luxc/lang/translation/jvm/procedure/common.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/jvm/procedure/common.jvm.lux @@ -322,7 +322,6 @@ <post>))] [text//size "java.lang.String" "length" lux-intI $t.int] - [text//hash "java.lang.Object" "hashCode" lux-intI $t.int] ) (do-template [<name> <pre-subject> <pre-param> <op> <post>] @@ -583,7 +582,6 @@ (install "concat" (binary text//concat)) (install "index" (trinary text//index)) (install "size" (unary text//size)) - (install "hash" (unary text//hash)) (install "char" (binary text//char)) (install "clip" (trinary text//clip)) ))) diff --git a/new-luxc/source/luxc/lang/translation/lua/procedure/common.jvm.lux b/new-luxc/source/luxc/lang/translation/lua/procedure/common.jvm.lux index 7497aeca2..c750bbaf4 100644 --- a/new-luxc/source/luxc/lang/translation/lua/procedure/common.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/lua/procedure/common.jvm.lux @@ -255,7 +255,6 @@ (|> inputO <transform>))] [frac//to-int (<| (lua.apply "math.floor") (list))] - [text//hash runtimeT.text//hash] ) (def: int//char @@ -428,7 +427,6 @@ (install "concat" (binary text//concat)) (install "index" (trinary text//index)) (install "size" (unary text//size)) - (install "hash" (unary text//hash)) (install "char" (binary text//char)) (install "clip" (trinary text//clip)) ))) diff --git a/new-luxc/source/luxc/lang/translation/lua/runtime.jvm.lux b/new-luxc/source/luxc/lang/translation/lua/runtime.jvm.lux index 9e7dc7422..2c0dfec17 100644 --- a/new-luxc/source/luxc/lang/translation/lua/runtime.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/lua/runtime.jvm.lux @@ -207,21 +207,11 @@ (lua.return! none) (lua.return! (some "char")))))) -(runtime: (text//hash input) - (lua.block! (list (lua.local! "hash" (#.Some (lua.int 0))) - (lua.for-step! "idx" (lua.int 1) (lua.apply "string.len" (list input)) (lua.int 1) - (lua.set! "hash" (|> "hash" - (lua.bit-shl (lua.int 5)) - (lua.- "hash") - (lua.+ (lua.apply "string.byte" (list input "idx")))))) - (lua.return! "hash")))) - (def: runtime//text Runtime (format @@text//index @@text//clip - @@text//char - @@text//hash)) + @@text//char)) (def: (check-index-out-of-bounds array idx body!) (-> Expression Expression Statement Statement) diff --git a/new-luxc/source/luxc/lang/translation/php/procedure/common.jvm.lux b/new-luxc/source/luxc/lang/translation/php/procedure/common.jvm.lux index 3f9825737..eea8682d3 100644 --- a/new-luxc/source/luxc/lang/translation/php/procedure/common.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/php/procedure/common.jvm.lux @@ -323,7 +323,6 @@ ## (install "concat" (binary text//concat)) ## (install "index" (trinary text//index)) ## (install "size" (unary (apply1 (_.global "len")))) -## (install "hash" (unary (apply1 (_.global "hash")))) ## (install "char" (binary text//char)) ## (install "clip" (trinary text//clip)) ## ))) diff --git a/new-luxc/source/luxc/lang/translation/python/procedure/common.jvm.lux b/new-luxc/source/luxc/lang/translation/python/procedure/common.jvm.lux index ea3d25687..2dece65c5 100644 --- a/new-luxc/source/luxc/lang/translation/python/procedure/common.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/python/procedure/common.jvm.lux @@ -343,7 +343,6 @@ (install "concat" (binary text//concat)) (install "index" (trinary text//index)) (install "size" (unary (apply1 (python.global "len")))) - (install "hash" (unary (apply1 (python.global "hash")))) (install "char" (binary text//char)) (install "clip" (trinary text//clip)) ))) diff --git a/new-luxc/source/luxc/lang/translation/r/procedure/common.jvm.lux b/new-luxc/source/luxc/lang/translation/r/procedure/common.jvm.lux index 2e6ea90e2..00f04e49f 100644 --- a/new-luxc/source/luxc/lang/translation/r/procedure/common.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/r/procedure/common.jvm.lux @@ -325,7 +325,6 @@ (install "concat" (binary text//concat)) (install "index" (trinary text//index)) (install "size" (unary (|>> (apply1 (r.global "nchar")) runtimeT.int//from-float))) - (install "hash" (unary runtimeT.text//hash)) (install "char" (binary text//char)) (install "clip" (trinary text//clip)) ))) diff --git a/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux b/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux index 09bc9e7b0..9cab92115 100644 --- a/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux @@ -720,26 +720,12 @@ (..some (int//from-float (char-at (@@ idx) (@@ text))))) ..none)) -(runtime: (text//hash input) - (let [bits-32 (r.code "0xFFFFFFFF")] - (with-vars [idx hash] - ($_ r.then - (r.set! hash (r.int 0)) - (r.for-in idx (r.range (r.int 1) (text-length (@@ input))) - (r.set! hash (|> (@@ hash) - (r.bit-shl (r.int 5)) - (r.- (@@ hash)) - (r.+ (char-at (@@ idx) (@@ input))) - (r.bit-and bits-32)))) - (int//from-float (@@ hash)))))) - (def: runtime//text Runtime ($_ r.then @@text//index @@text//clip - @@text//char - @@text//hash)) + @@text//char)) (def: (check-index-out-of-bounds array idx body) (-> Expression Expression Expression Expression) diff --git a/new-luxc/source/luxc/lang/translation/ruby/procedure/common.jvm.lux b/new-luxc/source/luxc/lang/translation/ruby/procedure/common.jvm.lux index 01ca1e8b4..7100cf9a4 100644 --- a/new-luxc/source/luxc/lang/translation/ruby/procedure/common.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/ruby/procedure/common.jvm.lux @@ -329,7 +329,6 @@ (ruby.send <op> (list)))] [text//size "length"] - [text//hash "hash"] ) (def: (text//concat [subjectO paramO]) @@ -357,7 +356,6 @@ (install "concat" (binary text//concat)) (install "index" (trinary text//index)) (install "size" (unary text//size)) - (install "hash" (unary text//hash)) (install "char" (binary text//char)) (install "clip" (trinary text//clip)) ))) diff --git a/new-luxc/test/test/luxc/lang/translation/common.lux b/new-luxc/test/test/luxc/lang/translation/common.lux index f933abe8d..0e2d66503 100644 --- a/new-luxc/test/test/luxc/lang/translation/common.lux +++ b/new-luxc/test/test/luxc/lang/translation/common.lux @@ -248,16 +248,6 @@ _ false)))) - (test "Text hashing is consistent." - (|> (run (` ("lux int =" - ("lux text hash" (~ sample0S)) - ("lux text hash" (~ sample0S))))) - (case> (#e.Success valueV) - (:coerce Bool valueV) - - (#e.Error error) - (exec (log! error) - false)))) (let [test-clip (function (_ from to expected) (|> (run (` ("lux text clip" (~ concatenatedS) 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)))) ))) 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." |