Skip to content

Optimizations, Architectural Improvements and Bug Fixes#4

Merged
CaseyHofland merged 10 commits intomasterfrom
develop
Jul 29, 2025
Merged

Optimizations, Architectural Improvements and Bug Fixes#4
CaseyHofland merged 10 commits intomasterfrom
develop

Conversation

@CaseyHofland
Copy link
Contributor

@CaseyHofland CaseyHofland commented May 16, 2025

This update makes a lot of improvements while keeping previous code intact, if not deprecated in certain places.

Deprecated Replaced by
JsonConverter<TInput, TOutput> SpanJsonConverter<T, U> or JsonConverter<T>
JsonSerializer JsonStreamSerializer

The deprecation of JsonSerializer to JsonStreamSerializer is simply a name change. Both classes function exactly the same, but the later name better conveys the intent of the class (an IStreamSerializer for Json serialization) and doesn't conflict with the JsonSerializer class in the System.Text.Json namespace. This is but a minor gripe, but a nice one to avoid.

This update also deprecates the JsonConverter<TInput, TOutput>. The HeatmapJsonConverters have been changed to inherit from JsonConverter<T>, and the NumericJsonConverters have been changed to inherit from the SpanJsonConverter<T, U>, a very fast JsonConverter<T> for serializing a data type to, and deserializing a data type from, an array of an unmanaged type. The SpanJsonConverter<T> allocates no extra memory serializing and deserializing the object by working directly with existing memory through the use of Spans.

To unify the heatmap implementations, a new class Counter<T> has been made and -parented to Heatmap2, Heatmap3, and Heatmap3to2. A Counter<T> is a wrapper for a Dictionary<T, int> that makes it simple to count items. Heatmaps are effectively positional counters, hence can inherit from this generic class. It may also be repurposed in different scenarios.

Other additions include the BooleanExtensions class with a utility function for converting a boolean to an int with ToInt() or a number with ToNumber<T>(), setting the projects globalization to invariant for consistent functionality across different regions, and changing the license from GNU to MIT.

Cheers.

…eatmap3, and Heatmap3to2.

Add settings to benchmarks on startup. This enables the use of starting up benchmarks from the command line with arguments.
…rialize data types as arrays of a single unmanaged type, like Vectors and Matrices.
…r and deprecate it for backwards compatability.
Change HeatmapJsonConverters to inherit from JsonConverter<TInput> and be much more performant.
Counter<TItem> is a wrapper for Dictionary<TItem, int> that makes it simple to count items. For example:
```csharp
public class Program
{
    public static void Main()
    {
        var counter = new Counter<string>();

        counter.Add("hello", 3);
        var i = counter["hello"]; // returns 3

        counter.Add("hello"); // Same as counter.Add("hello", 1);
        i = counter["hello"]; // returns 4

        counter.Remove("hello", 2);
        i = counter["hello"]; // returns 2
    }
}
```
This removes a lot of the similar code from both classes and makes the implementation more consistent.
A utility method for turning a boolean into an int / number.
This ensures that the library is build with invariant globalization in mind, making it function the same way across all regions.
This change was made so that seperate packages may be build and sold from this software.
@CaseyHofland CaseyHofland changed the title Optimize JsonConverters Optimizations, Architectural Improvements and Bug Fixes Jul 29, 2025
@CaseyHofland CaseyHofland merged commit 5d50f4e into master Jul 29, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant