HH\Lib\Keyset\intersect

Meta Engineer?

This is available as Keyset\intersect in the www repository.

Returns a new keyset containing only the elements of the first Traversable that appear in all the other ones

namespace HH\Lib\Keyset;

function intersect<Tv as arraykey>(
  Traversable<Tv> $first,
  Traversable<Tv> $second,
  Container<Tv> ...$rest,
): keyset<Tv>;

Time complexity: O(n + m), where n is size of $first and m is the combined size of $second plus all the ...$rest Space complexity: O(n), where n is size of $first

Parameters

Returns

  • keyset<Tv>

Examples

$example_set1 = keyset[1,2,3,4,5];
$example_set2 = keyset[1,3];

$result = Keyset\intersect($example_set1, $example_set2);
print_r($result);
//result: keyset[1,3]

$example_vec3 = keyset[6,7];
$result = Keyset\intersect($example_set1, $example_vec3);
print_r($result);
//result: keyset[]