go-type-string.c 1.14 KB
Newer Older
1 2 3 4 5 6
/* go-type-string.c -- hash and equality string functions.

   Copyright 2009 The Go Authors. All rights reserved.
   Use of this source code is governed by a BSD-style
   license that can be found in the LICENSE file.  */

7
#include "runtime.h"
8
#include "go-type.h"
9
#include "go-string.h"
10 11 12

/* A string hash function for a map.  */

13
uintptr_t
14
__go_type_hash_string (const void *vkey, uintptr_t seed,
15
		       uintptr_t key_size __attribute__ ((unused)))
16
{
17
  uintptr_t ret;
18 19 20 21
  const String *key;
  intgo len;
  intgo i;
  const byte *p;
22

23
  ret = seed;
24 25 26
  key = (const String *) vkey;
  len = key->len;
  for (i = 0, p = key->str; i < len; i++, p++)
27 28 29 30
    ret = ret * 33 + *p;
  return ret;
}

31 32 33
const FuncVal __go_type_hash_string_descriptor =
  { (void *) __go_type_hash_string };

34 35 36 37
/* A string equality function for a map.  */

_Bool
__go_type_equal_string (const void *vk1, const void *vk2,
38
			uintptr_t key_size __attribute__ ((unused)))
39
{
40 41
  const String *k1;
  const String *k2;
42

43 44 45
  k1 = (const String *) vk1;
  k2 = (const String *) vk2;
  return __go_ptr_strings_equal (k1, k2);
46
}
47 48 49

const FuncVal __go_type_equal_string_descriptor =
  { (void *) __go_type_equal_string };