Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ All notable changes to Celerity are documented here. This project follows [Keep

- **`Trie<TValue>`** in `Celerity.Collections` — an ordered prefix tree mapping `string` keys to values, filling a BCL gap (.NET ships no trie). `GetByPrefix` lists every entry whose key starts with a prefix in `O(prefix + matches)` and in ascending key order, and `TryGetLongestPrefix` finds the longest stored key that is a prefix of a query in `O(query)` — the autocomplete, longest-prefix-routing, and ordered-iteration workloads a `Dictionary<string, TValue>` can only answer with an `O(n)` scan plus a `StartsWith` per key. Exact `Add` / `TryGetValue` favour a `Dictionary`, so the trie earns its place on the prefix operations. Implements `IReadOnlyDictionary<string, TValue?>`; not thread-safe. Closes [#285](https://github.com/marius-bughiu/Celerity/issues/285).

### Fixed

- `PooledCelerityDictionary` and `PooledCeleritySet` now throw `ObjectDisposedException` from their read accessors (`Count`, and the dictionary's `Keys` / `Values`) after `Dispose`, matching the documented "every member throws after disposal" contract. Previously these returned a silent, misleading result over arrays already returned to `ArrayPool.Shared`. Closes [#296](https://github.com/marius-bughiu/Celerity/issues/296).

## [2.3.0] - 2026-07-19

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,15 @@ public void UseAfterDispose_ShouldThrowObjectDisposedException()
Assert.Throws<ObjectDisposedException>(() => map.TryAdd(2, 2));
Assert.Throws<ObjectDisposedException>(() => map.Clear());
Assert.Throws<ObjectDisposedException>(() => map.GetEnumerator());
Assert.Throws<ObjectDisposedException>(() => map.EnsureCapacity(64));
Assert.Throws<ObjectDisposedException>(() => map.TrimExcess());
// Read accessors must also honour the disposed contract: Dispose returns
// the backing arrays to the pool, so a silent Count / Keys / Values here
// would report over — or enumerate — buffers the pool may have re-handed
// out. Regression for #296.
Assert.Throws<ObjectDisposedException>(() => _ = map.Count);
Assert.Throws<ObjectDisposedException>(() => _ = map.Keys);
Assert.Throws<ObjectDisposedException>(() => _ = map.Values);
}

[Fact]
Expand Down
5 changes: 5 additions & 0 deletions src/Celerity.Tests/Collections/PooledCeleritySetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ public void UseAfterDispose_ShouldThrowObjectDisposedException()
Assert.Throws<ObjectDisposedException>(() => set.Overlaps(new[] { 3 }));
Assert.Throws<ObjectDisposedException>(() => set.SetEquals(new[] { 3 }));
Assert.Throws<ObjectDisposedException>(() => set.CopyTo(new int[4], 0));
// Read accessor must also honour the disposed contract: Dispose zeroes
// _count and returns the backing array to the pool, so a silent Count
// here would report 0 over a buffer the pool may have re-handed out.
// Regression for #296.
Assert.Throws<ObjectDisposedException>(() => _ = set.Count);
}

[Fact]
Expand Down
30 changes: 27 additions & 3 deletions src/Celerity/Collections/PooledCelerityDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,15 @@ private static int InitialCapacityForSource(
/// <summary>
/// Gets the number of key/value pairs contained in the dictionary.
/// </summary>
public int Count => _count;
/// <exception cref="ObjectDisposedException">The dictionary has been disposed.</exception>
public int Count
{
get
{
ThrowIfDisposed();
return _count;
}
}

/// <summary>
/// Gets or sets the value associated with the specified key.
Expand Down Expand Up @@ -619,13 +627,29 @@ public Enumerator GetEnumerator()
/// Gets an enumerable view over the keys in the dictionary. The view is a
/// lightweight struct and iterating it does not allocate.
/// </summary>
public KeyCollection Keys => new KeyCollection(this);
/// <exception cref="ObjectDisposedException">The dictionary has been disposed.</exception>
public KeyCollection Keys
{
get
{
ThrowIfDisposed();
return new KeyCollection(this);
}
}

/// <summary>
/// Gets an enumerable view over the values in the dictionary. The view is a
/// lightweight struct and iterating it does not allocate.
/// </summary>
public ValueCollection Values => new ValueCollection(this);
/// <exception cref="ObjectDisposedException">The dictionary has been disposed.</exception>
public ValueCollection Values
{
get
{
ThrowIfDisposed();
return new ValueCollection(this);
}
}

/// <summary>
/// A struct enumerator over a
Expand Down
10 changes: 9 additions & 1 deletion src/Celerity/Collections/PooledCeleritySet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,15 @@ private static int InitialCapacityForSource(IEnumerable<T> source, int capacity,
/// <summary>
/// Gets the number of elements contained in the set.
/// </summary>
public int Count => _count;
/// <exception cref="ObjectDisposedException">The set has been disposed.</exception>
public int Count
{
get
{
ThrowIfDisposed();
return _count;
}
}

/// <summary>
/// Adds the specified element to the set.
Expand Down
Loading