HH\Lib\Keyset\diff

Meta Engineer?

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

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

namespace HH\Lib\Keyset;

function diff<Tv1 as arraykey, Tv2 as arraykey>(
  Traversable<Tv1> $first,
  Traversable<Tv2> $second,
  Container<Tv2> ...$rest,
): keyset<Tv1>;

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 + m), where n is size of $first and m is the combined size of $second plus all the ...$rest -- note that this is bigger than O(n)

Parameters

Returns

  • keyset<Tv1>

Examples

$result = Keyset\diff(keyset[1,2,3,4,5,6], vec[1,2,3]);
print_r($result);
//result: keyset[4,5,6]

$result = Keyset\diff(vec[1,2,3,4,5,6], keyset[]);
print_r($result);
//result: keyset[1,2,3,4,5,6]