<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
set	B-Language
is	O
an	O
abstract	O
data	O
type	O
that	O
can	O
store	O
unique	O
values	O
,	O
without	O
any	O
particular	O
order	O
.	O
</s>
<s>
It	O
is	O
a	O
computer	O
implementation	O
of	O
the	O
mathematical	O
concept	O
of	O
a	O
finite	O
set	B-Language
.	O
</s>
<s>
Unlike	O
most	O
other	O
collection	B-Application
types	O
,	O
rather	O
than	O
retrieving	O
a	O
specific	O
element	O
from	O
a	O
set	B-Language
,	O
one	O
typically	O
tests	O
a	O
value	O
for	O
membership	O
in	O
a	O
set	B-Language
.	O
</s>
<s>
Some	O
set	B-Language
data	B-General_Concept
structures	I-General_Concept
are	O
designed	O
for	O
static	O
or	O
frozen	O
sets	O
that	O
do	O
not	O
change	O
after	O
they	O
are	O
constructed	O
.	O
</s>
<s>
Static	O
sets	O
allow	O
only	O
query	O
operations	O
on	O
their	O
elements	O
—	O
such	O
as	O
checking	O
whether	O
a	O
given	O
value	O
is	O
in	O
the	O
set	B-Language
,	O
or	O
enumerating	O
the	O
values	O
in	O
some	O
arbitrary	O
order	O
.	O
</s>
<s>
Other	O
variants	O
,	O
called	O
dynamic	O
or	O
mutable	O
sets	O
,	O
allow	O
also	O
the	O
insertion	O
and	O
deletion	O
of	O
elements	O
from	O
the	O
set	B-Language
.	O
</s>
<s>
A	O
multiset	B-Language
is	O
a	O
special	O
kind	O
of	O
set	B-Language
in	O
which	O
an	O
element	O
can	O
appear	O
multiple	O
times	O
in	O
the	O
set	B-Language
.	O
</s>
<s>
In	O
type	O
theory	O
,	O
sets	O
are	O
generally	O
identified	O
with	O
their	O
indicator	O
function	O
(	O
characteristic	O
function	O
)	O
:	O
accordingly	O
,	O
a	O
set	B-Language
of	O
values	O
of	O
type	O
may	O
be	O
denoted	O
by	O
or	O
.	O
</s>
<s>
The	O
characteristic	O
function	O
of	O
a	O
set	B-Language
is	O
defined	O
as	O
:	O
</s>
<s>
In	O
theory	O
,	O
many	O
other	O
abstract	O
data	B-General_Concept
structures	I-General_Concept
can	O
be	O
viewed	O
as	O
set	B-Language
structures	O
with	O
additional	O
operations	O
and/or	O
additional	O
axioms	B-Algorithm
imposed	O
on	O
the	O
standard	O
operations	O
.	O
</s>
<s>
For	O
example	O
,	O
an	O
abstract	O
heap	B-Application
can	O
be	O
viewed	O
as	O
a	O
set	B-Language
structure	O
with	O
a	O
min(S )	O
operation	O
that	O
returns	O
the	O
element	O
of	O
smallest	O
value	O
.	O
</s>
<s>
subset(S,T )	O
:	O
a	O
predicate	B-Algorithm
that	O
tests	O
whether	O
the	O
set	B-Language
S	O
is	O
a	O
subset	O
of	O
set	B-Language
T	O
.	O
</s>
<s>
Typical	O
operations	O
that	O
may	O
be	O
provided	O
by	O
a	O
static	O
set	B-Language
structure	O
S	O
are	O
:	O
</s>
<s>
is_element_of(x,S )	O
:	O
checks	O
whether	O
the	O
value	O
x	O
is	O
in	O
the	O
set	B-Language
S	O
.	O
</s>
<s>
is_empty(S )	O
:	O
checks	O
whether	O
the	O
set	B-Language
S	O
is	O
empty	O
.	O
</s>
<s>
size(S )	O
or	O
cardinality(S )	O
:	O
returns	O
the	O
number	O
of	O
elements	O
in	O
S	O
.	O
</s>
<s>
build( x1	O
,	O
x2	O
,…,	O
xn	O
,	O
)	O
:	O
creates	O
a	O
set	B-Language
structure	O
with	O
values	O
x1	O
,	O
x2	O
,...,	O
xn	O
.	O
</s>
<s>
create_from(collection )	O
:	O
creates	O
a	O
new	O
set	B-Language
structure	O
containing	O
all	O
the	O
elements	O
of	O
the	O
given	O
collection	B-Application
or	O
all	O
the	O
elements	O
returned	O
by	O
the	O
given	O
iterator	O
.	O
</s>
<s>
Dynamic	O
set	B-Language
structures	O
typically	O
add	O
:	O
</s>
<s>
create( )	O
:	O
creates	O
a	O
new	O
,	O
initially	O
empty	O
set	B-Language
structure	O
.	O
</s>
<s>
create_with_capacity(n )	O
:	O
creates	O
a	O
new	O
set	B-Language
structure	O
,	O
initially	O
empty	O
but	O
capable	O
of	O
holding	O
up	O
to	O
n	O
elements	O
.	O
</s>
<s>
Some	O
set	B-Language
structures	O
may	O
allow	O
only	O
some	O
of	O
these	O
operations	O
.	O
</s>
<s>
The	O
cost	O
of	O
each	O
operation	O
will	O
depend	O
on	O
the	O
implementation	O
,	O
and	O
possibly	O
also	O
on	O
the	O
particular	O
values	O
stored	O
in	O
the	O
set	B-Language
,	O
and	O
the	O
order	O
in	O
which	O
they	O
are	O
inserted	O
.	O
</s>
<s>
pick(S )	O
:	O
returns	O
an	O
arbitrary	O
element	O
of	O
S	O
.	O
Functionally	O
,	O
the	O
mutator	O
pop	O
can	O
be	O
interpreted	O
as	O
the	O
pair	O
of	O
selectors	O
(	O
pick	O
,	O
rest	O
)	O
,	O
where	O
rest	O
returns	O
the	O
set	B-Language
consisting	O
of	O
all	O
elements	O
except	O
for	O
the	O
arbitrary	O
element	O
.	O
</s>
<s>
map(F,S )	O
:	O
returns	O
the	O
set	B-Language
of	O
distinct	O
values	O
resulting	O
from	O
applying	O
function	O
F	O
to	O
each	O
element	O
of	O
S	O
.	O
</s>
<s>
filter(P,S )	O
:	O
returns	O
the	O
subset	O
containing	O
all	O
elements	O
of	O
S	O
that	O
satisfy	O
a	O
given	O
predicate	B-Algorithm
P	O
.	O
</s>
<s>
fold(A0,F,S )	O
:	O
returns	O
the	O
value	O
A|S|	O
after	O
applying	O
Ai+1	O
:=	O
F(Ai, e )	O
for	O
each	O
element	O
e	O
of	O
S	O
,	O
for	O
some	O
binary	O
operation	O
F	O
.	O
F	O
must	O
be	O
associative	O
and	O
commutative	O
for	O
this	O
to	O
be	O
well-defined	O
.	O
</s>
<s>
For	O
example	O
,	O
over	O
integers	O
or	O
reals	O
,	O
it	O
may	O
be	O
defined	O
as	O
fold(0, add, S )	O
.	O
</s>
<s>
collapse(S )	O
:	O
given	O
a	O
set	B-Language
of	O
sets	O
,	O
return	O
the	O
union	O
.	O
</s>
<s>
flatten(S )	O
:	O
given	O
a	O
set	B-Language
consisting	O
of	O
sets	O
and	O
atomic	O
elements	O
(	O
elements	O
that	O
are	O
not	O
sets	O
)	O
,	O
returns	O
a	O
set	B-Language
whose	O
elements	O
are	O
the	O
atomic	O
elements	O
of	O
the	O
original	O
top-level	O
set	B-Language
or	O
elements	O
of	O
the	O
sets	O
it	O
contains	O
.	O
</s>
<s>
This	O
can	O
be	O
done	O
a	O
single	O
time	O
,	O
or	O
recursively	O
flattening	O
to	O
obtain	O
a	O
set	B-Language
of	O
only	O
atomic	O
elements	O
.	O
</s>
<s>
Sets	O
can	O
be	O
implemented	O
using	O
various	O
data	B-General_Concept
structures	I-General_Concept
,	O
which	O
provide	O
different	O
time	O
and	O
space	O
trade-offs	O
for	O
various	O
operations	O
.	O
</s>
<s>
This	O
is	O
simple	O
but	O
inefficient	O
,	O
as	O
operations	O
like	O
set	B-Language
membership	O
or	O
element	O
deletion	O
are	O
O(n )	O
,	O
as	O
they	O
require	O
scanning	O
the	O
entire	O
list	O
.	O
</s>
<s>
Sets	O
are	O
often	O
instead	O
implemented	O
using	O
more	O
efficient	O
data	B-General_Concept
structures	I-General_Concept
,	O
particularly	O
various	O
flavors	O
of	O
trees	B-Application
,	O
tries	B-General_Concept
,	O
or	O
hash	B-Algorithm
tables	I-Algorithm
.	O
</s>
<s>
As	O
sets	O
can	O
be	O
interpreted	O
as	O
a	O
kind	O
of	O
map	O
(	O
by	O
the	O
indicator	O
function	O
)	O
,	O
sets	O
are	O
commonly	O
implemented	O
in	O
the	O
same	O
way	O
as	O
(	O
partial	O
)	O
maps	O
(	O
associative	B-Application
arrays	I-Application
)	O
–	O
in	O
this	O
case	O
in	O
which	O
the	O
value	O
of	O
each	O
key-value	O
pair	O
has	O
the	O
unit	O
type	O
or	O
a	O
sentinel	O
value	O
(	O
like	O
1	O
)	O
–	O
namely	O
,	O
a	O
self-balancing	B-Data_Structure
binary	I-Data_Structure
search	I-Data_Structure
tree	I-Data_Structure
for	O
sorted	O
sets	O
(	O
which	O
has	O
O(log n )	O
for	O
most	O
operations	O
)	O
,	O
or	O
a	O
hash	B-Algorithm
table	I-Algorithm
for	O
unsorted	O
sets	O
(	O
which	O
has	O
O(1 )	O
average-case	O
,	O
but	O
O(n )	O
worst-case	O
,	O
for	O
most	O
operations	O
)	O
.	O
</s>
<s>
A	O
sorted	O
linear	O
hash	B-Algorithm
table	I-Algorithm
may	O
be	O
used	O
to	O
provide	O
deterministically	O
ordered	O
sets	O
.	O
</s>
<s>
For	O
example	O
,	O
a	O
common	O
programming	O
idiom	O
in	O
Perl	B-Language
that	O
converts	O
an	O
array	O
to	O
a	O
hash	B-Error_Name
whose	O
values	O
are	O
the	O
sentinel	O
value	O
1	O
,	O
for	O
use	O
as	O
a	O
set	B-Language
,	O
is	O
:	O
</s>
<s>
Other	O
popular	O
methods	O
include	O
arrays	B-Data_Structure
.	O
</s>
<s>
In	O
particular	O
a	O
subset	O
of	O
the	O
integers	O
1	O
..	O
n	O
can	O
be	O
implemented	O
efficiently	O
as	O
an	O
n-bit	O
bit	B-Data_Structure
array	I-Data_Structure
,	O
which	O
also	O
support	O
very	O
efficient	O
union	O
and	O
intersection	O
operations	O
.	O
</s>
<s>
A	O
Bloom	B-Algorithm
map	I-Algorithm
implements	O
a	O
set	B-Language
probabilistically	O
,	O
using	O
a	O
very	O
compact	O
representation	O
but	O
risking	O
a	O
small	O
chance	O
of	O
false	O
positives	O
on	O
queries	O
.	O
</s>
<s>
The	O
Boolean	O
set	B-Language
operations	O
can	O
be	O
implemented	O
in	O
terms	O
of	O
more	O
elementary	O
operations	O
(	O
pop	O
,	O
clear	O
,	O
and	O
add	O
)	O
,	O
but	O
specialized	O
algorithms	O
may	O
yield	O
lower	O
asymptotic	O
time	O
bounds	O
.	O
</s>
<s>
If	O
sets	O
are	O
implemented	O
as	O
sorted	O
lists	O
,	O
for	O
example	O
,	O
the	O
naive	O
algorithm	O
for	O
union(S,T )	O
will	O
take	O
time	O
proportional	O
to	O
the	O
length	O
m	O
of	O
S	O
times	O
the	O
length	O
n	O
of	O
T	O
;	O
whereas	O
a	O
variant	O
of	O
the	O
list	B-Algorithm
merging	I-Algorithm
algorithm	I-Algorithm
will	O
do	O
the	O
job	O
in	O
time	O
proportional	O
to	O
m+n	O
.	O
</s>
<s>
Moreover	O
,	O
there	O
are	O
specialized	O
set	B-Language
data	B-General_Concept
structures	I-General_Concept
(	O
such	O
as	O
the	O
union-find	B-Algorithm
data	I-Algorithm
structure	I-Algorithm
)	O
that	O
are	O
optimized	O
for	O
one	O
or	O
more	O
of	O
these	O
operations	O
,	O
at	O
the	O
expense	O
of	O
others	O
.	O
</s>
<s>
One	O
of	O
the	O
earliest	O
languages	O
to	O
support	O
sets	O
was	O
Pascal	B-Application
;	O
many	O
languages	O
now	O
include	O
it	O
,	O
whether	O
in	O
the	O
core	O
language	O
or	O
in	O
a	O
standard	B-Library
library	I-Library
.	O
</s>
<s>
In	O
C++	B-Language
,	O
the	O
Standard	B-Application
Template	I-Application
Library	I-Application
(	O
STL	O
)	O
provides	O
the	O
set	B-Language
template	O
class	O
,	O
which	O
is	O
typically	O
implemented	O
using	O
a	O
binary	O
search	O
tree	O
(	O
e.g.	O
</s>
<s>
red	O
–	O
black	O
tree	O
)	O
;	O
SGI	O
's	O
STL	O
also	O
provides	O
the	O
hash_set	O
template	O
class	O
,	O
which	O
implements	O
a	O
set	B-Language
using	O
a	O
hash	B-Algorithm
table	I-Algorithm
.	O
</s>
<s>
C++11	B-Language
has	O
support	O
for	O
the	O
unordered_set	O
template	O
class	O
,	O
which	O
is	O
implemented	O
using	O
a	O
hash	B-Algorithm
table	I-Algorithm
.	O
</s>
<s>
In	O
sets	O
,	O
the	O
elements	O
themselves	O
are	O
the	O
keys	O
,	O
in	O
contrast	O
to	O
sequenced	O
containers	B-Application
,	O
where	O
elements	O
are	O
accessed	O
using	O
their	O
(	O
relative	O
or	O
absolute	O
)	O
position	O
.	O
</s>
<s>
Set	B-Language
elements	O
must	O
have	O
a	O
strict	O
weak	O
ordering	O
.	O
</s>
<s>
The	O
Rust	B-Application
(	O
programming	O
language	O
)	O
standard	B-Library
library	I-Library
provides	O
the	O
generic	O
HashSet	O
and	O
BTreeSet	O
types	O
.	O
</s>
<s>
Java	B-Language
offers	O
the	O
interface	B-Application
to	O
support	O
sets	O
(	O
with	O
the	O
class	O
implementing	O
it	O
using	O
a	O
hash	B-Algorithm
table	I-Algorithm
)	O
,	O
and	O
the	O
sub-interface	O
to	O
support	O
sorted	O
sets	O
(	O
with	O
the	O
class	O
implementing	O
it	O
using	O
a	O
binary	O
search	O
tree	O
)	O
.	O
</s>
<s>
Apple	O
's	O
Foundation	B-Operating_System
framework	I-Operating_System
(	O
part	O
of	O
Cocoa	B-Operating_System
)	O
provides	O
the	O
Objective-C	B-Language
classes	O
NSSet	O
,	O
NSMutableSet	O
,	O
NSCountedSet	O
,	O
NSOrderedSet	O
,	O
and	O
NSMutableOrderedSet	O
.	O
</s>
<s>
The	O
CoreFoundation	B-Operating_System
APIs	O
provide	O
the	O
and	O
types	O
for	O
use	O
in	O
C	B-Language
.	O
</s>
<s>
Python	B-Language
has	O
built-in	O
since	O
2.4	O
,	O
and	O
since	O
Python	B-Language
3.0	O
and	O
2.7	O
,	O
supports	O
non-empty	O
set	B-Language
literals	O
using	O
a	O
curly-bracket	O
syntax	O
,	O
e.g.	O
</s>
<s>
:	O
{	O
x	O
,	O
y	O
,	O
z}	O
;	O
empty	O
sets	O
must	O
be	O
created	O
using	O
set( )	O
,	O
because	O
Python	B-Language
uses	O
 {  } 	O
