Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/23/15 18:47:21 (8 years ago)
Author:
swagner
Message:

#2520: Worked on persistence overhaul

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/Index.cs

    r13326 r13347  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3333
    3434    public Index() {
    35       indexes = new Dictionary<T, uint>();
    36       values = new Dictionary<uint, T>();
    37       nextIndex = 1;
     35      this.indexes = new Dictionary<T, uint>();
     36      this.values = new Dictionary<uint, T>();
     37      nextIndex = 0;
    3838    }
    39     public Index(IEnumerable<Tuple<uint, T>> values)
     39    public Index(IEnumerable<T> values)
    4040      : this() {
    4141      foreach (var value in values) {
    42         this.indexes.Add(value.Item2, value.Item1);
    43         this.values.Add(value.Item1, value.Item2);
     42        this.indexes.Add(value, nextIndex);
     43        this.values.Add(nextIndex, value);
    4444        nextIndex++;
    4545      }
     
    4747
    4848    public uint GetIndex(T value) {
    49       uint index = 0;
    50       indexes.TryGetValue(value, out index);
    51       if (index == 0) {
     49      uint index;
     50      if (!indexes.TryGetValue(value, out index)) {
    5251        index = nextIndex;
    5352        nextIndex++;
     
    6059      return values[index];
    6160    }
    62     public IEnumerable<Tuple<uint, T>> GetValues() {
    63       return values.Select(x => new Tuple<uint, T>(x.Key, x.Value));
     61    public IEnumerable<T> GetValues() {
     62      return values.Values;
    6463    }
    6564  }
Note: See TracChangeset for help on using the changeset viewer.