Skip to content

Commit cad6058

Browse files
Abseil Teamcopybara-github
authored andcommitted
Clarify the post-condition of reserve() in Abseil hash containers.
The comments for `reserve()` in `flat_hash_map`, `flat_hash_set`, `node_hash_map`, and `node_hash_set` are updated to explicitly state that after calling `reserve(count)`, at least `count - size()` additional elements can be inserted without triggering a rehash. PiperOrigin-RevId: 818932349 Change-Id: I76b014eace2367ca7aac8f5ba5cf6e5d9cbc50f1
1 parent f2678d2 commit cad6058

File tree

4 files changed

+4
-12
lines changed

4 files changed

+4
-12
lines changed

absl/container/flat_hash_map.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,7 @@ class ABSL_ATTRIBUTE_OWNER flat_hash_map
462462
//
463463
// Sets the number of slots in the `flat_hash_map` to the number needed to
464464
// accommodate at least `count` total elements without exceeding the current
465-
// maximum load factor, and may rehash the container if needed. After this
466-
// returns, it is guaranteed that `count - size()` elements can be inserted
467-
// into the `flat_hash_map` without another rehash.
465+
// maximum load factor, and may rehash the container if needed.
468466
using Base::reserve;
469467

470468
// flat_hash_map::at()

absl/container/flat_hash_set.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,7 @@ class ABSL_ATTRIBUTE_OWNER flat_hash_set
396396
//
397397
// Sets the number of slots in the `flat_hash_set` to the number needed to
398398
// accommodate at least `count` total elements without exceeding the current
399-
// maximum load factor, and may rehash the container if needed. After this
400-
// returns, it is guaranteed that `count - size()` elements can be inserted
401-
// into the `flat_hash_set` without another rehash.
399+
// maximum load factor, and may rehash the container if needed.
402400
using Base::reserve;
403401

404402
// flat_hash_set::contains()

absl/container/node_hash_map.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,7 @@ class ABSL_ATTRIBUTE_OWNER node_hash_map
455455
//
456456
// Sets the number of slots in the `node_hash_map` to the number needed to
457457
// accommodate at least `count` total elements without exceeding the current
458-
// maximum load factor, and may rehash the container if needed. After this
459-
// returns, it is guaranteed that `count - size()` elements can be inserted
460-
// into the `node_hash_map` without another rehash.
458+
// maximum load factor, and may rehash the container if needed.
461459
using Base::reserve;
462460

463461
// node_hash_map::at()

absl/container/node_hash_set.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,7 @@ class ABSL_ATTRIBUTE_OWNER node_hash_set
390390
//
391391
// Sets the number of slots in the `node_hash_set` to the number needed to
392392
// accommodate at least `count` total elements without exceeding the current
393-
// maximum load factor, and may rehash the container if needed. After this
394-
// returns, it is guaranteed that `count - size()` elements can be inserted
395-
// into the `node_hash_set` without another rehash.
393+
// maximum load factor, and may rehash the container if needed.
396394
using Base::reserve;
397395

398396
// node_hash_set::contains()

0 commit comments

Comments
 (0)