Importing Upstream version 4.8.2
[platform/upstream/gcc48.git] / libgo / runtime / go-type-string.c
1 /* go-type-string.c -- hash and equality string functions.
2
3    Copyright 2009 The Go Authors. All rights reserved.
4    Use of this source code is governed by a BSD-style
5    license that can be found in the LICENSE file.  */
6
7 #include "runtime.h"
8 #include "go-type.h"
9 #include "go-string.h"
10
11 /* A string hash function for a map.  */
12
13 uintptr_t
14 __go_type_hash_string (const void *vkey,
15                        uintptr_t key_size __attribute__ ((unused)))
16 {
17   uintptr_t ret;
18   const String *key;
19   intgo len;
20   intgo i;
21   const byte *p;
22
23   ret = 5381;
24   key = (const String *) vkey;
25   len = key->len;
26   for (i = 0, p = key->str; i < len; i++, p++)
27     ret = ret * 33 + *p;
28   return ret;
29 }
30
31 /* A string equality function for a map.  */
32
33 _Bool
34 __go_type_equal_string (const void *vk1, const void *vk2,
35                         uintptr_t key_size __attribute__ ((unused)))
36 {
37   const String *k1;
38   const String *k2;
39
40   k1 = (const String *) vk1;
41   k2 = (const String *) vk2;
42   return __go_ptr_strings_equal (k1, k2);
43 }