X-Git-Url: http://nitlanguage.org diff --git a/lib/standard/string.nit b/lib/standard/string.nit index 1c7e953..164e6f3 100644 --- a/lib/standard/string.nit +++ b/lib/standard/string.nit @@ -15,6 +15,7 @@ package string intrude import collection # FIXME should be collection::array +import hash ############################################################################### # String # @@ -246,6 +247,20 @@ special AbstractString end redef fun to_s do return self + + redef fun hash + do + # djb2 hash algorythm + var h = 5381 + var i = _length - 1 + var it = _items + while i >= 0 do + h = (h * 32) + h + it[i].ascii + i -= 1 + end + return h + + end end # Strings are arrays of characters. @@ -399,7 +414,7 @@ redef class Object return "<{object_id.to_hex}" end - protected fun args: IndexedCollection[String] + protected fun args: Sequence[String] do return sys.args end @@ -587,9 +602,9 @@ class StringCapable end redef class Sys - var _args_cache: nullable IndexedCollection[String] + var _args_cache: nullable Sequence[String] - redef fun args: IndexedCollection[String] + redef fun args: Sequence[String] do if _args_cache == null then init_args return _args_cache.as(not null)