1 /* go-map-delete.c -- delete an entry from a map.
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. */
13 #include "go-assert.h"
16 /* Delete the entry matching KEY from MAP. */
19 __go_map_delete (struct __go_map
*map
, const void *key
)
21 const struct __go_map_descriptor
*descriptor
;
22 const struct __go_type_descriptor
*key_descriptor
;
24 _Bool (*equalfn
) (const void*, const void*, uintptr_t);
33 descriptor
= map
->__descriptor
;
35 key_descriptor
= descriptor
->__map_descriptor
->__key_type
;
36 key_offset
= descriptor
->__key_offset
;
37 key_size
= key_descriptor
->__size
;
38 __go_assert (key_size
!= 0 && key_size
!= -1UL);
39 equalfn
= key_descriptor
->__equalfn
;
41 key_hash
= key_descriptor
->__hashfn (key
, key_size
);
42 bucket_index
= key_hash
% map
->__bucket_count
;
44 pentry
= map
->__buckets
+ bucket_index
;
45 while (*pentry
!= NULL
)
47 char *entry
= (char *) *pentry
;
48 if (equalfn (key
, entry
+ key_offset
, key_size
))
50 *pentry
= *(void **) entry
;
51 if (descriptor
->__entry_size
>= TinySize
)
53 map
->__element_count
-= 1;
56 pentry
= (void **) entry
;