public void ClearHashSet() { var set = UnsafeHashSet.Allocate <int>(3); UnsafeHashSet.Add(set, 1); UnsafeHashSet.Add(set, 2); UnsafeHashSet.Add(set, 3); Assert.IsTrue(UnsafeHashSet.Contains(set, 2)); Assert.AreEqual(3, UnsafeHashSet.GetCount(set)); UnsafeHashSet.Add(set, 4); Assert.AreEqual(4, UnsafeHashSet.GetCount(set)); UnsafeHashSet.Clear(set); Assert.AreEqual(0, UnsafeHashSet.GetCount(set)); Assert.IsFalse(UnsafeHashSet.Contains(set, 2)); UnsafeHashSet.Add(set, 4); Assert.AreEqual(1, UnsafeHashSet.GetCount(set)); Assert.IsTrue(UnsafeHashSet.Contains(set, 4)); UnsafeHashSet.Clear(set); Assert.AreEqual(0, UnsafeHashSet.GetCount(set)); UnsafeHashSet.Free(set); }
public void UnsafeHashSet_IsEmpty() { var container = new UnsafeHashSet <int>(0, Allocator.Persistent); Assert.IsTrue(container.IsEmpty); Assert.IsTrue(container.Add(0)); Assert.IsFalse(container.IsEmpty); Assert.AreEqual(1, container.Capacity); ExpectedCount(ref container, 1); container.Remove(0); Assert.IsTrue(container.IsEmpty); Assert.IsTrue(container.Add(0)); container.Clear(); Assert.IsTrue(container.IsEmpty); container.Dispose(); }
public void UnsafeHashSet_Full_Throws() { var container = new UnsafeHashSet <int>(16, Allocator.Temp); ExpectedCount(ref container, 0); for (int i = 0, capacity = container.Capacity; i < capacity; ++i) { Assert.DoesNotThrow(() => { container.Add(i); }); } ExpectedCount(ref container, container.Capacity); // Make sure overallocating throws and exception if using the Concurrent version - normal hash map would grow var writer = container.AsParallelWriter(); Assert.Throws <System.InvalidOperationException>(() => { writer.Add(100); }); ExpectedCount(ref container, container.Capacity); container.Clear(); ExpectedCount(ref container, 0); container.Dispose(); }
public void Clear() { UnsafeHashSet.Clear(m_inner); }