HH\Set::reserve

Reserves enough memory to accommodate a given number of elements.

Description

public function reserve(
  int $sz,
): void

Reserves enough memory to accommodate a given number of elements.

Reserves enough memory for sz elements. If sz is less than or equal to the current capacity of this Set, this method does nothing.

Parameters

  • int $sz - The pre-determined size you want for the current Set.

Examples

This example reserves space for 1000 elements and then fills the Set with 1000 integers:

<?hh

namespace Hack\UserDocumentation\API\Examples\Set\Reserve;

const int SET_SIZE = 1000;

$s = Set {};
$s->reserve(SET_SIZE);

for ($i = 0; $i < SET_SIZE; $i++) {
  $s[] = $i * 10;
}

var_dump($s);