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/HistoryList.cs

    r14650 r14657  
    99
    1010  [StorableClass]
    11   public class HistoryList<T> : IList<T> {
     11  public class HistoryList<T> : IList<T>, ICloneable {
    1212
    1313    [Storable]
    1414    private readonly ArrayMappedTrie<T> amt;
    1515
    16     public int Count { get; private set; }
     16    public int Count {
     17      get { return (int) amt.MetaInfo; }
     18      private set { amt.MetaInfo = value; }
     19    }
    1720
    1821    [StorableConstructor]
    1922    protected HistoryList(bool isDesierializing) { }
    2023
     24    private HistoryList(ArrayMappedTrie<T> amt) { this.amt = amt; }
     25
    2126    public HistoryList() {
    22       amt = new ArrayMappedTrie<T>(true);
     27      amt = new ArrayMappedTrie<T> { SnapshotInterval = 0 };
    2328      Count = 0;
     29    }
     30
     31    public HistoryList(HistoryList<T> orig) {
     32      amt = orig.amt.Clone();
     33      Count = orig.Count;
     34    }
     35
     36
     37    [Obsolete]
     38    public HistoryList(IEnumerable<T> values) {
     39      amt = new ArrayMappedTrie<T> { SnapshotInterval = 0 };
     40      Count = 0;
     41      foreach (var value in values) Add(value);
    2442    }
    2543
     
    114132        amt.CreateSnapshot();
    115133    }
     134
     135    public void CreateSnapshot() {
     136      amt.CreateSnapshot();
     137    }
     138
     139    public IEnumerable<HistoryList<T>> GetHistory() {
     140      yield return this;
     141      var prev = amt.Rollback();
     142      while (prev != null) {
     143        yield return new HistoryList<T>(prev);
     144        prev = prev.Rollback();
     145      }
     146    }
     147
     148    public object Clone() { return new HistoryList<T>(this); }
    116149  }
    117150}
Note: See TracChangeset for help on using the changeset viewer.