Ignore:
Timestamp:
02/10/17 15:13:29 (4 years ago)
Author:
epitzer
Message:

#2727 add generic MetaInfo to AMT e.g. for tracking Count in facades

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PersistentDataStructures/HeuristicLab.Data/3.3/PersistentDataStructures/Adaptations/HistoryArray.cs

    r14650 r14657  
    1313    [Storable]
    1414    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
    1721    public int Length { get { return Count; } }
    1822
    1923    [StorableConstructor]
    2024    protected HistoryArray(bool isDeserializing) { }
     25
     26    private HistoryArray(ArrayMappedTrie<T> amt) {
     27      this.amt = amt.Clone();
     28      Count = (int?) amt.MetaInfo ?? 0;
     29    }
    2130
    2231    protected HistoryArray(HistoryArray<T> orig) {
     
    2635
    2736    public HistoryArray(int size) {
    28       amt = new ArrayMappedTrie<T>();
     37      amt = new ArrayMappedTrie<T> { SnapshotInterval = 0 };
    2938      Count = size;
    3039    }
    3140
     41    [Obsolete]
    3242    public HistoryArray(IEnumerable<T> elements) {
    33       amt = new ArrayMappedTrie<T>();
     43      amt = new ArrayMappedTrie<T> { SnapshotInterval = 0 };
    3444      Count = 0;
    3545      foreach (var element in elements) {
     
    125135        int hash = (int)2166136261;
    126136        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());
    128138        }
    129139        return hash;
     
    137147      Count = newSize;
    138148    }
     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    }
    139162  }
    140163}
Note: See TracChangeset for help on using the changeset viewer.