diff options
| author | ppedrot | 2013-10-24 17:28:00 +0000 |
|---|---|---|
| committer | ppedrot | 2013-10-24 17:28:00 +0000 |
| commit | 9e37e3b9695a214040c52082b1e7288df9362b33 (patch) | |
| tree | bc2bc853f3a01999ac4b07b847e43e747e6f104d /lib/cString.ml | |
| parent | 748d4e285c9352b5678e07963a295341cc6acc5b (diff) | |
Specializing hash functions for widely used types.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@16933 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'lib/cString.ml')
| -rw-r--r-- | lib/cString.ml | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/cString.ml b/lib/cString.ml index 823a356797..551b628342 100644 --- a/lib/cString.ml +++ b/lib/cString.ml @@ -46,6 +46,7 @@ module type ExtS = sig include S external equal : string -> string -> bool = "caml_string_equal" "noalloc" + val hash : string -> int val is_empty : string -> bool val explode : string -> string list val implode : string list -> string @@ -67,6 +68,16 @@ include String external equal : string -> string -> bool = "caml_string_equal" "noalloc" +let rec hash len s i accu = + if i = len then accu + else + let c = Char.code (String.unsafe_get s i) in + hash len s (succ i) (accu * 19 + c) + +let hash s = + let len = String.length s in + hash len s 0 0 + let explode s = let rec explode_rec n = if n >= String.length s then |