to	O
represent	O
the	O
empty	O
dictionary	B-Application
.	O
</s>
<s>
The	O
.NET	B-Application
Framework	I-Application
provides	O
the	O
generic	O
HashSet	O
and	O
SortedSet	O
classes	O
that	O
implement	O
the	O
generic	O
ISet	O
interface	B-Application
.	O
</s>
<s>
Smalltalk	B-Application
's	O
class	O
library	O
includes	O
Set	B-Language
and	O
IdentitySet	O
,	O
using	O
equality	O
and	O
identity	O
for	O
inclusion	O
test	O
respectively	O
.	O
</s>
<s>
or	O
for	O
weak	B-General_Concept
references	I-General_Concept
(	O
WeakIdentitySet	O
)	O
.	O
</s>
<s>
Ruby	B-Language
's	O
standard	B-Library
library	I-Library
includes	O
a	O
set	B-Language
module	O
which	O
contains	O
Set	B-Language
and	O
SortedSet	O
classes	O
that	O
implement	O
sets	O
using	O
hash	B-Algorithm
tables	I-Algorithm
,	O
the	O
latter	O
allowing	O
iteration	O
in	O
sorted	O
order	O
.	O
</s>
<s>
OCaml	B-Language
's	O
standard	B-Library
library	I-Library
contains	O
a	O
Set	B-Language
module	O
,	O
which	O
implements	O
a	O
functional	O
set	B-Language
data	B-General_Concept
structure	I-General_Concept
using	O
binary	O
search	O
trees	B-Application
.	O
</s>
<s>
The	O
GHC	B-Application
implementation	O
of	O
Haskell	B-Language
provides	O
a	O
Data.Set	O
module	O
,	O
which	O
implements	O
immutable	O
sets	O
using	O
binary	O
search	O
trees	B-Application
.	O
</s>
<s>
The	O
Tcl	B-Operating_System
Tcllib	O
package	O
provides	O
a	O
set	B-Language
module	O
which	O
implements	O
a	O
set	B-Language
data	B-General_Concept
structure	I-General_Concept
based	O
upon	O
TCL	B-Operating_System
lists	O
.	O
</s>
<s>
The	O
Swift	B-Application
standard	B-Library
library	I-Library
contains	O
a	O
Set	B-Language
type	O
,	O
since	O
Swift	B-Application
1.2	O
.	O
</s>
<s>
JavaScript	B-Language
introduced	O
Set	B-Language
as	O
a	O
standard	O
built-in	O
object	O
with	O
the	O
ECMAScript	O
2015	O
standard	O
.	O
</s>
<s>
Erlang	B-Operating_System
's	O
standard	B-Library
library	I-Library
has	O
a	O
sets	O
module	O
.	O
</s>
<s>
Clojure	B-Language
has	O
literal	O
syntax	O
for	O
hashed	O
sets	O
,	O
and	O
also	O
implements	O
sorted	O
sets	O
.	O
</s>
<s>
LabVIEW	B-Application
has	O
native	O
support	O
for	O
sets	O
,	O
from	O
version	O
2019	O
.	O
</s>
<s>
Ada	B-Language
provides	O
the	O
Ada.Containers.Hashed_Sets	O
and	O
Ada.Containers.Ordered_Sets	O
packages	O
.	O
</s>
<s>
As	O
noted	O
in	O
the	O
previous	O
section	O
,	O
in	O
languages	O
which	O
do	O
not	O
directly	O
support	O
sets	O
but	O
do	O
support	O
associative	B-Application
arrays	I-Application
,	O
sets	O
can	O
be	O
emulated	O
using	O
associative	B-Application
arrays	I-Application
,	O
by	O
using	O
the	O
elements	O
as	O
keys	O
,	O
and	O
using	O
a	O
dummy	O
value	O
as	O
the	O
values	O
,	O
which	O
are	O
ignored	O
.	O
</s>
<s>
A	O
generalization	O
of	O
the	O
notion	O
of	O
a	O
set	B-Language
is	O
that	O
of	O
a	O
multiset	B-Language
or	O
bag	O
,	O
which	O
is	O
similar	O
to	O
a	O
set	B-Language
but	O
allows	O
repeated	O
(	O
"	O
equal	O
"	O
)	O
values	O
(	O
duplicates	O
)	O
.	O
</s>
<s>
For	O
example	O
,	O
given	O
a	O
list	O
of	O
people	O
(	O
by	O
name	O
)	O
and	O
ages	O
(	O
in	O
years	O
)	O
,	O
one	O
could	O
construct	O
a	O
multiset	B-Language
of	O
ages	O
,	O
which	O
simply	O
counts	O
the	O
number	O
of	O
people	O
of	O
a	O
given	O
age	O
.	O
</s>
<s>
Alternatively	O
,	O
one	O
can	O
construct	O
a	O
multiset	B-Language
of	O
people	O
,	O
where	O
two	O
people	O
are	O
considered	O
equivalent	O
if	O
their	O
ages	O
are	O
the	O
same	O
(	O
but	O
may	O
be	O
different	O
people	O
and	O
have	O
different	O
names	O
)	O
,	O
in	O
which	O
case	O
each	O
pair	O
(	O
name	O
,	O
age	O
)	O
must	O
be	O
stored	O
,	O
and	O
selecting	O
on	O
a	O
given	O
age	O
gives	O
all	O
the	O
people	O
of	O
a	O
given	O
age	O
.	O
</s>
<s>
Formally	O
,	O
it	O
is	O
possible	O
for	O
objects	O
in	O
computer	B-General_Concept
science	I-General_Concept
to	O
be	O
considered	O
"	O
equal	O
"	O
under	O
some	O
equivalence	O
relation	O
but	O
still	O
distinct	O
under	O
another	O
relation	O
.	O
</s>
<s>
Some	O
types	O
of	O
multiset	B-Language
implementations	O
will	O
store	O
distinct	O
equal	O
objects	O
as	O
separate	O
items	O
in	O
the	O
data	B-General_Concept
structure	I-General_Concept
;	O
while	O
others	O
will	O
collapse	O
it	O
down	O
to	O
one	O
version	O
(	O
the	O
first	O
one	O
encountered	O
)	O
and	O
keep	O
a	O
positive	O
integer	O
count	O
of	O
the	O
multiplicity	O
of	O
the	O
element	O
.	O
</s>
<s>
As	O
with	O
sets	O
,	O
multisets	B-Language
can	O
naturally	O
be	O
implemented	O
using	O
hash	B-Algorithm
table	I-Algorithm
or	O
trees	B-Application
,	O
which	O
yield	O
different	O
performance	O
characteristics	O
.	O
</s>
<s>
The	O
set	B-Language
of	O
all	O
bags	O
over	O
type	O
T	O
is	O
given	O
by	O
the	O
expression	O
bag	O
T	O
.	O
If	O
by	O
multiset	B-Language
one	O
considers	O
equal	O
items	O
identical	O
and	O
simply	O
counts	O
them	O
,	O
then	O
a	O
multiset	B-Language
can	O
be	O
interpreted	O
as	O
a	O
function	O
from	O
the	O
input	O
domain	O
to	O
the	O
non-negative	O
integers	O
(	O
natural	O
numbers	O
)	O
,	O
generalizing	O
the	O
identification	O
of	O
a	O
set	B-Language
with	O
its	O
indicator	O
function	O
.	O
</s>
<s>
In	O
some	O
cases	O
a	O
multiset	B-Language
in	O
this	O
counting	O
sense	O
may	O
be	O
generalized	O
to	O
allow	O
negative	O
values	O
,	O
as	O
in	O
Python	B-Language
.	O
</s>
<s>
C++'s	O
Standard	B-Application
Template	I-Application
Library	I-Application
implements	O
both	O
sorted	O
and	O
unsorted	O
multisets	B-Language
.	O
</s>
<s>
It	O
provides	O
the	O
multiset	B-Language
class	O
for	O
the	O
sorted	O
multiset	B-Language
,	O
as	O
a	O
kind	O
of	O
associative	B-Application
container	I-Application
,	O
which	O
implements	O
this	O
multiset	B-Language
using	O
a	O
self-balancing	B-Data_Structure
binary	I-Data_Structure
search	I-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
It	O
provides	O
the	O
unordered_multiset	O
class	O
for	O
the	O
unsorted	O
multiset	B-Language
,	O
as	O
a	O
kind	O
of	O
unordered	B-Language
associative	I-Language
container	I-Language
,	O
which	O
implements	O
this	O
multiset	B-Language
using	O
a	O
hash	B-Algorithm
table	I-Algorithm
.	O
</s>
<s>
The	O
unsorted	O
multiset	B-Language
is	O
standard	O
as	O
of	O
C++11	B-Language
;	O
previously	O
SGI	O
's	O
STL	O
provides	O
the	O
hash_multiset	O
class	O
,	O
which	O
was	O
copied	O
and	O
eventually	O
standardized	O
.	O
</s>
<s>
For	O
Java	B-Language
,	O
third-party	O
libraries	O
provide	O
multiset	B-Language
functionality	O
:	O
</s>
<s>
Apache	B-Language
Commons	I-Language
Collections	O
provides	O
the	O
Bag	O
and	O
SortedBag	O
interfaces	B-Application
,	O
with	O
implementing	O
classes	O
like	O
HashBag	O
and	O
TreeBag	O
.	O
</s>
<s>
Google	B-Language
Guava	I-Language
provides	O
the	O
Multiset	B-Language
interface	B-Application
,	O
with	O
implementing	O
classes	O
like	O
HashMultiset	O
and	O
TreeMultiset	O
.	O
</s>
<s>
Apple	O
provides	O
the	O
NSCountedSet	O
class	O
as	O
part	O
of	O
Cocoa	B-Operating_System
,	O
and	O
the	O
CFBag	O
and	O
CFMutableBag	O
types	O
as	O
part	O
of	O
CoreFoundation	B-Operating_System
.	O
</s>
<s>
Python	B-Language
's	I-Language
standard	B-Library
library	I-Library
includes	O
collections.Counter	O
,	O
which	O
is	O
similar	O
to	O
a	O
multiset	B-Language
.	O
</s>
<s>
Smalltalk	B-Application
includes	O
the	O
Bag	O
class	O
,	O
which	O
can	O
be	O
instantiated	O
to	O
use	O
either	O
identity	O
or	O
equality	O
as	O
predicate	B-Algorithm
for	O
inclusion	O
test	O
.	O
</s>
<s>
Where	O
a	O
multiset	B-Language
data	B-General_Concept
structure	I-General_Concept
is	O
not	O
available	O
,	O
a	O
workaround	O
is	O
to	O
use	O
a	O
regular	O
set	B-Language
,	O
but	O
override	O
the	O
equality	O
predicate	B-Algorithm
of	O
its	O
items	O
to	O
always	O
return	O
"	O
not	O
equal	O
"	O
on	O
distinct	O
objects	O
(	O
however	O
,	O
such	O
will	O
still	O
not	O
be	O
able	O
to	O
store	O
multiple	O
occurrences	O
of	O
the	O
same	O
object	O
)	O
or	O
use	O
an	O
associative	B-Application
array	I-Application
mapping	O
the	O
values	O
to	O
their	O
integer	O
multiplicities	O
(	O
this	O
will	O
not	O
be	O
able	O
to	O
distinguish	O
between	O
equal	O
elements	O
at	O
all	O
)	O
.	O
</s>
<s>
In	O
relational	B-Application
databases	I-Application
,	O
a	O
table	O
can	O
be	O
a	O
(	O
mathematical	O
)	O
set	B-Language
or	O
a	O
multiset	B-Language
,	O
depending	O
on	O
the	O
presence	O
of	O
unicity	O
constraints	O
on	O
some	O
columns	O
(	O
which	O
turns	O
it	O
into	O
a	O
candidate	B-Application
key	I-Application
)	O
.	O
</s>
<s>
SQL	B-Language
allows	O
the	O
selection	O
of	O
rows	O
from	O
a	O
relational	O
table	O
:	O
this	O
operation	O
will	O
in	O
general	O
yield	O
a	O
multiset	B-Language
,	O
unless	O
the	O
keyword	O
DISTINCT	O
is	O
used	O
to	O
force	O
the	O
rows	O
to	O
be	O
all	O
different	O
,	O
or	O
the	O
selection	O
includes	O
the	O
primary	O
(	O
or	O
a	O
candidate	O
)	O
key	O
.	O
</s>
<s>
In	O
ANSI	O
SQL	B-Language
the	O
MULTISET	B-Language
keyword	O
can	O
be	O
used	O
to	O
transform	O
a	O
subquery	O
into	O
a	O
collection	B-Application
expression	O
:	O
</s>
<s>
transforms	O
the	O
subquery	O
into	O
a	O
collection	B-Application
expression	O
that	O
can	O
be	O
used	O
in	O
another	O
query	O
,	O
or	O
in	O
assignment	O
to	O
a	O
column	O
of	O
appropriate	O
collection	B-Application
type	O
.	O
</s>
