Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/02/09 12:03:13 (15 years ago)
Author:
mkommend
Message:

changed SparseMatrix.Matrix and MatrixRow to a generic type (ticket #701)

Location:
trunk/sources/HeuristicLab.SparseMatrix/3.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.SparseMatrix/3.2/Matrix.cs

    r2284 r2325  
    2525
    2626namespace HeuristicLab.SparseMatrix {   
    27   public class Matrix : ItemBase {
     27  public class Matrix<KeyType,ValueType> : ItemBase {
    2828    public Matrix() {
    29       this.rows = new List<MatrixRow>();
     29      this.rows = new List<MatrixRow<KeyType,ValueType>>();
    3030    }
    3131
    32     public Matrix(IEnumerable<MatrixRow> rows)
     32    public Matrix(IEnumerable<MatrixRow<KeyType,ValueType>> rows)
    3333      : this() {
    3434      this.rows.AddRange(rows);
    3535    }
    3636
    37     private List<MatrixRow> rows;
    38     public ReadOnlyCollection<MatrixRow> GetRows() {
     37    private List<MatrixRow<KeyType, ValueType>> rows;
     38    public ReadOnlyCollection<MatrixRow<KeyType, ValueType>> GetRows() {
    3939      return rows.AsReadOnly();
    4040    }
    4141
    42     public void AddRow(MatrixRow row) {
     42    public void AddRow(MatrixRow<KeyType, ValueType> row) {
    4343      this.rows.Add(row);
    4444    }
    4545
    46     public void RemoveRow(MatrixRow row) {
     46    public void RemoveRow(MatrixRow<KeyType, ValueType> row) {
    4747      this.rows.Remove(row);
    4848    }
  • trunk/sources/HeuristicLab.SparseMatrix/3.2/MatrixRow.cs

    r2288 r2325  
    2323
    2424namespace HeuristicLab.SparseMatrix {
    25   public class MatrixRow {
    26     private Dictionary<string, object> values;
     25  public class MatrixRow<KeyType, ValueType> {
     26    private Dictionary<KeyType, ValueType> values;
    2727    public MatrixRow() {
    28       values = new Dictionary<string, object>();
    29     }
    30 
    31     public void Set(string name, object value) {
    32       values.Add(name, value);
     28      values = new Dictionary<KeyType, ValueType>();
    3329    }
    3430
    35     public object Get(string name) {
    36       if (name == null || !values.ContainsKey(name)) return null;
    37       return values[name];
     31    public void Set(KeyType key, ValueType value) {
     32      values.Add(key, value);
    3833    }
    3934
    40     public IEnumerable<KeyValuePair<string, object>> Values {
     35    public bool ContainsKey(KeyType key) {
     36      return values.ContainsKey(key);
     37    }
     38
     39    public ValueType Get(KeyType key) {
     40      if (key == null || !values.ContainsKey(key)) return default(ValueType);
     41      return values[key];
     42    }
     43
     44    public IEnumerable<KeyValuePair<KeyType, ValueType>> Values {
    4145      get { return values; }
    4246    }
Note: See TracChangeset for help on using the changeset viewer.