2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libgo / runtime / go-type-string.c
bloba96af0290b256e29963a1916e34b5c871728b891
1 /* go-type-string.c -- hash and equality string functions.
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. */
7 #include "runtime.h"
8 #include "go-type.h"
9 #include "go-string.h"
11 /* A string hash function for a map. */
13 uintptr_t
14 __go_type_hash_string (const void *vkey,
15 uintptr_t key_size __attribute__ ((unused)))
17 uintptr_t ret;
18 const String *key;
19 intgo len;
20 intgo i;
21 const byte *p;
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;
31 /* A string equality function for a map. */
33 _Bool
34 __go_type_equal_string (const void *vk1, const void *vk2,
35 uintptr_t key_size __attribute__ ((unused)))
37 const String *k1;
38 const String *k2;
40 k1 = (const String *) vk1;
41 k2 = (const String *) vk2;
42 return __go_ptr_strings_equal (k1, k2);