Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1518 for trunk


Ignore:
Timestamp:
04/07/09 11:34:49 (16 years ago)
Author:
epitzer
Message:

Make serialization order of array components explicit (in all array decomposers) (#574)

Location:
trunk/sources
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence.Test/NewSerializationTest.cs

    r1494 r1518  
    243243    }
    244244
    245     public class Base {
    246       [Storable] private int baseInt = 3;     
    247     }
    248 
    249     public class Derived: Base {
    250       [Storable] private int derivedInt = 5;
     245    public static void Test6() {
     246      string[,] mDimString = new string[,] {
     247        {"ora", "et", "labora"},
     248        {"Beten", "und", "Arbeiten"}
     249      };
     250      XmlGenerator.Serialize(mDimString, "test6.zip");
     251      object o = XmlParser.DeSerialize("test6.zip");
     252      Console.WriteLine(ViewOnlyGenerator.Serialize(mDimString));
     253      Console.WriteLine(ViewOnlyGenerator.Serialize(o));
    251254    }
    252255
     
    259262      Test4();
    260263      Test5();
     264      Test6();
    261265      //SpeedTest();
    262266      //SpeedTest2();
  • trunk/sources/HeuristicLab.Persistence/Default/Decomposers/ArrayDecomposer.cs

    r1463 r1518  
    1515      Array a = (Array)array;     
    1616      yield return new Tag("rank", a.Rank);
     17      int[] lengths = new int[a.Rank];
     18      int[] lowerBounds = new int[a.Rank];
    1719      for (int i = 0; i < a.Rank; i++) {
     20        lengths[i] = a.GetLength(i);
    1821        yield return new Tag("length_" + i, a.GetLength(i));
    1922      }
    2023      for (int i = 0; i < a.Rank; i++) {
     24        lowerBounds[i] = a.GetLowerBound(i);
    2125        yield return new Tag("lowerBound_" + i, a.GetLowerBound(i));
    2226      }
    23       foreach (object o in (Array)array) {
    24         yield return new Tag(null, o);
     27      int[] positions = (int[])lowerBounds.Clone();
     28      while (positions[a.Rank - 1] < lengths[a.Rank - 1] + lowerBounds[a.Rank - 1]) {
     29        yield return new Tag(a.GetValue(positions));
     30        positions[0] += 1;
     31        for (int i = 0; i < a.Rank - 1; i++) {
     32          if (positions[i] >= lowerBounds[i] + lengths[i]) {
     33            positions[i] = lowerBounds[i];
     34            positions[i + 1] += 1;
     35          } else {
     36            break;
     37          }
     38        }
    2539      }
    2640    }
  • trunk/sources/HeuristicLab.Persistence/Default/Decomposers/X2StringDecomposer.cs

    r1514 r1518  
    111111    public IEnumerable<Tag> DeCompose(object obj) {
    112112      Array a = (Array) obj;
     113      int[] lengths = new int[a.Rank];
     114      int[] lowerBounds = new int[a.Rank];
    113115      StringBuilder sb = new StringBuilder();
    114       sb.Append(a.Rank).Append(';');     
    115       for ( int i = 0; i<a.Rank; i++ )
     116      sb.Append(a.Rank).Append(';');
     117      for (int i = 0; i < a.Rank; i++) {
    116118        sb.Append(a.GetLength(i)).Append(';');
    117       for ( int i = 0; i<a.Rank; i++)
     119        lengths[i] = a.GetLength(i);
     120      }
     121      for (int i = 0; i < a.Rank; i++) {
    118122        sb.Append(a.GetLowerBound(i)).Append(';');
    119       foreach (var number in a) {       
    120         sb.Append(numberDecomposer.Format(number)).Append(';');
     123        lowerBounds[i] = a.GetLowerBound(i);
     124      }
     125      int[] positions = (int[])lowerBounds.Clone();
     126      while (positions[a.Rank - 1] < lengths[a.Rank - 1] + lowerBounds[a.Rank - 1]) {
     127        sb.Append(numberDecomposer.Format(a.GetValue(positions))).Append(';');
     128        positions[0] += 1;
     129        for (int i = 0; i < a.Rank - 1; i++) {
     130          if (positions[i] >= lengths[i] + lowerBounds[i]) {
     131            positions[i] = lowerBounds[i];
     132            positions[i + 1] += 1;
     133          } else {
     134            break;
     135          }
     136        }
    121137      }
    122138      yield return new Tag("compact array", sb.ToString());
  • trunk/sources/HeuristicLab.Persistence/Default/Xml/Compact/NumberArray2XmlFormatters.cs

    r1454 r1518  
    33using HeuristicLab.Persistence.Interfaces;
    44using System;
     5using HeuristicLab.Persistence.Default.ViewOnly;
    56
    67namespace HeuristicLab.Persistence.Default.Xml.Compact {
     
    1617    public object DoFormat(object obj) {
    1718      Array a = (Array)obj;
     19      int[] lengths = new int[a.Rank];
     20      int[] lowerBounds = new int[a.Rank];
    1821      StringBuilder sb = new StringBuilder();
    1922      sb.Append(a.Rank);
     
    2124        sb.Append(Separator);
    2225        sb.Append(a.GetLength(i));
     26        lengths[i] = a.GetLength(i);
    2327      }
    2428      for (int i = 0; i < a.Rank; i++) {
    2529        sb.Append(Separator);
    2630        sb.Append(a.GetLowerBound(i));
     31        lowerBounds[i] = a.GetLowerBound(i);
    2732      }
    28       foreach (object o in a) {
     33      int[] positions = (int[])lowerBounds.Clone();
     34      while (positions[a.Rank - 1] < lengths[a.Rank - 1] + lowerBounds[a.Rank - 1]) {
     35        Console.WriteLine(ViewOnlyGenerator.Serialize(positions));
    2936        sb.Append(Separator);
    30         sb.Append(formatValue(o));
    31       }
     37        sb.Append(formatValue(a.GetValue(positions)));
     38        positions[0] += 1;
     39        for (int i = 0; i < a.Rank - 1; i++) {
     40          if (positions[i] >= lengths[i] + lowerBounds[i]) {
     41            positions[i] = lowerBounds[i];
     42            positions[i + 1] += 1;
     43          } else {
     44            break;
     45          }
     46        }
     47      }     
    3248      return sb.ToString();
    3349    }
Note: See TracChangeset for help on using the changeset viewer.