diff options
author | Jakub Jelinek <jakub@redhat.com> | 2019-03-21 23:00:04 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2019-03-21 23:00:04 +0100 |
commit | 36a3a7a3726c8b65eeceb6eb4a8946e0cd5650a9 (patch) | |
tree | ce1f9656a446322fdb783d3909c677132ee5d92a /gcc/hash-set-tests.c | |
parent | 2e4182ae07e16f30b8917af3c0581a6c8af31357 (diff) | |
download | gcc-36a3a7a3726c8b65eeceb6eb4a8946e0cd5650a9.zip gcc-36a3a7a3726c8b65eeceb6eb4a8946e0cd5650a9.tar.gz gcc-36a3a7a3726c8b65eeceb6eb4a8946e0cd5650a9.tar.bz2 |
hash-table.h (hash_table): Add Lazy template parameter defaulted to false...
* hash-table.h (hash_table): Add Lazy template parameter defaulted
to false, if true, don't alloc_entries during construction, but defer
it to the first method that needs m_entries allocated.
(hash_table::hash_table, hash_table::~hash_table,
hash_table::alloc_entries, hash_table::find_empty_slot_for_expand,
hash_table::too_empty_p, hash_table::expand, hash_table::empty_slow,
hash_table::clear_slot, hash_table::traverse_noresize,
hash_table::traverse, hash_table::iterator::slide): Adjust all methods.
* hash-set.h (hash_set): Add Lazy template parameter defaulted to
false.
(hash_set::contains): If Lazy is true, use find_slot_with_hash with
NO_INSERT instead of find_with_hash.
(hash_set::traverse, hash_set::iterator, hash_set::iterator::m_iter,
hash_set::m_table): Add Lazy to template params of hash_table.
(gt_ggc_mx, gt_pch_nx): Use false as Lazy in hash_set template param.
* attribs.c (test_attribute_exclusions): Likewise.
* hash-set-tests.c (test_set_of_strings): Add iterator tests for
hash_set. Add tests for hash_set with Lazy = true.
c-family/
* c-common.c (per_file_includes_t): Use false as Lazy in hash_set
template param.
jit/
* jit-recording.c (reproducer::m_set_identifiers): Use false as Lazy
in hash_set template param.
From-SVN: r269859
Diffstat (limited to 'gcc/hash-set-tests.c')
-rw-r--r-- | gcc/hash-set-tests.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/gcc/hash-set-tests.c b/gcc/hash-set-tests.c index f75d41a..e0d1d47 100644 --- a/gcc/hash-set-tests.c +++ b/gcc/hash-set-tests.c @@ -44,6 +44,9 @@ test_set_of_strings () ASSERT_EQ (false, s.contains (red)); + for (hash_set<const char *>::iterator it = s.begin (); it != s.end (); ++it) + ASSERT_EQ (true, false); + /* Populate the hash_set. */ ASSERT_EQ (false, s.add (red)); ASSERT_EQ (false, s.add (green)); @@ -68,6 +71,67 @@ test_set_of_strings () ASSERT_EQ (true, s.contains (green)); ASSERT_EQ (true, s.contains (blue)); ASSERT_EQ (2, s.elements ()); + + int seen = 0; + for (hash_set<const char *>::iterator it = s.begin (); it != s.end (); ++it) + { + int n = *it == green; + if (n == 0) + ASSERT_EQ (*it, blue); + ASSERT_EQ (seen & (1 << n), 0); + seen |= 1 << n; + } + ASSERT_EQ (seen, 3); + + hash_set <const char *, true> t; + ASSERT_EQ (0, t.elements ()); + + ASSERT_EQ (false, t.contains (red)); + + for (hash_set<const char *, true>::iterator it = t.begin (); + it != t.end (); ++it) + ASSERT_EQ (true, false); + + /* Populate the hash_set. */ + ASSERT_EQ (false, t.add (red)); + ASSERT_EQ (false, t.add (green)); + ASSERT_EQ (false, t.add (blue)); + ASSERT_EQ (true, t.add (green)); + + /* Verify that the values are now within the set. */ + ASSERT_EQ (true, t.contains (red)); + ASSERT_EQ (true, t.contains (green)); + ASSERT_EQ (true, t.contains (blue)); + ASSERT_EQ (3, t.elements ()); + + seen = 0; + for (hash_set<const char *, true>::iterator it = t.begin (); + it != t.end (); ++it) + { + int n = 2; + if (*it == green) + n = 0; + else if (*it == blue) + n = 1; + else + ASSERT_EQ (*it, red); + ASSERT_EQ (seen & (1 << n), 0); + seen |= 1 << n; + } + ASSERT_EQ (seen, 7); + + /* Test removal. */ + t.remove (red); + ASSERT_EQ (false, t.contains (red)); + ASSERT_EQ (true, t.contains (green)); + ASSERT_EQ (true, t.contains (blue)); + ASSERT_EQ (2, t.elements ()); + + t.remove (red); + ASSERT_EQ (false, t.contains (red)); + ASSERT_EQ (true, t.contains (green)); + ASSERT_EQ (true, t.contains (blue)); + ASSERT_EQ (2, t.elements ()); } /* Run all of the selftests within this file. */ |