go-type-string.c 974 B

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