diff --git a/src/DtronixCommon/Collections/Lists/Lists.g.cs b/src/DtronixCommon/Collections/Lists/Lists.g.cs
index 566365f..7d54f62 100644
--- a/src/DtronixCommon/Collections/Lists/Lists.g.cs
+++ b/src/DtronixCommon/Collections/Lists/Lists.g.cs
@@ -1,3 +1,4 @@
+#nullable enable
// ----------------------------
// This file is auto generated.
// Any modifications to this file will be overridden
@@ -13,7 +14,7 @@ namespace DtronixCommon.Collections.Lists;
/// List of float with varying size with a backing array. Items erased are returned to be reused.
///
/// https://stackoverflow.com/a/48354356
-public class FloatList
+public class FloatList : IDisposable
{
public class Cache
{
@@ -59,7 +60,7 @@ public Item Get()
///
/// Contains the data.
///
- private float[] _data;
+ private float[]? _data;
///
/// Number of fields which are used in the list. This number is multuplied
@@ -114,7 +115,7 @@ public FloatList(int fieldCount, int capacity)
public float Get(int index, int field)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- return _data[index * _numFields + field];
+ return _data![index * _numFields + field];
}
///
@@ -153,7 +154,7 @@ public int GetInt(int index, int field)
public void Set(int index, int field, float value)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- _data[index * _numFields + field] = value;
+ _data![index * _numFields + field] = value;
}
///
@@ -175,7 +176,7 @@ public int PushBack()
// If the list is full, we need to reallocate the buffer to make room
// for the new element.
- if (newPos > _data.Length)
+ if (newPos > _data!.Length)
{
// Use double the size for the new capacity.
int newCap = newPos * 2;
@@ -199,7 +200,7 @@ public int PushBack(ReadOnlySpan values)
// If the list is full, we need to reallocate the buffer to make room
// for the new element.
- if (newPos > _data.Length)
+ if (newPos > _data!.Length)
{
// Use double the size for the new capacity.
int newCap = newPos * 2;
@@ -228,13 +229,13 @@ public void PopBack()
public void Increment(int index, int field)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- _data[index * _numFields + field]++;
+ _data![index * _numFields + field]++;
}
public void Decrement(int index, int field)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- _data[index * _numFields + field]--;
+ _data![index * _numFields + field]--;
}
///
@@ -250,7 +251,7 @@ public int Insert()
int pos = index * _numFields;
// Set the free index to the next free index.
- _freeElement = (int)_data[pos];
+ _freeElement = (int)_data![pos];
// Return the free index.
return index;
@@ -273,7 +274,7 @@ public int Insert(ReadOnlySpan values)
int pos = index * _numFields;
// Set the free index to the next free index.
- _freeElement = (int)_data[pos];
+ _freeElement = (int)_data![pos];
// Return the free index.
values.CopyTo(_data.AsSpan(index * _numFields));
@@ -292,16 +293,24 @@ public void Erase(int index)
{
// Push the element to the free list.
int pos = index * _numFields;
- _data[pos] = _freeElement;
+ _data![pos] = _freeElement;
_freeElement = index;
}
+
+ ///
+ /// Disposes of the list.
+ ///
+ public void Dispose()
+ {
+ _data = null;
+ }
}
///
/// List of double with varying size with a backing array. Items erased are returned to be reused.
///
/// https://stackoverflow.com/a/48354356
-public class DoubleList
+public class DoubleList : IDisposable
{
public class Cache
{
@@ -347,7 +356,7 @@ public Item Get()
///
/// Contains the data.
///
- private double[] _data;
+ private double[]? _data;
///
/// Number of fields which are used in the list. This number is multuplied
@@ -402,7 +411,7 @@ public DoubleList(int fieldCount, int capacity)
public double Get(int index, int field)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- return _data[index * _numFields + field];
+ return _data![index * _numFields + field];
}
///
@@ -441,7 +450,7 @@ public int GetInt(int index, int field)
public void Set(int index, int field, double value)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- _data[index * _numFields + field] = value;
+ _data![index * _numFields + field] = value;
}
///
@@ -463,7 +472,7 @@ public int PushBack()
// If the list is full, we need to reallocate the buffer to make room
// for the new element.
- if (newPos > _data.Length)
+ if (newPos > _data!.Length)
{
// Use double the size for the new capacity.
int newCap = newPos * 2;
@@ -487,7 +496,7 @@ public int PushBack(ReadOnlySpan values)
// If the list is full, we need to reallocate the buffer to make room
// for the new element.
- if (newPos > _data.Length)
+ if (newPos > _data!.Length)
{
// Use double the size for the new capacity.
int newCap = newPos * 2;
@@ -516,13 +525,13 @@ public void PopBack()
public void Increment(int index, int field)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- _data[index * _numFields + field]++;
+ _data![index * _numFields + field]++;
}
public void Decrement(int index, int field)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- _data[index * _numFields + field]--;
+ _data![index * _numFields + field]--;
}
///
@@ -538,7 +547,7 @@ public int Insert()
int pos = index * _numFields;
// Set the free index to the next free index.
- _freeElement = (int)_data[pos];
+ _freeElement = (int)_data![pos];
// Return the free index.
return index;
@@ -561,7 +570,7 @@ public int Insert(ReadOnlySpan values)
int pos = index * _numFields;
// Set the free index to the next free index.
- _freeElement = (int)_data[pos];
+ _freeElement = (int)_data![pos];
// Return the free index.
values.CopyTo(_data.AsSpan(index * _numFields));
@@ -580,16 +589,24 @@ public void Erase(int index)
{
// Push the element to the free list.
int pos = index * _numFields;
- _data[pos] = _freeElement;
+ _data![pos] = _freeElement;
_freeElement = index;
}
+
+ ///
+ /// Disposes of the list.
+ ///
+ public void Dispose()
+ {
+ _data = null;
+ }
}
///
/// List of int with varying size with a backing array. Items erased are returned to be reused.
///
/// https://stackoverflow.com/a/48354356
-public class IntList
+public class IntList : IDisposable
{
public class Cache
{
@@ -635,7 +652,7 @@ public Item Get()
///
/// Contains the data.
///
- private int[] _data;
+ private int[]? _data;
///
/// Number of fields which are used in the list. This number is multuplied
@@ -690,7 +707,7 @@ public IntList(int fieldCount, int capacity)
public int Get(int index, int field)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- return _data[index * _numFields + field];
+ return _data![index * _numFields + field];
}
///
@@ -729,7 +746,7 @@ public int GetInt(int index, int field)
public void Set(int index, int field, int value)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- _data[index * _numFields + field] = value;
+ _data![index * _numFields + field] = value;
}
///
@@ -751,7 +768,7 @@ public int PushBack()
// If the list is full, we need to reallocate the buffer to make room
// for the new element.
- if (newPos > _data.Length)
+ if (newPos > _data!.Length)
{
// Use double the size for the new capacity.
int newCap = newPos * 2;
@@ -775,7 +792,7 @@ public int PushBack(ReadOnlySpan values)
// If the list is full, we need to reallocate the buffer to make room
// for the new element.
- if (newPos > _data.Length)
+ if (newPos > _data!.Length)
{
// Use double the size for the new capacity.
int newCap = newPos * 2;
@@ -804,13 +821,13 @@ public void PopBack()
public void Increment(int index, int field)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- _data[index * _numFields + field]++;
+ _data![index * _numFields + field]++;
}
public void Decrement(int index, int field)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- _data[index * _numFields + field]--;
+ _data![index * _numFields + field]--;
}
///
@@ -826,7 +843,7 @@ public int Insert()
int pos = index * _numFields;
// Set the free index to the next free index.
- _freeElement = (int)_data[pos];
+ _freeElement = (int)_data![pos];
// Return the free index.
return index;
@@ -849,7 +866,7 @@ public int Insert(ReadOnlySpan values)
int pos = index * _numFields;
// Set the free index to the next free index.
- _freeElement = (int)_data[pos];
+ _freeElement = (int)_data![pos];
// Return the free index.
values.CopyTo(_data.AsSpan(index * _numFields));
@@ -868,16 +885,24 @@ public void Erase(int index)
{
// Push the element to the free list.
int pos = index * _numFields;
- _data[pos] = _freeElement;
+ _data![pos] = _freeElement;
_freeElement = index;
}
+
+ ///
+ /// Disposes of the list.
+ ///
+ public void Dispose()
+ {
+ _data = null;
+ }
}
///
/// List of long with varying size with a backing array. Items erased are returned to be reused.
///
/// https://stackoverflow.com/a/48354356
-public class LongList
+public class LongList : IDisposable
{
public class Cache
{
@@ -923,7 +948,7 @@ public Item Get()
///
/// Contains the data.
///
- private long[] _data;
+ private long[]? _data;
///
/// Number of fields which are used in the list. This number is multuplied
@@ -978,7 +1003,7 @@ public LongList(int fieldCount, int capacity)
public long Get(int index, int field)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- return _data[index * _numFields + field];
+ return _data![index * _numFields + field];
}
///
@@ -1017,7 +1042,7 @@ public int GetInt(int index, int field)
public void Set(int index, int field, long value)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- _data[index * _numFields + field] = value;
+ _data![index * _numFields + field] = value;
}
///
@@ -1039,7 +1064,7 @@ public int PushBack()
// If the list is full, we need to reallocate the buffer to make room
// for the new element.
- if (newPos > _data.Length)
+ if (newPos > _data!.Length)
{
// Use double the size for the new capacity.
int newCap = newPos * 2;
@@ -1063,7 +1088,7 @@ public int PushBack(ReadOnlySpan values)
// If the list is full, we need to reallocate the buffer to make room
// for the new element.
- if (newPos > _data.Length)
+ if (newPos > _data!.Length)
{
// Use double the size for the new capacity.
int newCap = newPos * 2;
@@ -1092,13 +1117,13 @@ public void PopBack()
public void Increment(int index, int field)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- _data[index * _numFields + field]++;
+ _data![index * _numFields + field]++;
}
public void Decrement(int index, int field)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- _data[index * _numFields + field]--;
+ _data![index * _numFields + field]--;
}
///
@@ -1114,7 +1139,7 @@ public int Insert()
int pos = index * _numFields;
// Set the free index to the next free index.
- _freeElement = (int)_data[pos];
+ _freeElement = (int)_data![pos];
// Return the free index.
return index;
@@ -1137,7 +1162,7 @@ public int Insert(ReadOnlySpan values)
int pos = index * _numFields;
// Set the free index to the next free index.
- _freeElement = (int)_data[pos];
+ _freeElement = (int)_data![pos];
// Return the free index.
values.CopyTo(_data.AsSpan(index * _numFields));
@@ -1156,7 +1181,15 @@ public void Erase(int index)
{
// Push the element to the free list.
int pos = index * _numFields;
- _data[pos] = _freeElement;
+ _data![pos] = _freeElement;
_freeElement = index;
}
+
+ ///
+ /// Disposes of the list.
+ ///
+ public void Dispose()
+ {
+ _data = null;
+ }
}
diff --git a/src/DtronixCommon/Collections/Lists/Lists.tt b/src/DtronixCommon/Collections/Lists/Lists.tt
index 2637cef..dec851a 100644
--- a/src/DtronixCommon/Collections/Lists/Lists.tt
+++ b/src/DtronixCommon/Collections/Lists/Lists.tt
@@ -32,6 +32,7 @@
}
};
#>
+#nullable enable
// ----------------------------
// This file is auto generated.
// Any modifications to this file will be overridden
@@ -49,7 +50,7 @@ namespace DtronixCommon.Collections.Lists;
/// List of <#=config.NumberType#> with varying size with a backing array. Items erased are returned to be reused.
///
/// https://stackoverflow.com/a/48354356
-<#=config.Visibility#> class <#=config.ClassName#>
+<#=config.Visibility#> class <#=config.ClassName#> : IDisposable
{
public class Cache
{
@@ -95,7 +96,7 @@ namespace DtronixCommon.Collections.Lists;
///
/// Contains the data.
///
- private <#=config.NumberType#>[] _data;
+ private <#=config.NumberType#>[]? _data;
///
/// Number of fields which are used in the list. This number is multuplied
@@ -150,7 +151,7 @@ namespace DtronixCommon.Collections.Lists;
public <#=config.NumberType#> Get(int index, int field)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- return _data[index * _numFields + field];
+ return _data![index * _numFields + field];
}
///
@@ -189,7 +190,7 @@ namespace DtronixCommon.Collections.Lists;
public void Set(int index, int field, <#=config.NumberType#> value)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- _data[index * _numFields + field] = value;
+ _data![index * _numFields + field] = value;
}
///
@@ -211,7 +212,7 @@ namespace DtronixCommon.Collections.Lists;
// If the list is full, we need to reallocate the buffer to make room
// for the new element.
- if (newPos > _data.Length)
+ if (newPos > _data!.Length)
{
// Use double the size for the new capacity.
int newCap = newPos * 2;
@@ -235,7 +236,7 @@ namespace DtronixCommon.Collections.Lists;
// If the list is full, we need to reallocate the buffer to make room
// for the new element.
- if (newPos > _data.Length)
+ if (newPos > _data!.Length)
{
// Use double the size for the new capacity.
int newCap = newPos * 2;
@@ -264,13 +265,13 @@ namespace DtronixCommon.Collections.Lists;
public void Increment(int index, int field)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- _data[index * _numFields + field]++;
+ _data![index * _numFields + field]++;
}
public void Decrement(int index, int field)
{
Debug.Assert(index >= 0 && index < InternalCount && field >= 0 && field < _numFields);
- _data[index * _numFields + field]--;
+ _data![index * _numFields + field]--;
}
///
@@ -286,7 +287,7 @@ namespace DtronixCommon.Collections.Lists;
int pos = index * _numFields;
// Set the free index to the next free index.
- _freeElement = (int)_data[pos];
+ _freeElement = (int)_data![pos];
// Return the free index.
return index;
@@ -309,7 +310,7 @@ namespace DtronixCommon.Collections.Lists;
int pos = index * _numFields;
// Set the free index to the next free index.
- _freeElement = (int)_data[pos];
+ _freeElement = (int)_data![pos];
// Return the free index.
values.CopyTo(_data.AsSpan(index * _numFields));
@@ -328,9 +329,17 @@ namespace DtronixCommon.Collections.Lists;
{
// Push the element to the free list.
int pos = index * _numFields;
- _data[pos] = _freeElement;
+ _data![pos] = _freeElement;
_freeElement = index;
}
+
+ ///
+ /// Disposes of the list.
+ ///
+ public void Dispose()
+ {
+ _data = null;
+ }
}
<#
}
diff --git a/src/DtronixCommon/Collections/Trees/QuadTrees.g.cs b/src/DtronixCommon/Collections/Trees/QuadTrees.g.cs
index e79a6d3..ac4cccd 100644
--- a/src/DtronixCommon/Collections/Trees/QuadTrees.g.cs
+++ b/src/DtronixCommon/Collections/Trees/QuadTrees.g.cs
@@ -1,3 +1,4 @@
+#nullable enable
// ----------------------------
// This file is auto generated.
// Any modifications to this file will be overridden
@@ -12,7 +13,7 @@ namespace DtronixCommon.Collections.Trees;
///
/// Quadtree with
///
-public class FloatQuadTree
+public class FloatQuadTree : IDisposable
where T : IQuadTreeItem
{
// ----------------------------------------------------------------------------------------
@@ -78,7 +79,7 @@ public class FloatQuadTree
// Data Members
// ----------------------------------------------------------------------------------------
// Temporary buffer used for queries.
- private bool[] _temp;
+ private bool[]? _temp;
// Stores the size of the temporary buffer.
private int _tempSize = 0;
@@ -90,7 +91,7 @@ public class FloatQuadTree
// Stores the maximum depth allowed for the quadtree.
private int _maxDepth;
- private T?[] items;
+ private T[]? items;
private readonly float[] _rootNode;
@@ -179,7 +180,7 @@ public int Insert(float x1, float y1, float x2, float y2, T element)
// Insert a new element.
var newElement = _eleBounds.Insert(bounds);
- if (newElement == items.Length)
+ if (newElement == items!.Length)
Array.Resize(ref items, items.Length * 2);
items[newElement] = element;
@@ -236,7 +237,7 @@ public void Remove(T element)
leaves.Return();
// Remove the element.
_eleBounds.Erase(id);
- items[id] = default;
+ items![id] = default!;
_quadTreeIdSetter(element, -1);
}
@@ -335,9 +336,9 @@ public List Query(
while (eltNodeIndex != -1)
{
int element = _eleNodes.Get(eltNodeIndex, _enodeIdxElt);
- if (!_temp[element] && Intersect(bounds, _eleBounds.Get(element, 0, 4)))
+ if (!_temp![element] && Intersect(bounds, _eleBounds.Get(element, 0, 4)))
{
- listOut.Add(items[element]!);
+ listOut.Add(items![element]);
_temp[element] = true;
}
eltNodeIndex = _eleNodes.Get(eltNodeIndex, _enodeIdxNext);
@@ -348,7 +349,7 @@ public List Query(
leaves.Return();
// Unmark the elements that were inserted.
for (int j = 0; j < listOut.Count; j++)
- _temp[listOut[j].QuadTreeId] = false;
+ _temp![listOut[j].QuadTreeId] = false;
return listOut;
}
@@ -398,11 +399,11 @@ public IntList Query(
int element = _eleNodes.Get(eltNodeIndex, _enodeIdxElt);
if (Intersect(bounds, _eleBounds.Get(element, 0, 4)))
{
- cancel = !callback.Invoke(items[element]!);
+ cancel = !callback.Invoke(items![element]);
if(cancel)
break;
intListOut.Set(intListOut.PushBack(), 0, element);
- _temp[element] = true;
+ _temp![element] = true;
}
eltNodeIndex = _eleNodes.Get(eltNodeIndex, _enodeIdxNext);
}
@@ -415,7 +416,7 @@ public IntList Query(
// Unmark the elements that were inserted.
for (int j = 0; j < intListOut.InternalCount; ++j)
- _temp[intListOut.Get(j, 0)] = false;
+ _temp![intListOut.Get(j, 0)] = false;
return intListOut;
}
@@ -457,7 +458,7 @@ public unsafe void Walk(
element = _eleNodes.Get(eltNodeIndex, _enodeIdxElt);
if (Intersect(bounds, _eleBounds.Get(element, 0, 4)))
{
- cancel = !callback.Invoke(items[element]!);
+ cancel = !callback.Invoke(items![element]);
if(cancel)
break;
}
@@ -479,8 +480,12 @@ public void Clear()
_eleNodes.Clear();
_nodes.Clear();
_eleBounds.Clear();
- Array.Clear(items, 0, items.Length);
+#if NET6_0_OR_GREATER
+ Array.Clear(items!);
+#else
+ Array.Clear(items!, 0, items.Length);
+#endif
_nodes.Insert();
_nodes.Set(0, _nodeIdxFc, -1);
_nodes.Set(0, _nodeIdxNum, 0);
@@ -627,11 +632,30 @@ private void leaf_insert(int element, ReadOnlySpan data)
_nodes.Increment(node, _nodeIdxNum);
}
}
+
+ ///
+ /// Disposes the quad tree.
+ ///
+ public void Dispose()
+ {
+ if(items == null)
+ return;
+
+ _eleNodes?.Dispose();
+ _eleBounds?.Dispose();
+ _nodes?.Dispose();
+#if NET6_0_OR_GREATER
+ Array.Clear(items!);
+#else
+ Array.Clear(items!, 0, items.Length);
+#endif
+ items = null!;
+ }
}
///
/// Quadtree with
///
-public class LongQuadTree
+public class LongQuadTree : IDisposable
where T : IQuadTreeItem
{
// ----------------------------------------------------------------------------------------
@@ -697,7 +721,7 @@ public class LongQuadTree
// Data Members
// ----------------------------------------------------------------------------------------
// Temporary buffer used for queries.
- private bool[] _temp;
+ private bool[]? _temp;
// Stores the size of the temporary buffer.
private int _tempSize = 0;
@@ -709,7 +733,7 @@ public class LongQuadTree
// Stores the maximum depth allowed for the quadtree.
private int _maxDepth;
- private T?[] items;
+ private T[]? items;
private readonly long[] _rootNode;
@@ -798,7 +822,7 @@ public int Insert(long x1, long y1, long x2, long y2, T element)
// Insert a new element.
var newElement = _eleBounds.Insert(bounds);
- if (newElement == items.Length)
+ if (newElement == items!.Length)
Array.Resize(ref items, items.Length * 2);
items[newElement] = element;
@@ -855,7 +879,7 @@ public void Remove(T element)
leaves.Return();
// Remove the element.
_eleBounds.Erase(id);
- items[id] = default;
+ items![id] = default!;
_quadTreeIdSetter(element, -1);
}
@@ -954,9 +978,9 @@ public List Query(
while (eltNodeIndex != -1)
{
int element = _eleNodes.Get(eltNodeIndex, _enodeIdxElt);
- if (!_temp[element] && Intersect(bounds, _eleBounds.Get(element, 0, 4)))
+ if (!_temp![element] && Intersect(bounds, _eleBounds.Get(element, 0, 4)))
{
- listOut.Add(items[element]!);
+ listOut.Add(items![element]);
_temp[element] = true;
}
eltNodeIndex = _eleNodes.Get(eltNodeIndex, _enodeIdxNext);
@@ -967,7 +991,7 @@ public List Query(
leaves.Return();
// Unmark the elements that were inserted.
for (int j = 0; j < listOut.Count; j++)
- _temp[listOut[j].QuadTreeId] = false;
+ _temp![listOut[j].QuadTreeId] = false;
return listOut;
}
@@ -1017,11 +1041,11 @@ public IntList Query(
int element = _eleNodes.Get(eltNodeIndex, _enodeIdxElt);
if (Intersect(bounds, _eleBounds.Get(element, 0, 4)))
{
- cancel = !callback.Invoke(items[element]!);
+ cancel = !callback.Invoke(items![element]);
if(cancel)
break;
intListOut.Set(intListOut.PushBack(), 0, element);
- _temp[element] = true;
+ _temp![element] = true;
}
eltNodeIndex = _eleNodes.Get(eltNodeIndex, _enodeIdxNext);
}
@@ -1034,7 +1058,7 @@ public IntList Query(
// Unmark the elements that were inserted.
for (int j = 0; j < intListOut.InternalCount; ++j)
- _temp[intListOut.Get(j, 0)] = false;
+ _temp![intListOut.Get(j, 0)] = false;
return intListOut;
}
@@ -1076,7 +1100,7 @@ public unsafe void Walk(
element = _eleNodes.Get(eltNodeIndex, _enodeIdxElt);
if (Intersect(bounds, _eleBounds.Get(element, 0, 4)))
{
- cancel = !callback.Invoke(items[element]!);
+ cancel = !callback.Invoke(items![element]);
if(cancel)
break;
}
@@ -1098,8 +1122,12 @@ public void Clear()
_eleNodes.Clear();
_nodes.Clear();
_eleBounds.Clear();
- Array.Clear(items, 0, items.Length);
+#if NET6_0_OR_GREATER
+ Array.Clear(items!);
+#else
+ Array.Clear(items!, 0, items.Length);
+#endif
_nodes.Insert();
_nodes.Set(0, _nodeIdxFc, -1);
_nodes.Set(0, _nodeIdxNum, 0);
@@ -1246,11 +1274,30 @@ private void leaf_insert(int element, ReadOnlySpan data)
_nodes.Increment(node, _nodeIdxNum);
}
}
+
+ ///
+ /// Disposes the quad tree.
+ ///
+ public void Dispose()
+ {
+ if(items == null)
+ return;
+
+ _eleNodes?.Dispose();
+ _eleBounds?.Dispose();
+ _nodes?.Dispose();
+#if NET6_0_OR_GREATER
+ Array.Clear(items!);
+#else
+ Array.Clear(items!, 0, items.Length);
+#endif
+ items = null!;
+ }
}
///
/// Quadtree with
///
-public class IntQuadTree
+public class IntQuadTree : IDisposable
where T : IQuadTreeItem
{
// ----------------------------------------------------------------------------------------
@@ -1316,7 +1363,7 @@ public class IntQuadTree
// Data Members
// ----------------------------------------------------------------------------------------
// Temporary buffer used for queries.
- private bool[] _temp;
+ private bool[]? _temp;
// Stores the size of the temporary buffer.
private int _tempSize = 0;
@@ -1328,7 +1375,7 @@ public class IntQuadTree
// Stores the maximum depth allowed for the quadtree.
private int _maxDepth;
- private T?[] items;
+ private T[]? items;
private readonly int[] _rootNode;
@@ -1417,7 +1464,7 @@ public int Insert(int x1, int y1, int x2, int y2, T element)
// Insert a new element.
var newElement = _eleBounds.Insert(bounds);
- if (newElement == items.Length)
+ if (newElement == items!.Length)
Array.Resize(ref items, items.Length * 2);
items[newElement] = element;
@@ -1474,7 +1521,7 @@ public void Remove(T element)
leaves.Return();
// Remove the element.
_eleBounds.Erase(id);
- items[id] = default;
+ items![id] = default!;
_quadTreeIdSetter(element, -1);
}
@@ -1573,9 +1620,9 @@ public List Query(
while (eltNodeIndex != -1)
{
int element = _eleNodes.Get(eltNodeIndex, _enodeIdxElt);
- if (!_temp[element] && Intersect(bounds, _eleBounds.Get(element, 0, 4)))
+ if (!_temp![element] && Intersect(bounds, _eleBounds.Get(element, 0, 4)))
{
- listOut.Add(items[element]!);
+ listOut.Add(items![element]);
_temp[element] = true;
}
eltNodeIndex = _eleNodes.Get(eltNodeIndex, _enodeIdxNext);
@@ -1586,7 +1633,7 @@ public List Query(
leaves.Return();
// Unmark the elements that were inserted.
for (int j = 0; j < listOut.Count; j++)
- _temp[listOut[j].QuadTreeId] = false;
+ _temp![listOut[j].QuadTreeId] = false;
return listOut;
}
@@ -1636,11 +1683,11 @@ public IntList Query(
int element = _eleNodes.Get(eltNodeIndex, _enodeIdxElt);
if (Intersect(bounds, _eleBounds.Get(element, 0, 4)))
{
- cancel = !callback.Invoke(items[element]!);
+ cancel = !callback.Invoke(items![element]);
if(cancel)
break;
intListOut.Set(intListOut.PushBack(), 0, element);
- _temp[element] = true;
+ _temp![element] = true;
}
eltNodeIndex = _eleNodes.Get(eltNodeIndex, _enodeIdxNext);
}
@@ -1653,7 +1700,7 @@ public IntList Query(
// Unmark the elements that were inserted.
for (int j = 0; j < intListOut.InternalCount; ++j)
- _temp[intListOut.Get(j, 0)] = false;
+ _temp![intListOut.Get(j, 0)] = false;
return intListOut;
}
@@ -1695,7 +1742,7 @@ public unsafe void Walk(
element = _eleNodes.Get(eltNodeIndex, _enodeIdxElt);
if (Intersect(bounds, _eleBounds.Get(element, 0, 4)))
{
- cancel = !callback.Invoke(items[element]!);
+ cancel = !callback.Invoke(items![element]);
if(cancel)
break;
}
@@ -1717,8 +1764,12 @@ public void Clear()
_eleNodes.Clear();
_nodes.Clear();
_eleBounds.Clear();
- Array.Clear(items, 0, items.Length);
+#if NET6_0_OR_GREATER
+ Array.Clear(items!);
+#else
+ Array.Clear(items!, 0, items.Length);
+#endif
_nodes.Insert();
_nodes.Set(0, _nodeIdxFc, -1);
_nodes.Set(0, _nodeIdxNum, 0);
@@ -1865,11 +1916,30 @@ private void leaf_insert(int element, ReadOnlySpan data)
_nodes.Increment(node, _nodeIdxNum);
}
}
+
+ ///
+ /// Disposes the quad tree.
+ ///
+ public void Dispose()
+ {
+ if(items == null)
+ return;
+
+ _eleNodes?.Dispose();
+ _eleBounds?.Dispose();
+ _nodes?.Dispose();
+#if NET6_0_OR_GREATER
+ Array.Clear(items!);
+#else
+ Array.Clear(items!, 0, items.Length);
+#endif
+ items = null!;
+ }
}
///
/// Quadtree with
///
-public class DoubleQuadTree
+public class DoubleQuadTree : IDisposable
where T : IQuadTreeItem
{
// ----------------------------------------------------------------------------------------
@@ -1935,7 +2005,7 @@ public class DoubleQuadTree
// Data Members
// ----------------------------------------------------------------------------------------
// Temporary buffer used for queries.
- private bool[] _temp;
+ private bool[]? _temp;
// Stores the size of the temporary buffer.
private int _tempSize = 0;
@@ -1947,7 +2017,7 @@ public class DoubleQuadTree
// Stores the maximum depth allowed for the quadtree.
private int _maxDepth;
- private T?[] items;
+ private T[]? items;
private readonly double[] _rootNode;
@@ -2036,7 +2106,7 @@ public int Insert(double x1, double y1, double x2, double y2, T element)
// Insert a new element.
var newElement = _eleBounds.Insert(bounds);
- if (newElement == items.Length)
+ if (newElement == items!.Length)
Array.Resize(ref items, items.Length * 2);
items[newElement] = element;
@@ -2093,7 +2163,7 @@ public void Remove(T element)
leaves.Return();
// Remove the element.
_eleBounds.Erase(id);
- items[id] = default;
+ items![id] = default!;
_quadTreeIdSetter(element, -1);
}
@@ -2192,9 +2262,9 @@ public List Query(
while (eltNodeIndex != -1)
{
int element = _eleNodes.Get(eltNodeIndex, _enodeIdxElt);
- if (!_temp[element] && Intersect(bounds, _eleBounds.Get(element, 0, 4)))
+ if (!_temp![element] && Intersect(bounds, _eleBounds.Get(element, 0, 4)))
{
- listOut.Add(items[element]!);
+ listOut.Add(items![element]);
_temp[element] = true;
}
eltNodeIndex = _eleNodes.Get(eltNodeIndex, _enodeIdxNext);
@@ -2205,7 +2275,7 @@ public List Query(
leaves.Return();
// Unmark the elements that were inserted.
for (int j = 0; j < listOut.Count; j++)
- _temp[listOut[j].QuadTreeId] = false;
+ _temp![listOut[j].QuadTreeId] = false;
return listOut;
}
@@ -2255,11 +2325,11 @@ public IntList Query(
int element = _eleNodes.Get(eltNodeIndex, _enodeIdxElt);
if (Intersect(bounds, _eleBounds.Get(element, 0, 4)))
{
- cancel = !callback.Invoke(items[element]!);
+ cancel = !callback.Invoke(items![element]);
if(cancel)
break;
intListOut.Set(intListOut.PushBack(), 0, element);
- _temp[element] = true;
+ _temp![element] = true;
}
eltNodeIndex = _eleNodes.Get(eltNodeIndex, _enodeIdxNext);
}
@@ -2272,7 +2342,7 @@ public IntList Query(
// Unmark the elements that were inserted.
for (int j = 0; j < intListOut.InternalCount; ++j)
- _temp[intListOut.Get(j, 0)] = false;
+ _temp![intListOut.Get(j, 0)] = false;
return intListOut;
}
@@ -2314,7 +2384,7 @@ public unsafe void Walk(
element = _eleNodes.Get(eltNodeIndex, _enodeIdxElt);
if (Intersect(bounds, _eleBounds.Get(element, 0, 4)))
{
- cancel = !callback.Invoke(items[element]!);
+ cancel = !callback.Invoke(items![element]);
if(cancel)
break;
}
@@ -2336,8 +2406,12 @@ public void Clear()
_eleNodes.Clear();
_nodes.Clear();
_eleBounds.Clear();
- Array.Clear(items, 0, items.Length);
+#if NET6_0_OR_GREATER
+ Array.Clear(items!);
+#else
+ Array.Clear(items!, 0, items.Length);
+#endif
_nodes.Insert();
_nodes.Set(0, _nodeIdxFc, -1);
_nodes.Set(0, _nodeIdxNum, 0);
@@ -2484,4 +2558,23 @@ private void leaf_insert(int element, ReadOnlySpan data)
_nodes.Increment(node, _nodeIdxNum);
}
}
+
+ ///
+ /// Disposes the quad tree.
+ ///
+ public void Dispose()
+ {
+ if(items == null)
+ return;
+
+ _eleNodes?.Dispose();
+ _eleBounds?.Dispose();
+ _nodes?.Dispose();
+#if NET6_0_OR_GREATER
+ Array.Clear(items!);
+#else
+ Array.Clear(items!, 0, items.Length);
+#endif
+ items = null!;
+ }
}
diff --git a/src/DtronixCommon/Collections/Trees/QuadTrees.tt b/src/DtronixCommon/Collections/Trees/QuadTrees.tt
index 043fc2f..22ace8f 100644
--- a/src/DtronixCommon/Collections/Trees/QuadTrees.tt
+++ b/src/DtronixCommon/Collections/Trees/QuadTrees.tt
@@ -32,6 +32,7 @@
}
};
#>
+#nullable enable
// ----------------------------
// This file is auto generated.
// Any modifications to this file will be overridden
@@ -50,7 +51,7 @@ namespace DtronixCommon.Collections.Trees;
///
/// Quadtree with
///
-public class <#=config.ClassName#>
+public class <#=config.ClassName#> : IDisposable
where T : IQuadTreeItem
{
// ----------------------------------------------------------------------------------------
@@ -116,7 +117,7 @@ public class <#=config.ClassName#>
// Data Members
// ----------------------------------------------------------------------------------------
// Temporary buffer used for queries.
- private bool[] _temp;
+ private bool[]? _temp;
// Stores the size of the temporary buffer.
private int _tempSize = 0;
@@ -128,7 +129,7 @@ public class <#=config.ClassName#>
// Stores the maximum depth allowed for the quadtree.
private int _maxDepth;
- private T?[] items;
+ private T[]? items;
private readonly <#=config.MainNumberType#>[] _rootNode;
@@ -217,7 +218,7 @@ public class <#=config.ClassName#>
// Insert a new element.
var newElement = _eleBounds.Insert(bounds);
- if (newElement == items.Length)
+ if (newElement == items!.Length)
Array.Resize(ref items, items.Length * 2);
items[newElement] = element;
@@ -274,7 +275,7 @@ public class <#=config.ClassName#>
leaves.Return();
// Remove the element.
_eleBounds.Erase(id);
- items[id] = default;
+ items![id] = default!;
_quadTreeIdSetter(element, -1);
}
@@ -373,9 +374,9 @@ public class <#=config.ClassName#>
while (eltNodeIndex != -1)
{
int element = _eleNodes.Get(eltNodeIndex, _enodeIdxElt);
- if (!_temp[element] && Intersect(bounds, _eleBounds.Get(element, 0, 4)))
+ if (!_temp![element] && Intersect(bounds, _eleBounds.Get(element, 0, 4)))
{
- listOut.Add(items[element]!);
+ listOut.Add(items![element]);
_temp[element] = true;
}
eltNodeIndex = _eleNodes.Get(eltNodeIndex, _enodeIdxNext);
@@ -386,7 +387,7 @@ public class <#=config.ClassName#>
leaves.Return();
// Unmark the elements that were inserted.
for (int j = 0; j < listOut.Count; j++)
- _temp[listOut[j].QuadTreeId] = false;
+ _temp![listOut[j].QuadTreeId] = false;
return listOut;
}
@@ -436,11 +437,11 @@ public class <#=config.ClassName#>
int element = _eleNodes.Get(eltNodeIndex, _enodeIdxElt);
if (Intersect(bounds, _eleBounds.Get(element, 0, 4)))
{
- cancel = !callback.Invoke(items[element]!);
+ cancel = !callback.Invoke(items![element]);
if(cancel)
break;
intListOut.Set(intListOut.PushBack(), 0, element);
- _temp[element] = true;
+ _temp![element] = true;
}
eltNodeIndex = _eleNodes.Get(eltNodeIndex, _enodeIdxNext);
}
@@ -453,7 +454,7 @@ public class <#=config.ClassName#>
// Unmark the elements that were inserted.
for (int j = 0; j < intListOut.InternalCount; ++j)
- _temp[intListOut.Get(j, 0)] = false;
+ _temp![intListOut.Get(j, 0)] = false;
return intListOut;
}
@@ -495,7 +496,7 @@ public class <#=config.ClassName#>
element = _eleNodes.Get(eltNodeIndex, _enodeIdxElt);
if (Intersect(bounds, _eleBounds.Get(element, 0, 4)))
{
- cancel = !callback.Invoke(items[element]!);
+ cancel = !callback.Invoke(items![element]);
if(cancel)
break;
}
@@ -517,8 +518,12 @@ public class <#=config.ClassName#>
_eleNodes.Clear();
_nodes.Clear();
_eleBounds.Clear();
- Array.Clear(items, 0, items.Length);
+#if NET6_0_OR_GREATER
+ Array.Clear(items!);
+#else
+ Array.Clear(items!, 0, items.Length);
+#endif
_nodes.Insert();
_nodes.Set(0, _nodeIdxFc, -1);
_nodes.Set(0, _nodeIdxNum, 0);
@@ -665,6 +670,25 @@ public class <#=config.ClassName#>
_nodes.Increment(node, _nodeIdxNum);
}
}
+
+ ///
+ /// Disposes the quad tree.
+ ///
+ public void Dispose()
+ {
+ if(items == null)
+ return;
+
+ _eleNodes?.Dispose();
+ _eleBounds?.Dispose();
+ _nodes?.Dispose();
+#if NET6_0_OR_GREATER
+ Array.Clear(items!);
+#else
+ Array.Clear(items!, 0, items.Length);
+#endif
+ items = null!;
+ }
}
<#
}
diff --git a/src/DtronixCommon/DtronixCommon.csproj b/src/DtronixCommon/DtronixCommon.csproj
index bbcd1ca..8b35a1d 100644
--- a/src/DtronixCommon/DtronixCommon.csproj
+++ b/src/DtronixCommon/DtronixCommon.csproj
@@ -2,7 +2,7 @@
net5.0;net6.0
enable
- 0.7.0.0
+ 0.8.0.0
enable
10
Dtronix
diff --git a/src/DtronixCommon/tag_release.ps1 b/src/DtronixCommon/tag_release.ps1
new file mode 100644
index 0000000..a613ccc
--- /dev/null
+++ b/src/DtronixCommon/tag_release.ps1
@@ -0,0 +1,24 @@
+# Ensure that changes are not pending.
+$gitChanges = git status --porcelain;
+$ChangedFiles = $($gitChanges | Measure-Object | Select-Object -expand Count)
+if ($ChangedFiles -gt 0)
+{
+ Write-Output "There are $ChangedFiles uncommited changes in the repository. Must commit prior to tagging. Changed Files:"
+ Write-Output $gitChanges
+ Read-Host -Prompt "Press Enter to exit"
+ exit
+}
+
+$projectFile = Get-ChildItem -filter "*.csproj"
+$version = Select-Xml -Path $projectFile -XPath "Project/PropertyGroup/Version" | Select-Object -ExpandProperty Node
+$tag = $projectFile.BaseName + "-v" + $version.InnerText
+
+$confirmation = Read-Host "Tag current commit with '$tag' (y/n):"
+if ($confirmation -eq 'y') {
+ git tag $tag
+}
+
+$confirmation = Read-Host "Push new tag to origin? (y/n):"
+if ($confirmation -eq 'y') {
+ git push origin $tag
+}
\ No newline at end of file