Commit 62de703f by Jason Merrill Committed by Jakub Jelinek

hash-table.h (remove_elt_with_hash): Return if slot is NULL rather than if is_empty (*slot).

	* hash-table.h (remove_elt_with_hash): Return if slot is NULL rather
	than if is_empty (*slot).
	* hash-set-tests.c (test_set_of_strings): Add tests for addition of
	existing elt and for elt removal.
	* hash-map-tests.c (test_map_of_strings_to_int): Add test for removal
	of already removed elt.

	* hashtab.c (htab_remove_elt_with_hash): Return if slot is NULL rather
	than if *slot is HTAB_EMPTY_ENTRY.

Co-Authored-By: Jakub Jelinek <jakub@redhat.com>

From-SVN: r269695
parent 12fb7712
2019-03-14 Jason Merrill <jason@redhat.com>
Jakub Jelinek <jakub@redhat.com>
* hash-table.h (remove_elt_with_hash): Return if slot is NULL rather
than if is_empty (*slot).
* hash-set-tests.c (test_set_of_strings): Add tests for addition of
existing elt and for elt removal.
* hash-map-tests.c (test_map_of_strings_to_int): Add test for removal
of already removed elt.
2019-03-15 H.J. Lu <hongjiu.lu@intel.com> 2019-03-15 H.J. Lu <hongjiu.lu@intel.com>
PR target/89650 PR target/89650
......
...@@ -78,6 +78,10 @@ test_map_of_strings_to_int () ...@@ -78,6 +78,10 @@ test_map_of_strings_to_int ()
ASSERT_EQ (5, m.elements ()); ASSERT_EQ (5, m.elements ());
ASSERT_EQ (NULL, m.get (eric)); ASSERT_EQ (NULL, m.get (eric));
m.remove (eric);
ASSERT_EQ (5, m.elements ());
ASSERT_EQ (NULL, m.get (eric));
/* A plain char * key is hashed based on its value (address), rather /* A plain char * key is hashed based on its value (address), rather
than the string it points to. */ than the string it points to. */
char *another_ant = static_cast <char *> (xcalloc (4, 1)); char *another_ant = static_cast <char *> (xcalloc (4, 1));
......
...@@ -48,11 +48,26 @@ test_set_of_strings () ...@@ -48,11 +48,26 @@ test_set_of_strings ()
ASSERT_EQ (false, s.add (red)); ASSERT_EQ (false, s.add (red));
ASSERT_EQ (false, s.add (green)); ASSERT_EQ (false, s.add (green));
ASSERT_EQ (false, s.add (blue)); ASSERT_EQ (false, s.add (blue));
ASSERT_EQ (true, s.add (green));
/* Verify that the values are now within the set. */ /* Verify that the values are now within the set. */
ASSERT_EQ (true, s.contains (red)); ASSERT_EQ (true, s.contains (red));
ASSERT_EQ (true, s.contains (green)); ASSERT_EQ (true, s.contains (green));
ASSERT_EQ (true, s.contains (blue)); ASSERT_EQ (true, s.contains (blue));
ASSERT_EQ (3, s.elements ());
/* Test removal. */
s.remove (red);
ASSERT_EQ (false, s.contains (red));
ASSERT_EQ (true, s.contains (green));
ASSERT_EQ (true, s.contains (blue));
ASSERT_EQ (2, s.elements ());
s.remove (red);
ASSERT_EQ (false, s.contains (red));
ASSERT_EQ (true, s.contains (green));
ASSERT_EQ (true, s.contains (blue));
ASSERT_EQ (2, s.elements ());
} }
/* Run all of the selftests within this file. */ /* Run all of the selftests within this file. */
......
...@@ -940,7 +940,7 @@ hash_table<Descriptor, Allocator> ...@@ -940,7 +940,7 @@ hash_table<Descriptor, Allocator>
::remove_elt_with_hash (const compare_type &comparable, hashval_t hash) ::remove_elt_with_hash (const compare_type &comparable, hashval_t hash)
{ {
value_type *slot = find_slot_with_hash (comparable, hash, NO_INSERT); value_type *slot = find_slot_with_hash (comparable, hash, NO_INSERT);
if (is_empty (*slot)) if (slot == NULL)
return; return;
Descriptor::remove (*slot); Descriptor::remove (*slot);
......
2019-03-14 Jason Merrill <jason@redhat.com>
Jakub Jelinek <jakub@redhat.com>
* hashtab.c (htab_remove_elt_with_hash): Return if slot is NULL rather
than if *slot is HTAB_EMPTY_ENTRY.
2019-02-11 Philippe Waroquiers <philippe.waroquiers@skynet.be> 2019-02-11 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* splay-tree.c (splay_tree_insert): Also release old KEY in case * splay-tree.c (splay_tree_insert): Also release old KEY in case
......
...@@ -725,7 +725,7 @@ htab_remove_elt_with_hash (htab_t htab, PTR element, hashval_t hash) ...@@ -725,7 +725,7 @@ htab_remove_elt_with_hash (htab_t htab, PTR element, hashval_t hash)
PTR *slot; PTR *slot;
slot = htab_find_slot_with_hash (htab, element, hash, NO_INSERT); slot = htab_find_slot_with_hash (htab, element, hash, NO_INSERT);
if (*slot == HTAB_EMPTY_ENTRY) if (slot == NULL)
return; return;
if (htab->del_f) if (htab->del_f)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment