Skip to content

Commit

Permalink
Merge pull request #133 from dlang-community/fix_hashset_remove
Browse files Browse the repository at this point in the history
Fix crash when attempting to remove en element from an empty set
merged-on-behalf-of: Brian Schott <[email protected]>
  • Loading branch information
dlang-bot authored Jan 25, 2019
2 parents 836a0cc + 57abb5a commit 22fe1e5
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/containers/hashset.d
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ struct HashSet(T, Allocator = Mallocator, alias hashFunction = generateHash!T,
*/
bool remove(T value)
{
if (buckets.length == 0)
return false;
immutable Hash hash = hashFunction(value);
immutable size_t index = hashToIndex(hash, buckets.length);
static if (storeHash)
Expand Down Expand Up @@ -594,6 +596,7 @@ version(emsi_containers_unittest) unittest
import std.uuid : randomUUID;

auto s = HashSet!string(16);
assert(s.remove("DoesNotExist") == false);
assert(!s.contains("nonsense"));
assert(s.put("test"));
assert(s.contains("test"));
Expand Down

0 comments on commit 22fe1e5

Please sign in to comment.