Skip to content

Commit

Permalink
HybridPriorityQueue // Concurrency-safe patches.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen committed Feb 13, 2025
1 parent 9f081d1 commit a457ba4
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Megrez/src/0_CSharpExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,21 +321,23 @@ private void HeapifyDown(int index) {
/// 清空佇列。
/// </summary>
public void Clear() {
if (_storage != null) {
Array.Clear(_storage, 0, _storage.Length);
if (_storage.Length > InitialCapacity) {
_storage = new T[InitialCapacity];
lock (_syncRoot) {
if (_storage.Length != 0) {
Array.Clear(_storage, 0, _storage.Length);
if (_storage.Length > InitialCapacity) {
_storage = new T[InitialCapacity];
}
}
Count = 0;
_usingArray = true;
}
Count = 0;
_usingArray = true;
}

public void Dispose() {
if (_isDisposed) return;

Clear();
if (_storage != null) {
if (_storage.Length != 0) {
Array.Clear(_storage, 0, _storage.Length);
_storage = null!;
}
Expand Down

0 comments on commit a457ba4

Please sign in to comment.