HashSet

Source: lib/HashSet.cs

This page is generated from the source by scripts/gen-reference.py.

HashSet: a set of unmanaged values, backed by an Arena.

var seen = HashSet<int>.Create(arena);
if (!seen.Add(id)) Console.WriteLine($"duplicate: {id}");

A Dict without values underneath, so it behaves like one: a handle whose copies share contents, default(HashSet) is "not created", and items are compared as .NET's HashSet compares them (EqualityComparer.Default). HashSet<T, TComparer> takes a comparer of your own, as Dict<TKey, TValue, TComparer> does; ByteEqualityComparer compares raw bytes.

Members

Create

public static HashSet<T> Create(Arena arena, int capacity = 32)

Returns a new set in arena, or a not-created set if it is out of memory.

IsCreated

public bool IsCreated

Count

public int Count

Add

public bool Add(T item)

Adds the item. Returns true if it was added; false if it was already in the set, or the set isn't created or the arena is full (Count tells which).

Contains

public bool Contains(T item)

Remove

public bool Remove(T item)

Removes the item. Returns false if it wasn't in the set.

Clear

public void Clear()

UnionWith

public bool UnionWith(HashSet<T> other)

Adds every item of other. Returns false if the arena filled up first.

IntersectWith

public void IntersectWith(HashSet<T> other)

Keeps only the items that are also in other.

ExceptWith

public void ExceptWith(HashSet<T> other)

Removes every item that is in other.

GetEnumerator

public HashSet<T, DefaultEqualityComparer<T>>.Enumerator GetEnumerator()

For foreach: every item, in no particular order. Don't Add or Remove during the loop.

Clone

public HashSet<T> Clone(Arena target)

Returns an independent copy in target, or a not-created set if this one isn't created or the target is out of memory.