NanoXLSX.Writer 3.0.0-rc.3
Loading...
Searching...
No Matches
SortedMap.cs
1/*
2 * NanoXLSX is a small .NET library to generate and read XLSX (Microsoft Excel 2007 or newer) files in an easy and native way
3 * Copyright Raphael Stoeckli © 2025
4 * This library is licensed under the MIT License.
5 * You find a copy of the license in project folder or on: http://opensource.org/licenses/MIT
6 */
7
9using System.Collections.Generic;
10
11namespace NanoXLSX.Internal
12{
17 internal class SortedMap : ISortedMap
18 {
19 private readonly List<string> indexEntries;
20 private readonly Dictionary<IFormattableText, int> index;
21 private List<IFormattableText> keys;
22
26 public int Count { get; private set; }
27
31 public IEnumerable<IFormattableText> Keys => keys;
32
36 int ISortedMap.Count => keys.Count;
37
41 public SortedMap()
42 {
43 keys = new List<IFormattableText>();
44 indexEntries = new List<string>();
45 index = new Dictionary<IFormattableText, int>();
46 Count = 0;
47 }
48
55 public string Add(IFormattableText text, string referenceIndex)
56 {
57 if (index.ContainsKey(text))
58 {
59 return indexEntries[index[text]];
60 }
61 index.Add(text, Count);
62 Count++;
63 keys.Add(text);
64 indexEntries.Add(referenceIndex);
65 return referenceIndex;
66 }
67
74 string ISortedMap.Add(IFormattableText text, string referenceIndex)
75 {
76 return Add(text, referenceIndex);
77 }
78 }
79}