Izayoi.Collections.TimestampedDictionary 1.0.0

dotnet add package Izayoi.Collections.TimestampedDictionary --version 1.0.0                
NuGet\Install-Package Izayoi.Collections.TimestampedDictionary -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Izayoi.Collections.TimestampedDictionary" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Izayoi.Collections.TimestampedDictionary --version 1.0.0                
#r "nuget: Izayoi.Collections.TimestampedDictionary, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Izayoi.Collections.TimestampedDictionary as a Cake Addin
#addin nuget:?package=Izayoi.Collections.TimestampedDictionary&version=1.0.0

// Install Izayoi.Collections.TimestampedDictionary as a Cake Tool
#tool nuget:?package=Izayoi.Collections.TimestampedDictionary&version=1.0.0                

Timestamped Dictionary

This is a dictionary that records datetime when data is added.

Feature

  • When an element is added or updated, a timestamp is recorded on the element.
  • It is possible to set an upper limit on the number of elements that can be stored. (By default, it is unlimited)
  • When adding elements, the oldest element is deleted if the capacity is exceeded.

Documentation

Class Remarks
TimestampedDictionary<TKey, TValue>
TimestampedDictionary<TValue> Key type is string.

Usage

Generate various types of dictionaries.

    using Izayoi.Collections;
    using System;

    static void Main()
    {
        // key: int, value: long
        var intKeyDicionary = new TimestampedDictionary<int, long>();

        // key: Guid, value: User
        var userDicionary = new TimestampedDictionary<Guid, User>();

        // key: string, value: int
        var stringKeyDicionary = new TimestampedDictionary<int>();
    }

See timestamp.

    using Izayoi.Collections;

    static void Main()
    {
        var dictionary = new TimestampedDictionary<int, string>();

        bool addResult = dictionary.TryAdd(key: 1, value: "a");

        // addResult: true

        bool getResult = dictionary.TryGetValue(key: 1, out var value);

        // getResult: true

        // value: "a"

        bool getDataResult = dictionary.TryGetData(key: 1, out var data);

        // getDataResult: true

        // data.Timestamp: 1234567890, data.Key: 1, data.Value: "a"

        var keys = dictionary.GetTimestampedKeys();

        // keys[0].Timestamp: 1234567890, keys[0].Key: 1
    }

Delete old data.

    using Izayoi.Collections;
    using System.Threading.Tasks;

    static async Task Main()
    {
        var cache = new TimestampedDictionary<int, string>();

        _ = cache.TryAdd(key: 1, value: "a");
        _ = cache.TryAdd(key: 2, value: "b");

        await Task.Delay(1000);

        DateTimeOffset datetime = DateTimeOffset.UtcNow;

        await Task.Delay(1000);

        _ = cache.TryAdd(key: 3, value: "c");

        await Task.Delay(1000);

        // delete old data
        cache.ClearBefore(datetime);

        bool result1 = cache.TryGetValue(key: 1, out var value1);

        // result1: false, value1: null

        bool result2 = cache.TryGetValue(key: 2, out var value2);

        // result2: false, value2: null

        bool result3 = cache.TryGetValue(key: 3, out var value3);

        // result3: true, value3: "c"
    }

Enable capacity.

    using Izayoi.Collections;

    static void Main()
    {
        var dictionary = new TimestampedDictionary<int, string>(capacity: 2);

        bool containsKey1;

        bool addResult1 = dictionary.TryAdd(key: 1, value: "a");

        // addResult1: true

        bool addResult2 = dictionary.TryAdd(key: 2, value: "b");

        // addResult1: true

        // contains: 1, 2
        containsKey1 = dictionary.ContainsKey(key: 1);

        // containsKey1: true

        bool addResult3 = dictionary.TryAdd(key: 3, value: "c");

        // addResult3: true

        // contains: 2, 3
        containsKey1 = dictionary.ContainsKey(key: 1);

        // containsKey1: false

        bool addResult4 = dictionary.TryAdd(key: 4, value: "d");

        // addResult4: true

        // contains: 3, 4
        bool containsKey2 = dictionary.ContainsKey(key: 2);

        // containsKey2: false
    }

Last updated: 15 July, 2024
Editor: Izayoi Jiichan

Copyright (C) 2024 Izayoi Jiichan. All Rights Reserved.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 94 7/15/2024