The unsorted union of a list is a list containing the same elements as
but with the second and subsequent occurrence of any given
element removed. For example, the unsorted union of the set
is
. The unsorted union differs from the usual union
in that the elements of the
unsorted union are not necessarily ordered.
The unsorted union is implemented in the Wolfram Language as DeleteDuplicates[list].
It can be implemented in the Wolfram Language top-level code as:
UnsortedUnion1[x_] := Tally[x][[All, 1]]
or
UnsortedUnion2[x_] := Reap[Sow[1, x], _, #1&][[2]]
or
UnsortedUnion3[x_] := Module[{f}, f[y_] := (f[y] = Sequence[]; y); f /@ x ]
Depending on the nature of the list to be unioned, different implementations above may be more efficient, although in general, the first is the fastest.