go-map-len.c 660 B

1234567891011121314151617181920212223242526
  1. /* go-map-len.c -- return the length of a map.
  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 <stddef.h>
  6. #include "runtime.h"
  7. #include "go-assert.h"
  8. #include "map.h"
  9. /* Return the length of a map. This could be done inline, of course,
  10. but I'm doing it as a function for now to make it easy to change
  11. the map structure. */
  12. intgo
  13. __go_map_len (struct __go_map *map)
  14. {
  15. if (map == NULL)
  16. return 0;
  17. __go_assert (map->__element_count
  18. == (uintptr_t) (intgo) map->__element_count);
  19. return map->__element_count;
  20. }