aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/text.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/data/text.lux')
-rw-r--r--stdlib/source/lux/data/text.lux27
1 files changed, 24 insertions, 3 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)