< Summary

Information
Class: Chronicler.OrderedStringMap<T>
Assembly: Chronicler
File(s): /home/runner/work/Chronicler/Chronicler/src/Chronicler/Serialization/OrderedStringMap.cs
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 76
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Count()100%11100%
set_Item(...)100%11100%
TryGetValue(...)100%22100%
Remove(...)100%44100%
GetEnumerator()100%11100%
System.Collections.IEnumerable.GetEnumerator()100%11100%
Set(...)100%44100%

File(s)

/home/runner/work/Chronicler/Chronicler/src/Chronicler/Serialization/OrderedStringMap.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4
 5namespace Chronicler;
 6
 7internal sealed class OrderedStringMap<TValue> : IEnumerable<KeyValuePair<string, TValue>>
 8{
 9    private readonly List<KeyValuePair<string, TValue>> _entries;
 10    private readonly Dictionary<string, int> _indexes;
 11
 42312    public OrderedStringMap(int capacity, IEqualityComparer<string> comparer)
 13    {
 42314        _entries = new List<KeyValuePair<string, TValue>>(capacity);
 42315        _indexes = new Dictionary<string, int>(capacity, comparer);
 42316    }
 17
 11618    public int Count => _entries.Count;
 19
 20    public TValue this[string key]
 21    {
 30922        set => Set(key, value);
 23    }
 24
 25    public bool TryGetValue(string key, out TValue value)
 26    {
 9227        if (!_indexes.TryGetValue(key, out int index))
 28        {
 3229            value = default!;
 3230            return false;
 31        }
 32
 6033        value = _entries[index].Value;
 6034        return true;
 35    }
 36
 37    public bool Remove(string key)
 38    {
 1239        if (!_indexes.TryGetValue(key, out int index))
 140            return false;
 41
 1142        _entries.RemoveAt(index);
 1143        _indexes.Remove(key);
 44
 3245        for (int i = index; i < _entries.Count; i++)
 546            _indexes[_entries[i].Key] = i;
 47
 1148        return true;
 49    }
 50
 51    public IEnumerator<KeyValuePair<string, TValue>> GetEnumerator()
 52    {
 18153        return _entries.GetEnumerator();
 54    }
 55
 56    IEnumerator IEnumerable.GetEnumerator()
 57    {
 158        return GetEnumerator();
 59    }
 60
 61    private void Set(string key, TValue value)
 62    {
 30963        if (key == null)
 164            throw new ArgumentNullException(nameof(key));
 65
 30866        if (_indexes.TryGetValue(key, out int index))
 67        {
 868            string existingKey = _entries[index].Key;
 869            _entries[index] = new KeyValuePair<string, TValue>(existingKey, value);
 870            return;
 71        }
 72
 30073        _indexes.Add(key, _entries.Count);
 30074        _entries.Add(new KeyValuePair<string, TValue>(key, value));
 30075    }
 76}