Ignore:
Timestamp:
02/07/17 14:05:09 (4 years ago)
Author:
epitzer
Message:

#2727 completely replace basic array with array mapped trie in ValueTypeArray and descendants

File:
1 edited

Legend:

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

    r14186 r14650  
    2828using HeuristicLab.Common;
    2929using HeuristicLab.Core;
     30using HeuristicLab.Data.PersistentDataStructures.Adaptations;
    3031using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3132
     
    4041    }
    4142
    42     [Storable]
    43     protected T[] array;
     43    [Storable(AllowOneWay = true, Name = "array")]
     44    protected T[] oldArrayValuePersistence { set { historyArray = new HistoryArray<T>(value); } }
     45
     46    [Storable]
     47    protected HistoryArray<T> historyArray;
    4448
    4549    [Storable]
     
    6064
    6165    public virtual int Length {
    62       get { return array.Length; }
     66      get { return historyArray.Length; }
    6367      #region Mono Compatibility
    6468      // this setter should be protected, but the Mono compiler couldn't handle it
     
    6670        if (ReadOnly) throw new NotSupportedException("Length cannot be set. ValueTypeArray is read-only.");
    6771        if (value != Length) {
    68           Array.Resize<T>(ref array, value);
     72          historyArray.Resize(value);
    6973          while (elementNames.Count > value)
    7074            elementNames.RemoveAt(elementNames.Count - 1);
     
    9094
    9195    public virtual T this[int index] {
    92       get { return array[index]; }
     96      get { return historyArray[index]; }
    9397      set {
    9498        if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeArray is read-only.");
    95         if (!value.Equals(array[index])) {
    96           array[index] = value;
     99        if (!value.Equals(historyArray[index])) {
     100          historyArray[index] = value;
    97101          OnItemChanged(index);
    98102        }
     
    115119    protected ValueTypeArray(ValueTypeArray<T> original, Cloner cloner)
    116120      : base(original, cloner) {
    117       this.array = (T[])original.array.Clone();
     121      this.historyArray = (HistoryArray<T>)original.historyArray.Clone();
    118122      this.readOnly = original.readOnly;
    119123      this.resizable = original.resizable;
     
    121125    }
    122126    protected ValueTypeArray() {
    123       array = new T[0];
     127      historyArray = new HistoryArray<T>(0);
    124128      readOnly = false;
    125129      resizable = true;
     
    127131    }
    128132    protected ValueTypeArray(int length) {
    129       array = new T[length];
     133      historyArray = new HistoryArray<T>(length);
    130134      readOnly = false;
    131135      resizable = true;
     
    134138    protected ValueTypeArray(T[] elements) {
    135139      if (elements == null) throw new ArgumentNullException();
    136       array = (T[])elements.Clone();
     140      historyArray = new HistoryArray<T>(elements);
    137141      readOnly = false;
    138142      resizable = true;
     
    147151
    148152    public T[] CloneAsArray() {
    149       //mkommend: this works because T must be a value type (struct constraint);
    150       return (T[])array.Clone();
     153      return historyArray.ToArray();
    151154    }
    152155
    153156    public override string ToString() {
    154       if (array.Length == 0) return "[]";
     157      if (historyArray.Length == 0) return "[]";
    155158
    156159      StringBuilder sb = new StringBuilder();
    157160      sb.Append("[");
    158       sb.Append(array[0].ToString());
    159       for (int i = 1; i < array.Length; i++) {
    160         sb.Append(";").Append(array[i].ToString());
     161      sb.Append(historyArray[0].ToString());
     162      for (int i = 1; i < historyArray.Length; i++) {
     163        sb.Append(";").Append(historyArray[i].ToString());
    161164        if (sb.Length > maximumToStringLength) {
    162165          sb.Append("...");
     
    169172
    170173    public virtual IEnumerator<T> GetEnumerator() {
    171       return array.Cast<T>().GetEnumerator();
     174      return historyArray.Cast<T>().GetEnumerator();
    172175    }
    173176
Note: See TracChangeset for help on using the changeset viewer.