This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
auto x = redBlackTree!T;
By default standard red-black trees don't accept duplicates, hence making great sets.
x := make(map[T]struct{})
The struct{} type is space efficient because it occupies zero bytes in memory.
x := make(map[T]bool)
There is no built-in Set type, but you can create a Map with key type T and boolean value (which will be ignored).
Set<T> x = new HashSet<T>();
The type T must respect the equals() / hashcode() contract.
class T:
def __init__(self, x):
self.x = x
def __hash__(self):
return hash(self.x)
def __eq__(self, t):
return self.x == t.x
x = {T('abc'), T(123), T(lambda: ...)}