18 using System.Collections;
19 using System.Collections.Generic;
34 private readonly Dictionary<string, MapFile> _mapFilesByPermtick;
35 private readonly Dictionary<string, SortedList<DateTime, MapFileRowEntry>> _bySymbol;
50 _mapFilesByPermtick =
new Dictionary<string, MapFile>(StringComparer.InvariantCultureIgnoreCase);
51 _bySymbol =
new Dictionary<string, SortedList<DateTime, MapFileRowEntry>>(StringComparer.InvariantCultureIgnoreCase);
53 foreach (var mapFile
in mapFiles)
56 _mapFilesByPermtick.Add(mapFile.Permtick, mapFile);
58 foreach (var row
in mapFile)
60 SortedList<DateTime, MapFileRowEntry> entries;
61 var mapFileRowEntry =
new MapFileRowEntry(mapFile.Permtick, row);
63 if (!_bySymbol.TryGetValue(row.MappedSymbol, out entries))
65 entries =
new SortedList<DateTime, MapFileRowEntry>();
66 _bySymbol[row.MappedSymbol] = entries;
69 if (entries.ContainsKey(mapFileRowEntry.MapFileRow.Date))
72 if (!entries[mapFileRowEntry.MapFileRow.Date].Equals(mapFileRowEntry))
74 throw new DuplicateNameException(
"Attempted to assign different history for symbol.");
79 entries.Add(mapFileRowEntry.MapFileRow.Date, mapFileRowEntry);
93 _mapFilesByPermtick.TryGetValue(permtick.LazyToUpper(), out mapFile);
106 SortedList<DateTime, MapFileRowEntry> entries;
107 if (_bySymbol.TryGetValue(symbol, out entries))
109 if (entries.Count == 0)
118 var indexOf = entries.Keys.BinarySearch(date);
121 symbol = entries.Values[indexOf].EntitySymbol;
125 if (indexOf == ~entries.Keys.Count)
128 indexOf = entries.Keys.Count - 1;
136 symbol = entries.Values[indexOf].EntitySymbol;
141 if (!_mapFilesByPermtick.TryGetValue(symbol, out mapFile)
152 class MapFileRowEntry : IEquatable<MapFileRowEntry>
162 public string EntitySymbol {
get;
private set; }
169 public MapFileRowEntry(
string entitySymbol, MapFileRow mapFileRow)
171 MapFileRow = mapFileRow;
172 EntitySymbol = entitySymbol;
182 public bool Equals(MapFileRowEntry other)
184 if (other ==
null)
return false;
185 return other.MapFileRow.Date == MapFileRow.Date
186 && other.MapFileRow.MappedSymbol == MapFileRow.MappedSymbol;
196 public override string ToString()
198 return MapFileRow.Date +
": " + MapFileRow.MappedSymbol +
": " + EntitySymbol;
202 #region Implementation of IEnumerable
213 return _mapFilesByPermtick.Values.GetEnumerator();
223 IEnumerator IEnumerable.GetEnumerator()