Changeset 14657 for branches/PersistentDataStructures/HeuristicLab.Data/3.3/PersistentDataStructures/Adaptations/HistoryArray.cs
- Timestamp:
- 02/10/17 15:13:29 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistentDataStructures/HeuristicLab.Data/3.3/PersistentDataStructures/Adaptations/HistoryArray.cs
r14650 r14657 13 13 [Storable] 14 14 private ArrayMappedTrie<T> amt; 15 [Storable] 16 public int Count { get; private set; } 15 16 public int Count { 17 get { return (int?) amt.MetaInfo ?? 0; } 18 private set { amt.MetaInfo = value; } 19 } 20 17 21 public int Length { get { return Count; } } 18 22 19 23 [StorableConstructor] 20 24 protected HistoryArray(bool isDeserializing) { } 25 26 private HistoryArray(ArrayMappedTrie<T> amt) { 27 this.amt = amt.Clone(); 28 Count = (int?) amt.MetaInfo ?? 0; 29 } 21 30 22 31 protected HistoryArray(HistoryArray<T> orig) { … … 26 35 27 36 public HistoryArray(int size) { 28 amt = new ArrayMappedTrie<T> ();37 amt = new ArrayMappedTrie<T> { SnapshotInterval = 0 }; 29 38 Count = size; 30 39 } 31 40 41 [Obsolete] 32 42 public HistoryArray(IEnumerable<T> elements) { 33 amt = new ArrayMappedTrie<T> ();43 amt = new ArrayMappedTrie<T> { SnapshotInterval = 0 }; 34 44 Count = 0; 35 45 foreach (var element in elements) { … … 125 135 int hash = (int)2166136261; 126 136 for (int i = 0; i < Count; i++) { 127 hash = (hash * 16777619) ^ (this[i] ?.GetHashCode() ?? 0);137 hash = (hash * 16777619) ^ (this[i] == null ? 0 : this[i].GetHashCode()); 128 138 } 129 139 return hash; … … 137 147 Count = newSize; 138 148 } 149 150 public void CreateSnapshot() { 151 amt.CreateSnapshot(); 152 } 153 154 public IEnumerable<HistoryArray<T>> GetHistory() { 155 yield return this; 156 var prev = amt.Rollback(); 157 while (prev != null) { 158 yield return new HistoryArray<T>(prev); 159 prev = prev.Rollback(); 160 } 161 } 139 162 } 140 163 }
Note: See TracChangeset
for help on using the changeset viewer.