lemon/matrix_maps.h
author deba
Sun, 11 Feb 2007 16:34:51 +0000
changeset 2357 5365600a7a5c
parent 2260 4274224f8a7d
child 2376 0ed45a6c74b1
permissions -rw-r--r--
Some bug fix
RevIt => RevEdgeIt renaming
deba@1720
     1
/* -*- C++ -*-
deba@1720
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@1956
     5
 * Copyright (C) 2003-2006
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@1720
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@1720
     8
 *
deba@1720
     9
 * Permission to use, modify and distribute this software is granted
deba@1720
    10
 * provided that this copyright notice appears in all copies. For
deba@1720
    11
 * precise terms see the accompanying LICENSE file.
deba@1720
    12
 *
deba@1720
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@1720
    14
 * express or implied, and with no claim as to its suitability for any
deba@1720
    15
 * purpose.
deba@1720
    16
 *
deba@1720
    17
 */
deba@1720
    18
deba@1720
    19
#ifndef LEMON_MATRIX_MAPS_H
deba@1720
    20
#define LEMON_MATRIX_MAPS_H
deba@1720
    21
deba@1720
    22
deba@1720
    23
#include <vector>
deba@1993
    24
#include <lemon/bits/utility.h>
alpar@2088
    25
#include <lemon/bits/invalid.h>
deba@1720
    26
#include <lemon/maps.h>
deba@1720
    27
alpar@2260
    28
#include <lemon/concepts/matrix_maps.h>
deba@1720
    29
deba@1720
    30
/// \file
alpar@2072
    31
/// \ingroup matrices
deba@1720
    32
/// \brief Maps indexed with pairs of items.
deba@1720
    33
///
alpar@2260
    34
/// \todo This file has the same name as the concept file in concepts/,
deba@1720
    35
///  and this is not easily detectable in docs...
deba@1720
    36
namespace lemon {
deba@1720
    37
deba@1720
    38
  /// \brief Map for the coloumn view of the matrix
deba@1720
    39
  ///
alpar@2072
    40
  /// \ingroup matrices
deba@1720
    41
  /// Map for the coloumn view of the matrix.
alpar@2072
    42
  ///
deba@1720
    43
  template <typename _MatrixMap>
deba@2039
    44
  class MatrixRowMap : public MatrixMapTraits<_MatrixMap> {
deba@1720
    45
  public:
deba@1720
    46
    typedef _MatrixMap MatrixMap;
deba@1720
    47
    typedef typename MatrixMap::SecondKey Key;
deba@1720
    48
    typedef typename MatrixMap::Value Value;
deba@1720
    49
deba@1720
    50
deba@2084
    51
    /// \brief Constructor of the row map
deba@2084
    52
    ///
deba@2084
    53
    /// Constructor of the row map.
deba@1751
    54
    MatrixRowMap(MatrixMap& _matrix, typename MatrixMap::FirstKey _row) 
deba@1720
    55
      : matrix(_matrix), row(_row) {}
deba@1720
    56
deba@1720
    57
    /// \brief Subscription operator
deba@1720
    58
    ///
deba@1720
    59
    /// Subscription operator.
deba@2039
    60
    typename MatrixMapTraits<MatrixMap>::ReturnValue
deba@1720
    61
    operator[](Key col) {
deba@1751
    62
      return matrix(row, col);
deba@1720
    63
    }
deba@1720
    64
deba@1720
    65
    /// \brief Setter function
deba@1720
    66
    ///
deba@1720
    67
    /// Setter function.
deba@1720
    68
    void set(Key col, const Value& val) {
deba@1751
    69
      matrix.set(row, col, val);
deba@1720
    70
    }
deba@1720
    71
      
deba@1720
    72
    /// \brief Subscription operator
deba@1720
    73
    ///
deba@1720
    74
    /// Subscription operator.
deba@2039
    75
    typename MatrixMapTraits<MatrixMap>::ConstReturnValue
deba@1720
    76
    operator[](Key col) const {
deba@1751
    77
      return matrix(row, col);
deba@1720
    78
    }
deba@1720
    79
deba@1720
    80
  private:
deba@1720
    81
    MatrixMap& matrix;
deba@1751
    82
    typename MatrixMap::FirstKey row;
deba@1720
    83
  };
deba@1720
    84
deba@1720
    85
  /// \brief Map for the row view of the matrix
deba@1720
    86
  ///
alpar@2072
    87
  /// \ingroup matrices
deba@1720
    88
  /// Map for the row view of the matrix.
alpar@2072
    89
  ///
deba@1720
    90
  template <typename _MatrixMap>
deba@2039
    91
  class ConstMatrixRowMap : public MatrixMapTraits<_MatrixMap> {
deba@1720
    92
  public:
deba@1720
    93
    typedef _MatrixMap MatrixMap;
deba@1751
    94
    typedef typename MatrixMap::SecondKey Key;
deba@1720
    95
    typedef typename MatrixMap::Value Value;
deba@1720
    96
deba@1751
    97
deba@2084
    98
    /// \brief Constructor of the row map
deba@2084
    99
    ///
deba@2084
   100
    /// Constructor of the row map.
deba@1720
   101
    ConstMatrixRowMap(const MatrixMap& _matrix, 
deba@1751
   102
		      typename MatrixMap::FirstKey _row) 
deba@1720
   103
      : matrix(_matrix), row(_row) {}
deba@1720
   104
deba@1720
   105
    /// \brief Subscription operator
deba@1720
   106
    ///
deba@1720
   107
    /// Subscription operator.
deba@2039
   108
    typename MatrixMapTraits<MatrixMap>::ConstReturnValue
deba@1720
   109
    operator[](Key col) const {
deba@1751
   110
      return matrix(row, col);
deba@1720
   111
    }
deba@1720
   112
deba@1720
   113
  private:
deba@1720
   114
    const MatrixMap& matrix;
deba@1751
   115
    typename MatrixMap::FirstKey row;
deba@1720
   116
  };
deba@1720
   117
deba@2084
   118
  /// \ingroup matrices
deba@2084
   119
  ///
deba@1720
   120
  /// \brief Gives back a row view of the matrix map
deba@1720
   121
  ///
deba@1720
   122
  /// Gives back a row view of the matrix map.
alpar@2072
   123
  ///
deba@2084
   124
  /// \sa MatrixRowMap
deba@2084
   125
  /// \sa ConstMatrixRowMap
deba@1720
   126
  template <typename MatrixMap>
deba@1720
   127
  MatrixRowMap<MatrixMap> matrixRowMap(MatrixMap& matrixMap,
deba@1751
   128
				       typename MatrixMap::FirstKey row) {
deba@1720
   129
    return MatrixRowMap<MatrixMap>(matrixMap, row);
deba@1720
   130
  }
deba@1720
   131
deba@1720
   132
  template <typename MatrixMap>
deba@1751
   133
  ConstMatrixRowMap<MatrixMap>
deba@1751
   134
  matrixRowMap(const MatrixMap& matrixMap, typename MatrixMap::FirstKey row) {
deba@1720
   135
    return ConstMatrixRowMap<MatrixMap>(matrixMap, row);
deba@1720
   136
  }
deba@1720
   137
alpar@2072
   138
  /// \brief Map for the column view of the matrix
deba@1751
   139
  ///
alpar@2072
   140
  /// \ingroup matrices
alpar@2072
   141
  /// Map for the column view of the matrix.
alpar@2072
   142
  ///
deba@1751
   143
  template <typename _MatrixMap>
deba@2039
   144
  class MatrixColMap : public MatrixMapTraits<_MatrixMap> {
deba@1751
   145
  public:
deba@1751
   146
    typedef _MatrixMap MatrixMap;
deba@1751
   147
    typedef typename MatrixMap::FirstKey Key;
deba@1751
   148
    typedef typename MatrixMap::Value Value;
deba@1751
   149
deba@2084
   150
    /// \brief Constructor of the column map
deba@2084
   151
    ///
deba@2084
   152
    /// Constructor of the column map.
deba@1751
   153
    MatrixColMap(MatrixMap& _matrix, typename MatrixMap::SecondKey _col) 
deba@1751
   154
      : matrix(_matrix), col(_col) {}
deba@1751
   155
deba@1751
   156
    /// \brief Subscription operator
deba@1751
   157
    ///
deba@1751
   158
    /// Subscription operator.
deba@2039
   159
    typename MatrixMapTraits<MatrixMap>::ReturnValue
deba@1751
   160
    operator[](Key row) {
deba@1751
   161
      return matrix(row, col);
deba@1751
   162
    }
deba@1751
   163
deba@1751
   164
    /// \brief Setter function
deba@1751
   165
    ///
deba@1751
   166
    /// Setter function.
deba@1751
   167
    void set(Key row, const Value& val) {
deba@1751
   168
      matrix.set(row, col, val);
deba@1751
   169
    }
deba@1751
   170
      
deba@1751
   171
    /// \brief Subscription operator
deba@1751
   172
    ///
deba@1751
   173
    /// Subscription operator.
deba@2039
   174
    typename MatrixMapTraits<MatrixMap>::ConstReturnValue
deba@1751
   175
    operator[](Key row) const {
deba@1751
   176
      return matrix(row, col);
deba@1751
   177
    }
deba@1751
   178
deba@1751
   179
  private:
deba@1751
   180
    MatrixMap& matrix;
deba@1751
   181
    typename MatrixMap::SecondKey col;
deba@1751
   182
  };
deba@1751
   183
alpar@2072
   184
  /// \brief Map for the column view of the matrix
deba@1751
   185
  ///
alpar@2072
   186
  /// \ingroup matrices
alpar@2072
   187
  /// Map for the column view of the matrix.
alpar@2072
   188
  ///
deba@1751
   189
  template <typename _MatrixMap>
deba@2039
   190
  class ConstMatrixColMap : public MatrixMapTraits<_MatrixMap> {
deba@1751
   191
  public:
deba@1751
   192
    typedef _MatrixMap MatrixMap;
deba@1751
   193
    typedef typename MatrixMap::FirstKey Key;
deba@1751
   194
    typedef typename MatrixMap::Value Value;
deba@1751
   195
deba@2084
   196
    /// \brief Constructor of the column map
deba@2084
   197
    ///
deba@2084
   198
    /// Constructor of the column map.
deba@1751
   199
    ConstMatrixColMap(const MatrixMap& _matrix, 
deba@1751
   200
		      typename MatrixMap::SecondKey _col) 
deba@1751
   201
      : matrix(_matrix), col(_col) {}
deba@1751
   202
deba@1751
   203
    /// \brief Subscription operator
deba@1751
   204
    ///
deba@1751
   205
    /// Subscription operator.
deba@2039
   206
    typename MatrixMapTraits<MatrixMap>::ConstReturnValue
deba@1751
   207
    operator[](Key row) const {
deba@1751
   208
      return matrix(row, col);
deba@1751
   209
    }
deba@1751
   210
deba@1751
   211
  private:
deba@1751
   212
    const MatrixMap& matrix;
deba@1751
   213
    typename MatrixMap::SecondKey col;
deba@1751
   214
  };
deba@1751
   215
deba@2084
   216
  /// \ingroup matrices
deba@2084
   217
  ///
alpar@2072
   218
  /// \brief Gives back a column view of the matrix map
deba@1751
   219
  ///
alpar@2072
   220
  /// Gives back a column view of the matrix map.
alpar@2072
   221
  ///
deba@2084
   222
  /// \sa MatrixColMap
deba@2084
   223
  /// \sa ConstMatrixColMap
deba@1751
   224
  template <typename MatrixMap>
deba@1751
   225
  MatrixColMap<MatrixMap> matrixColMap(MatrixMap& matrixMap,
deba@1751
   226
				       typename MatrixMap::SecondKey col) {
deba@1751
   227
    return MatrixColMap<MatrixMap>(matrixMap, col);
deba@1751
   228
  }
deba@1751
   229
deba@1751
   230
  template <typename MatrixMap>
deba@1751
   231
  ConstMatrixColMap<MatrixMap> 
deba@1751
   232
  matrixColMap(const MatrixMap& matrixMap, typename MatrixMap::SecondKey col) {
deba@1751
   233
    return ConstMatrixColMap<MatrixMap>(matrixMap, col);
deba@1751
   234
  }
deba@1751
   235
deba@1720
   236
  /// \brief Container for store values for each ordered pair of graph items
deba@1720
   237
  ///
alpar@2072
   238
  /// \ingroup matrices
alpar@1757
   239
  /// This data structure can strore for each pair of the same item
deba@1720
   240
  /// type a value. It increase the size of the container when the 
deba@1720
   241
  /// associated graph modified, so it updated automaticly whenever
deba@1720
   242
  /// it is needed.
deba@1720
   243
  template <typename _Graph, typename _Item, typename _Value>
deba@1720
   244
  class DynamicMatrixMap 
deba@1999
   245
    : protected ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
deba@1720
   246
  public:
deba@1999
   247
    typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase 
deba@1999
   248
    Parent;
deba@1720
   249
deba@1720
   250
    typedef _Graph Graph;
deba@1720
   251
    typedef _Item Key;
deba@1720
   252
deba@1720
   253
    typedef _Item FirstKey;
deba@1720
   254
    typedef _Item SecondKey;
deba@1720
   255
    typedef _Value Value;
deba@1720
   256
deba@1720
   257
    typedef True ReferenceMapTag;
deba@1720
   258
deba@1720
   259
  private:
deba@1720
   260
		
deba@1720
   261
    typedef std::vector<Value> Container;
deba@1720
   262
deba@1720
   263
  public:
deba@1720
   264
deba@1720
   265
    typedef typename Container::reference Reference;
deba@1720
   266
    typedef typename Container::const_reference ConstReference;
deba@1720
   267
deba@1720
   268
    /// \brief Creates an item matrix for the given graph
deba@1720
   269
    ///
deba@1720
   270
    /// Creates an item matrix for the given graph.
deba@1720
   271
    DynamicMatrixMap(const Graph& _graph) 
deba@1999
   272
      : values(size(_graph.maxId(Key()) + 1)) {
deba@1999
   273
      Parent::attach(_graph.getNotifier(Key()));
deba@1720
   274
    }
deba@1720
   275
deba@1720
   276
    /// \brief Creates an item matrix for the given graph
deba@1720
   277
    ///
deba@1720
   278
    /// Creates an item matrix for the given graph and assigns for each
deba@1720
   279
    /// pairs of keys the given parameter.
deba@1720
   280
    DynamicMatrixMap(const Graph& _graph, const Value& _val) 
deba@1999
   281
      : values(size(_graph.maxId(Key()) + 1), _val) {
deba@1999
   282
      Parent::attach(_graph.getNotifier(Key()));
deba@1720
   283
    }
deba@1720
   284
deba@2039
   285
    ///\brief The assignement operator.
deba@2039
   286
    ///
deba@2039
   287
    ///It allow to assign a map to an other.
deba@2039
   288
    DynamicMatrixMap& operator=(const DynamicMatrixMap& _cmap){
deba@2039
   289
      return operator=<DynamicMatrixMap>(_cmap);
deba@2039
   290
    }
deba@2039
   291
      
deba@2039
   292
    ///\brief Template assignement operator.
deba@2039
   293
    ///
deba@2039
   294
    ///It copy the element of the given map to its own container.  The
deba@2039
   295
    ///type of the two map shall be the same.
deba@2039
   296
    template <typename CMap>
deba@2039
   297
    DynamicMatrixMap& operator=(const CMap& _cmap){
alpar@2260
   298
      checkConcept<concepts::ReadMatrixMap<FirstKey, SecondKey, Value>, CMap>();
deba@2039
   299
      typename Parent::Notifier* notifier = Parent::getNotifier();
deba@2039
   300
      Key first, second;
deba@2039
   301
      for(notifier->first(first); first != INVALID; 
deba@2039
   302
          notifier->next(first)){
deba@2039
   303
        for(notifier->first(second); second != INVALID; 
deba@2039
   304
            notifier->next(second)){
deba@2039
   305
          set(first, second, _cmap(first, second));
deba@2039
   306
        }
deba@2039
   307
      }
deba@2039
   308
      return *this;
deba@2039
   309
    }
deba@2039
   310
deba@1720
   311
    /// \brief Gives back the value assigned to the \c first - \c second
deba@1720
   312
    /// ordered pair.
deba@1720
   313
    ///
deba@1720
   314
    /// Gives back the value assigned to the \c first - \c second ordered pair.
deba@1720
   315
    ConstReference operator()(const Key& first, const Key& second) const {
deba@1999
   316
      return values[index(Parent::getNotifier()->id(first), 
deba@1999
   317
                          Parent::getNotifier()->id(second))];
deba@1720
   318
    }
deba@1720
   319
    
deba@1720
   320
    /// \brief Gives back the value assigned to the \c first - \c second
deba@1720
   321
    /// ordered pair.
deba@1720
   322
    ///
deba@1720
   323
    /// Gives back the value assigned to the \c first - \c second ordered pair.
deba@1720
   324
    Reference operator()(const Key& first, const Key& second) {
deba@1999
   325
      return values[index(Parent::getNotifier()->id(first), 
deba@1999
   326
                          Parent::getNotifier()->id(second))];
deba@1720
   327
    }
deba@1720
   328
deba@1720
   329
    /// \brief Setter function for the matrix map.
deba@1720
   330
    ///
deba@1720
   331
    /// Setter function for the matrix map.
deba@1720
   332
    void set(const Key& first, const Key& second, const Value& val) {
deba@1999
   333
      values[index(Parent::getNotifier()->id(first), 
deba@1999
   334
                   Parent::getNotifier()->id(second))] = val;
deba@1720
   335
    }
deba@1720
   336
deba@1720
   337
  protected:
deba@1720
   338
deba@1720
   339
    static int index(int i, int j) {
deba@1720
   340
      if (i < j) {
deba@1720
   341
	return j * j + i;
deba@1720
   342
      } else {
deba@1720
   343
	return i * i + i + j;
deba@1720
   344
      }
deba@1720
   345
    }
deba@1720
   346
deba@1720
   347
    static int size(int s) {
deba@1720
   348
      return s * s;
deba@1720
   349
    }
deba@1720
   350
deba@1720
   351
    virtual void add(const Key& key) {
deba@1999
   352
      if (size(Parent::getNotifier()->id(key) + 1) >= (int)values.size()) {
deba@1999
   353
	values.resize(size(Parent::getNotifier()->id(key) + 1));	
deba@1720
   354
      }
deba@1720
   355
    }
deba@1720
   356
deba@2305
   357
    virtual void add(const std::vector<Key>& keys) {
deba@2305
   358
      int new_size = 0;
deba@2305
   359
      for (int i = 0; i < (int)keys.size(); ++i) {
deba@2305
   360
        if (size(Parent::getNotifier()->id(keys[i]) + 1) >= new_size) {
deba@2305
   361
          new_size = size(Parent::getNotifier()->id(keys[i]) + 1);	
deba@2305
   362
        }
deba@2305
   363
      }
deba@2305
   364
      if (new_size > (int)values.size()) {
deba@2305
   365
        values.resize(new_size);
deba@2305
   366
      }
deba@2305
   367
    }
deba@2305
   368
deba@1720
   369
    virtual void erase(const Key&) {}
deba@1720
   370
deba@2305
   371
    virtual void erase(const std::vector<Key>&) {}
deba@2305
   372
deba@1720
   373
    virtual void build() {
deba@1999
   374
      values.resize(size(Parent::getNotifier()->maxId() + 1));
deba@1720
   375
    }
deba@1720
   376
deba@1720
   377
    virtual void clear() {
deba@1720
   378
      values.clear();
deba@1720
   379
    }   
deba@1720
   380
    
deba@1720
   381
  private:
deba@1720
   382
    std::vector<Value> values;
deba@1720
   383
  };
deba@1720
   384
deba@1720
   385
  /// \brief Container for store values for each unordered pair of graph items
deba@1720
   386
  ///
alpar@2072
   387
  /// \ingroup matrices
alpar@1757
   388
  /// This data structure can strore for each pair of the same item
deba@1720
   389
  /// type a value. It increase the size of the container when the 
deba@1720
   390
  /// associated graph modified, so it updated automaticly whenever
deba@1720
   391
  /// it is needed. 
deba@1720
   392
  template <typename _Graph, typename _Item, typename _Value>
deba@1720
   393
  class DynamicSymMatrixMap 
deba@1999
   394
    : protected ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
deba@1720
   395
  public:
deba@1999
   396
    typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase 
deba@1999
   397
    Parent;
deba@1720
   398
deba@1720
   399
    typedef _Graph Graph;
deba@1720
   400
    typedef _Item Key;
deba@1720
   401
deba@1720
   402
    typedef _Item FirstKey;
deba@1720
   403
    typedef _Item SecondKey;
deba@1720
   404
    typedef _Value Value;
deba@1720
   405
deba@1720
   406
    typedef True ReferenceMapTag;
deba@1720
   407
deba@1720
   408
  private:
deba@1720
   409
		
deba@1720
   410
    typedef std::vector<Value> Container;
deba@1720
   411
deba@1720
   412
  public:
deba@1720
   413
deba@1720
   414
    typedef typename Container::reference Reference;
deba@1720
   415
    typedef typename Container::const_reference ConstReference;
deba@1720
   416
deba@1720
   417
    /// \brief Creates an item matrix for the given graph
deba@1720
   418
    ///
deba@1720
   419
    /// Creates an item matrix for the given graph.
deba@1720
   420
    DynamicSymMatrixMap(const Graph& _graph) 
deba@1999
   421
      : values(size(_graph.maxId(Key()) + 1)) {
deba@1999
   422
      Parent::attach(_graph.getNotifier(Key()));
deba@1720
   423
    }
deba@1720
   424
deba@1720
   425
    /// \brief Creates an item matrix for the given graph
deba@1720
   426
    ///
deba@1720
   427
    /// Creates an item matrix for the given graph and assigns for each
deba@1720
   428
    /// pairs of keys the given parameter.
deba@1720
   429
    DynamicSymMatrixMap(const Graph& _graph, const Value& _val) 
deba@1999
   430
      : values(size(_graph.maxId(Key()) + 1), _val) {
deba@1999
   431
      Parent::attach(_graph.getNotifier(Key()));
deba@1720
   432
    }
deba@1720
   433
deba@2039
   434
deba@2039
   435
    ///\brief The assignement operator.
deba@2039
   436
    ///
deba@2039
   437
    ///It allow to assign a map to an other.
alpar@2072
   438
    ///
deba@2039
   439
    DynamicSymMatrixMap& operator=(const DynamicSymMatrixMap& _cmap){
deba@2039
   440
      return operator=<DynamicSymMatrixMap>(_cmap);
deba@2039
   441
    }
deba@2039
   442
      
deba@2039
   443
    ///\brief Template assignement operator.
deba@2039
   444
    ///
deba@2039
   445
    ///It copy the element of the given map to its own container.  The
deba@2039
   446
    ///type of the two map shall be the same.
deba@2039
   447
    template <typename CMap>
deba@2039
   448
    DynamicSymMatrixMap& operator=(const CMap& _cmap){
alpar@2260
   449
      checkConcept<concepts::ReadMatrixMap<FirstKey, SecondKey, Value>, CMap>();
deba@2039
   450
      typename Parent::Notifier* notifier = Parent::getNotifier();
deba@2039
   451
      Key first, second;
deba@2039
   452
      for(notifier->first(first); first != INVALID; 
deba@2039
   453
          notifier->next(first)){
deba@2039
   454
        for(notifier->first(second); second != first; 
deba@2039
   455
            notifier->next(second)){
deba@2039
   456
          set(first, second, _cmap(first, second));
deba@2039
   457
        }
deba@2039
   458
        set(first, first, _cmap(first, first));        
deba@2039
   459
      }
deba@2039
   460
      return *this;
deba@2039
   461
    }
deba@2039
   462
deba@1720
   463
    /// \brief Gives back the value assigned to the \c first - \c second
deba@1720
   464
    /// unordered pair.
deba@1720
   465
    ///
deba@1720
   466
    /// Gives back the value assigned to the \c first - \c second unordered 
deba@1720
   467
    /// pair.
deba@1720
   468
    ConstReference operator()(const Key& first, const Key& second) const {
deba@1999
   469
      return values[index(Parent::getNotifier()->id(first), 
deba@1999
   470
                          Parent::getNotifier()->id(second))];
deba@1720
   471
    }
deba@1720
   472
    
deba@1720
   473
    /// \brief Gives back the value assigned to the \c first - \c second
deba@1720
   474
    /// unordered pair.
deba@1720
   475
    ///
deba@1720
   476
    /// Gives back the value assigned to the \c first - \c second unordered 
deba@1720
   477
    /// pair.
deba@1720
   478
    Reference operator()(const Key& first, const Key& second) {
deba@1999
   479
      return values[index(Parent::getNotifier()->id(first), 
deba@1999
   480
                          Parent::getNotifier()->id(second))];
deba@1720
   481
    }
deba@1720
   482
deba@1720
   483
    /// \brief Setter function for the matrix map.
deba@1720
   484
    ///
deba@1720
   485
    /// Setter function for the matrix map.
alpar@2072
   486
    ///
deba@1720
   487
    void set(const Key& first, const Key& second, const Value& val) {
deba@1999
   488
      values[index(Parent::getNotifier()->id(first), 
deba@1999
   489
                   Parent::getNotifier()->id(second))] = val;
deba@1720
   490
    }
deba@1720
   491
deba@1720
   492
  protected:
deba@1720
   493
deba@1720
   494
    static int index(int i, int j) {
deba@1720
   495
      if (i < j) {
deba@1720
   496
	return j * (j + 1) / 2 + i;
deba@1720
   497
      } else {
deba@1720
   498
	return i * (i + 1) / 2 + j;
deba@1720
   499
      }
deba@1720
   500
    }
deba@1720
   501
deba@1720
   502
    static int size(int s) {
deba@1720
   503
      return s * (s + 1) / 2;
deba@1720
   504
    }
deba@1720
   505
deba@1720
   506
    virtual void add(const Key& key) {
deba@1999
   507
      if (size(Parent::getNotifier()->id(key) + 1) >= (int)values.size()) {
deba@1999
   508
	values.resize(size(Parent::getNotifier()->id(key) + 1));	
deba@1720
   509
      }
deba@1720
   510
    }
deba@1720
   511
deba@2305
   512
    virtual void add(const std::vector<Key>& keys) {
deba@2305
   513
      int new_size = 0;
deba@2305
   514
      for (int i = 0; i < (int)keys.size(); ++i) {
deba@2305
   515
        if (size(Parent::getNotifier()->id(keys[i]) + 1) >= new_size) {
deba@2305
   516
          new_size = size(Parent::getNotifier()->id(keys[i]) + 1);	
deba@2305
   517
        }
deba@2305
   518
      }
deba@2305
   519
      if (new_size > (int)values.size()) {
deba@2305
   520
        values.resize(new_size);
deba@2305
   521
      }
deba@2305
   522
    }
deba@2305
   523
deba@1720
   524
    virtual void erase(const Key&) {}
deba@1720
   525
deba@2305
   526
    virtual void erase(const std::vector<Key>&) {}
deba@2305
   527
deba@1720
   528
    virtual void build() {
deba@1999
   529
      values.resize(size(Parent::getNotifier()->maxId() + 1));
deba@1720
   530
    }
deba@1720
   531
deba@1720
   532
    virtual void clear() {
deba@1720
   533
      values.clear();
deba@1720
   534
    }   
deba@1720
   535
    
deba@1720
   536
  private:
deba@1720
   537
    std::vector<Value> values;
deba@1720
   538
  };
deba@2039
   539
  
deba@2039
   540
  ///\brief Dynamic Asymmetric Matrix Map.
deba@2039
   541
  ///
alpar@2072
   542
  ///\ingroup matrices
deba@2039
   543
  ///Dynamic Asymmetric Matrix Map.  Container for store values for each
deba@2039
   544
  ///ordered pair of containers items.  This data structure can store
deba@2039
   545
  ///data with different key types from different container types. It
deba@2039
   546
  ///increases the size of the container if the linked containers
deba@2039
   547
  ///content change, so it is updated automaticly whenever it is
deba@2039
   548
  ///needed.
deba@2039
   549
  ///
alpar@2260
   550
  ///This map meet with the concepts::ReferenceMatrixMap<typename K1,
deba@2039
   551
  ///typename K2, typename V, typename R, typename CR> called as
deba@2039
   552
  ///"ReferenceMatrixMap".
deba@2039
   553
  ///
deba@2039
   554
  ///\param _FirstContainer the desired type of first container. It is
deba@2039
   555
  ///ususally a Graph type, but can be any type with alteration
deba@2039
   556
  ///property.
deba@2039
   557
  ///  
deba@2039
   558
  ///\param _FirstContainerItem the nested type of the
deba@2039
   559
  ///FirstContainer. It is usually a graph item as Node, Edge,
deba@2039
   560
  ///etc. This type will be the FirstKey type.
deba@2039
   561
  ///
deba@2039
   562
  ///\param _SecondContainer the desired type of the second
deba@2039
   563
  ///container. It is usualy a Graph type, but can be any type with
deba@2039
   564
  ///alteration property.
deba@2039
   565
  ///
deba@2039
   566
  ///\param _SecondContainerItem the nested type of the
deba@2039
   567
  ///SecondContainer. It is usually a graph item such as Node, Edge,
deba@2039
   568
  ///UEdge, etc. This type will be the SecondKey type.
deba@2039
   569
  ///
deba@2039
   570
  ///\param _Value the type of the strored values in the container.
deba@2039
   571
  ///
deba@2039
   572
  /// \author Janos Nagy
deba@2039
   573
  template <typename _FirstContainer, typename _FirstContainerItem, 
deba@2039
   574
            typename _SecondContainer, typename _SecondContainerItem, 
deba@2039
   575
            typename _Value>
deba@2039
   576
  class DynamicAsymMatrixMap{
deba@2039
   577
  public:
deba@2039
   578
deba@2039
   579
    ///The first key type.
deba@2039
   580
    typedef _FirstContainerItem FirstKey;
deba@2039
   581
      
deba@2039
   582
    ///The second key type.
deba@2039
   583
    typedef _SecondContainerItem SecondKey;
deba@2039
   584
      
deba@2039
   585
    ///The value type of the map.
deba@2039
   586
    typedef _Value Value;
deba@2039
   587
      
deba@2039
   588
    ///Indicates it is a reference map.
deba@2039
   589
    typedef True ReferenceMapTag;
deba@2039
   590
    
deba@2039
   591
  protected:
deba@2039
   592
      
deba@2039
   593
    ///\brief Proxy class for the first key type.
deba@2039
   594
    ///
deba@2039
   595
    ///The proxy class belongs to the FirstKey type. It is necessary because
deba@2039
   596
    ///if one want use the same conatainer types and same nested types but on
deba@2039
   597
    ///other instances of containers than due to the type equiality of nested
deba@2039
   598
    ///types it requires a proxy mechanism. 
deba@2039
   599
    class FirstKeyProxy 
deba@2039
   600
      : protected 
deba@2039
   601
    ItemSetTraits<_FirstContainer,_FirstContainerItem>::
deba@2039
   602
    ItemNotifier::ObserverBase 
deba@2039
   603
    {
deba@2039
   604
        
deba@2039
   605
    public:
deba@2039
   606
deba@2039
   607
      friend class DynamicAsymMatrixMap;
deba@2039
   608
          
deba@2039
   609
      ///Constructor.
deba@2039
   610
      FirstKeyProxy(DynamicAsymMatrixMap& _map) : _owner(_map) { }
deba@2039
   611
    protected:
deba@2039
   612
deba@2039
   613
      ///\brief Add a new FirstKey to the map.
deba@2039
   614
      ///
deba@2039
   615
      ///It adds a new FirstKey to the map. It is called by the
deba@2039
   616
      ///observer notifier and it is ovverride the add() virtual
deba@2039
   617
      ///member function in the observer base. It will call the
deba@2039
   618
      ///maps addFirstKey() function.
deba@2039
   619
      virtual void add(const FirstKey& _firstKey){
deba@2039
   620
        _owner.addFirstKey(_firstKey);
deba@2039
   621
      }
deba@2039
   622
          
deba@2039
   623
      ///\brief Add more new FirstKey to the map.
deba@2039
   624
      ///
deba@2039
   625
      ///It adds more new FirstKey to the map. It is called by the
deba@2039
   626
      ///observer notifier and it is ovverride the add() virtual
deba@2039
   627
      ///member function in the observer base. It will call the
deba@2039
   628
      ///map's addFirstKeys() function.
deba@2039
   629
      virtual void add(const std::vector<FirstKey>& _firstKeys){
deba@2039
   630
        _owner.addFirstKeys(_firstKeys);
deba@2039
   631
      }
deba@2039
   632
          
deba@2039
   633
      ///\brief Erase a FirstKey from the map.
deba@2039
   634
      ///
deba@2039
   635
      ///Erase a FirstKey from the map. It called by the observer
deba@2039
   636
      ///notifier and it overrides the erase() virtual member
deba@2039
   637
      ///function of the observer base. It will call the map's
deba@2039
   638
      ///eraseFirstKey() function.
deba@2039
   639
      virtual void erase(const FirstKey& _firstKey){
deba@2039
   640
        _owner.eraseFirstKey(_firstKey);
deba@2039
   641
      }
deba@2039
   642
          
deba@2039
   643
      ///\brief Erase more FirstKey from the map.
deba@2039
   644
      ///
deba@2039
   645
      ///Erase more FirstKey from the map. It called by the
deba@2039
   646
      ///observer notifier and it overrides the erase() virtual
deba@2039
   647
      ///member function of the observer base. It will call the
deba@2039
   648
      ///map's eraseFirstKeys() function.
deba@2039
   649
      virtual void erase(const std::vector<FirstKey>& _firstKeys){
deba@2039
   650
        _owner.eraseFirstKeys(_firstKeys);
deba@2039
   651
      }
deba@2039
   652
          
deba@2039
   653
      ///\brief Builds the map.
deba@2039
   654
      ///
deba@2039
   655
      ///It buildes the map. It called by the observer notifier
deba@2039
   656
      ///and it overrides the build() virtual member function of
deba@2039
   657
      ///the observer base.  It will call the map's build()
deba@2039
   658
      ///function.
deba@2039
   659
      virtual void build() {
deba@2039
   660
        _owner.build();
deba@2039
   661
        //_owner.buildFirst();
deba@2039
   662
      }
deba@2039
   663
          
deba@2039
   664
      ///\brief Clear the map.
deba@2039
   665
      ///
deba@2039
   666
      ///It erases all items from the map. It called by the
deba@2039
   667
      ///observer notifier and it overrides the clear() virtual
deba@2039
   668
      ///memeber function of the observer base. It will call the
deba@2039
   669
      ///map's clear() function.
deba@2039
   670
      virtual void clear() {
deba@2039
   671
        _owner.clear();
deba@2039
   672
        //_owner.clearFirst();
deba@2039
   673
      }
deba@2039
   674
    private:
deba@2039
   675
          
deba@2039
   676
      ///The map type for it is linked.
deba@2039
   677
      DynamicAsymMatrixMap& _owner;
alpar@2072
   678
    };//END OF FIRSTKEYPROXY
deba@2039
   679
      
deba@2039
   680
      ///\brief Proxy class for the second key type.
deba@2039
   681
      ///
ladanyi@2047
   682
      ///The proxy class belongs to the SecondKey type. It is
deba@2039
   683
      ///necessary because if one want use the same conatainer types
deba@2039
   684
      ///and same nested types but on other instances of containers
deba@2039
   685
      ///than due to the type equiality of nested types it requires a
deba@2039
   686
      ///proxy mechanism.
deba@2039
   687
    class SecondKeyProxy
deba@2039
   688
      : protected 
deba@2039
   689
    ItemSetTraits<_SecondContainer, _SecondContainerItem>::
deba@2039
   690
    ItemNotifier::ObserverBase {
deba@2039
   691
        
deba@2039
   692
    public:
deba@2039
   693
deba@2039
   694
      friend class DynamicAsymMatrixMap;
deba@2039
   695
      ///Constructor.
deba@2039
   696
      SecondKeyProxy(DynamicAsymMatrixMap& _map) : _owner(_map) { }
deba@2039
   697
deba@2039
   698
    protected:
deba@2039
   699
          
deba@2039
   700
      ///\brief Add a new SecondKey to the map.
deba@2039
   701
      ///
deba@2039
   702
      ///It adds a new SecondKey to the map. It is called by the
deba@2039
   703
      ///observer notifier and it is ovverride the add() virtual
deba@2039
   704
      ///member function in the observer base. It will call the
deba@2039
   705
      ///maps addSecondKey() function.
deba@2039
   706
      virtual void add(const SecondKey& _secondKey){
deba@2039
   707
        _owner.addSecondKey(_secondKey);
deba@2039
   708
      }
deba@2039
   709
    
deba@2039
   710
      ///\brief Add more new SecondKey to the map.
deba@2039
   711
      ///
deba@2039
   712
      ///It adds more new SecondKey to the map. It is called by
deba@2039
   713
      ///the observer notifier and it is ovverride the add()
deba@2039
   714
      ///virtual member function in the observer base. It will
deba@2039
   715
      ///call the maps addSecondKeys() function.
deba@2039
   716
      virtual void add(const std::vector<SecondKey>& _secondKeys){
deba@2039
   717
        _owner.addSecondKeys(_secondKeys);
deba@2039
   718
      }
deba@2039
   719
          
deba@2039
   720
      ///\brief Erase a SecondKey from the map.
deba@2039
   721
      ///
deba@2039
   722
      ///Erase a SecondKey from the map. It called by the observer
deba@2039
   723
      ///notifier and it overrides the erase() virtual member
deba@2039
   724
      ///function of the observer base. It will call the map's
deba@2039
   725
      ///eraseSecondKey() function.
deba@2039
   726
      virtual void erase(const SecondKey& _secondKey){
deba@2039
   727
        _owner.eraseSecondKey(_secondKey);
deba@2039
   728
      }
deba@2039
   729
          
deba@2039
   730
      ///\brief Erase more SecondKeys from the map.
deba@2039
   731
      ///
deba@2039
   732
      ///Erase more SecondKey from the map. It called by the
deba@2039
   733
      ///observer notifier and it overrides the erase() virtual
deba@2039
   734
      ///member function of the observer base. It will call the
deba@2039
   735
      ///map's eraseSecondKeys() function.
deba@2039
   736
      virtual void erase(const std::vector<SecondKey>& _secondKeys){
deba@2039
   737
        _owner.eraseSecondKeys(_secondKeys);
deba@2039
   738
      }
deba@2039
   739
          
deba@2039
   740
      ///\brief Builds the map.
deba@2039
   741
      ///
deba@2039
   742
      ///It buildes the map. It called by the observer notifier
deba@2039
   743
      ///and it overrides the build() virtual member function of
deba@2039
   744
      ///the observer base.  It will call the map's build()
deba@2039
   745
      ///function.
deba@2039
   746
      virtual void build() {
deba@2039
   747
        _owner.build();
deba@2039
   748
      }
deba@2039
   749
          
deba@2039
   750
      ///\brief Clear the map.
deba@2039
   751
      ///
deba@2039
   752
      ///It erases all items from the map. It called by the
deba@2039
   753
      ///observer notifier and it overrides the clear() virtual
deba@2039
   754
      ///memeber function of the observer base. It will call the
deba@2039
   755
      ///map's clear() function.
deba@2039
   756
      virtual void clear() {
deba@2039
   757
        _owner.clear();
deba@2039
   758
        //_owner.clearFirst();
deba@2039
   759
      }
deba@2039
   760
    private:
deba@2039
   761
          
deba@2039
   762
      ///The type of map for which it is attached.
deba@2039
   763
      DynamicAsymMatrixMap& _owner;
alpar@2072
   764
    };//END OF SECONDKEYPROXY
deba@2039
   765
      
deba@2039
   766
  private:
deba@2039
   767
    
deba@2039
   768
    /// \e
deba@2039
   769
    typedef std::vector<Value> Container;
deba@2039
   770
      
deba@2039
   771
    ///The type of constainer which stores the values of the map.
deba@2039
   772
    typedef std::vector<Container> DContainer;
deba@2039
   773
deba@2039
   774
    ///The std:vector type which contains the data
deba@2039
   775
    DContainer values;
deba@2039
   776
      
deba@2039
   777
    ///Member for the first proxy class
deba@2039
   778
    FirstKeyProxy _first_key_proxy;
deba@2039
   779
      
deba@2039
   780
    ///Member for the second proxy class
deba@2039
   781
    SecondKeyProxy _second_key_proxy;
deba@2039
   782
deba@2039
   783
  public:
deba@2039
   784
    
deba@2039
   785
    ///The refernce type of the map.
deba@2039
   786
    typedef typename Container::reference Reference;
deba@2039
   787
      
deba@2039
   788
    ///The const reference type of the constainer.
deba@2039
   789
    typedef typename Container::const_reference ConstReference;
deba@2039
   790
deba@2039
   791
    ///\brief Constructor what create the map for the two containers type.
deba@2039
   792
    ///
deba@2039
   793
    ///Creates the matrix map and initialize the values with Value()
deba@2039
   794
    DynamicAsymMatrixMap(const _FirstContainer& _firstContainer, 
deba@2039
   795
                  const _SecondContainer& _secondContainer)
deba@2039
   796
      : values(DContainer(_firstContainer.maxId(FirstKey())+1,
deba@2039
   797
                          Container(_secondContainer.maxId(SecondKey())+1))),
deba@2039
   798
        _first_key_proxy(*this),
deba@2039
   799
        _second_key_proxy(*this)
deba@2039
   800
    {
deba@2039
   801
      _first_key_proxy.attach(_firstContainer.getNotifier(FirstKey()));
deba@2039
   802
      _second_key_proxy.attach(_secondContainer.getNotifier(SecondKey()));
deba@2039
   803
    }
deba@2039
   804
deba@2039
   805
    ///\brief Constructor what create the map for the two containers type.
deba@2039
   806
    ///
deba@2039
   807
    ///Creates the matrix map and initialize the values with the given _value
deba@2039
   808
    DynamicAsymMatrixMap(const _FirstContainer& _firstContainer, 
deba@2039
   809
                  const _SecondContainer& _secondContainer, 
deba@2039
   810
                  const Value& _value)
deba@2039
   811
      : values(DContainer(_firstContainer.maxId(FirstKey())+1,
deba@2039
   812
                          Container(_secondContainer.maxId(SecondKey())+1,
deba@2039
   813
                                    _value))),
deba@2039
   814
        _first_key_proxy(*this),
deba@2039
   815
        _second_key_proxy(*this)
deba@2039
   816
    {
deba@2039
   817
      _first_key_proxy.attach(_firstContainer.getNotifier(FirstKey()));
deba@2039
   818
      _second_key_proxy.attach(_secondContainer.getNotifier(SecondKey()));
deba@2039
   819
    }
deba@2039
   820
      
deba@2039
   821
    ///\brief Copy constructor.
deba@2039
   822
    ///
deba@2039
   823
    ///The copy constructor of the map.
deba@2039
   824
    DynamicAsymMatrixMap(const DynamicAsymMatrixMap& _copy) 
deba@2039
   825
      : _first_key_proxy(*this), _second_key_proxy(*this) {
deba@2039
   826
      if(_copy._first_key_proxy.attached() && 
deba@2039
   827
         _copy._second_key_proxy.attached()){
deba@2039
   828
        _first_key_proxy.attach(*_copy._first_key_proxy.getNotifier());
deba@2039
   829
        _second_key_proxy.attach(*_copy._second_key_proxy.getNotifier());
deba@2039
   830
        values = _copy.values;
deba@2039
   831
      }
deba@2039
   832
    }
deba@2039
   833
      
deba@2039
   834
    ///\brief Destructor
deba@2039
   835
    ///
deba@2039
   836
    ///Destructor what detach() from the attached objects.  May this
deba@2039
   837
    ///function is not necessary because the destructor of
deba@2039
   838
    ///ObserverBase do the same.
deba@2039
   839
    ~DynamicAsymMatrixMap() {
deba@2039
   840
      if(_first_key_proxy.attached()){
deba@2039
   841
        _first_key_proxy.detach();
deba@2039
   842
      }
deba@2039
   843
      if(_second_key_proxy.attached()){
deba@2039
   844
        _second_key_proxy.detach();
deba@2039
   845
      }
deba@2039
   846
    }
deba@2039
   847
      
deba@2039
   848
    ///\brief Gives back the value assigned to the \c first - \c
deba@2039
   849
    ///second ordered pair.
deba@2039
   850
    ///
deba@2039
   851
    ///Gives back the value assigned to the \c first - \c second
deba@2039
   852
    ///ordered pair.
deba@2039
   853
    Reference operator()(const FirstKey& _first, const SecondKey& _second) {
deba@2039
   854
      return values[_first_key_proxy.getNotifier()->id(_first)]
deba@2039
   855
        [_second_key_proxy.getNotifier()->id(_second)];
deba@2039
   856
    }
deba@2039
   857
deba@2039
   858
    ///\brief Gives back the value assigned to the \c first - \c
deba@2039
   859
    ///second ordered pair.
deba@2039
   860
    ///
deba@2039
   861
    ///Gives back the value assigned to the \c first - \c second
deba@2039
   862
    ///ordered pair.
deba@2039
   863
    ConstReference operator()(const FirstKey& _first, 
deba@2039
   864
                              const SecondKey& _second) const {
deba@2039
   865
      return values[_first_key_proxy.getNotifier()->id(_first)]
deba@2039
   866
        [_second_key_proxy.getNotifier()->id(_second)];
deba@2039
   867
    }
deba@2039
   868
deba@2039
   869
    ///\brief Setter function for this matrix map.
deba@2039
   870
    ///
deba@2039
   871
    ///Setter function for this matrix map.
deba@2039
   872
    void set(const FirstKey& first, const SecondKey& second, 
deba@2039
   873
             const Value& value){
deba@2039
   874
      values[_first_key_proxy.getNotifier()->id(first)]
deba@2039
   875
        [_second_key_proxy.getNotifier()->id(second)] = value;
deba@2039
   876
    }
deba@2039
   877
deba@2039
   878
    ///\brief The assignement operator.
deba@2039
   879
    ///
deba@2039
   880
    ///It allow to assign a map to an other. It
deba@2039
   881
    DynamicAsymMatrixMap& operator=(const DynamicAsymMatrixMap& _cmap){
deba@2039
   882
      return operator=<DynamicAsymMatrixMap>(_cmap);
deba@2039
   883
    }
deba@2039
   884
      
deba@2039
   885
    ///\brief Template assignement operator.
deba@2039
   886
    ///
deba@2039
   887
    ///It copy the element of the given map to its own container.  The
deba@2039
   888
    ///type of the two map shall be the same.
deba@2039
   889
    template <typename CMap>
deba@2039
   890
    DynamicAsymMatrixMap& operator=(const CMap& _cdmap){
alpar@2260
   891
      checkConcept<concepts::ReadMatrixMap<FirstKey, SecondKey, Value>, CMap>();
deba@2039
   892
      const typename FirstKeyProxy::Notifier* notifierFirstKey = 
deba@2039
   893
        _first_key_proxy.getNotifier();
deba@2039
   894
      const typename SecondKeyProxy::Notifier* notifierSecondKey = 
deba@2039
   895
        _second_key_proxy.getNotifier();
deba@2039
   896
      FirstKey itemFirst;
deba@2039
   897
      SecondKey itemSecond;
deba@2039
   898
      for(notifierFirstKey->first(itemFirst); itemFirst != INVALID; 
deba@2039
   899
          notifierFirstKey->next(itemFirst)){
deba@2039
   900
        for(notifierSecondKey->first(itemSecond); itemSecond != INVALID; 
deba@2039
   901
            notifierSecondKey->next(itemSecond)){
deba@2039
   902
          set(itemFirst, itemSecond, _cdmap(itemFirst,itemSecond));
deba@2039
   903
        }
deba@2039
   904
      }
deba@2039
   905
      return *this;
deba@2039
   906
    }
deba@2039
   907
      
deba@2039
   908
  protected:
deba@2039
   909
    
deba@2039
   910
    ///\brief Add a new FirstKey to the map.
deba@2039
   911
    ///
deba@2039
   912
    ///It adds a new FirstKey to the map. It is called by the observer
deba@2039
   913
    ///class belongs to the FirstKey type.
deba@2039
   914
    void addFirstKey(const FirstKey& firstKey) {
deba@2039
   915
      int size = (int)values.size();
deba@2039
   916
      if( _first_key_proxy.getNotifier()->id(firstKey)+1 >= size ){
deba@2039
   917
        values.resize(_first_key_proxy.getNotifier()->id(firstKey)+1);
deba@2039
   918
        if( (int)values[0].size() != 0 ){
deba@2039
   919
          int innersize = (int)values[0].size();
deba@2039
   920
          for(int i=size; i!=(int)values.size();++i){
deba@2039
   921
            (values[i]).resize(innersize);
deba@2039
   922
          }
deba@2039
   923
        }else if(_second_key_proxy.getNotifier()->maxId() >= 0){
deba@2039
   924
          int innersize = _second_key_proxy.getNotifier()->maxId();
deba@2039
   925
          for(int i = 0; i != (int)values.size(); ++i){
deba@2039
   926
            values[0].resize(innersize);
deba@2039
   927
          }
deba@2039
   928
        }
deba@2039
   929
      }
deba@2039
   930
    }
deba@2039
   931
deba@2039
   932
    ///\brief Adds more new FirstKeys to the map.
deba@2039
   933
    ///
deba@2039
   934
    ///It adds more new FirstKeys to the map. It called by the
deba@2039
   935
    ///observer class belongs to the FirstKey type.
deba@2039
   936
    void addFirstKeys(const std::vector<FirstKey>& firstKeys){
deba@2039
   937
      int max = values.size() - 1;
deba@2039
   938
      for(int i=0; i != (int)firstKeys.size(); ++i){
deba@2039
   939
        int id = _first_key_proxy.getNotifier()->id(firstKeys[i]);
deba@2039
   940
        if(max < id){
deba@2039
   941
          max = id;
deba@2039
   942
        }
deba@2039
   943
      }
deba@2039
   944
      int size = (int)values.size();
deba@2039
   945
      if(max >= size){
deba@2039
   946
        values.resize(max + 1);
deba@2039
   947
        if( (int)values[0].size() != 0){
deba@2039
   948
          int innersize = (int)values[0].size();
deba@2039
   949
          for(int i = size; i != (max + 1); ++i){
deba@2039
   950
            values[i].resize(innersize);
deba@2039
   951
          }
deba@2039
   952
        }else if(_second_key_proxy.getNotifier()->maxId() >= 0){
deba@2039
   953
          int innersize = _second_key_proxy.getNotifier()->maxId();
deba@2039
   954
          for(int i = 0; i != (int)values.size(); ++i){
deba@2039
   955
            values[i].resize(innersize);
deba@2039
   956
          }
deba@2039
   957
        }
deba@2039
   958
      }
deba@2039
   959
    }
deba@2039
   960
deba@2039
   961
    ///\brief Add a new SecondKey to the map.
deba@2039
   962
    ///
deba@2039
   963
    ///It adds a new SecondKey to the map. It is called by the
deba@2039
   964
    ///observer class belongs to the SecondKey type.
deba@2039
   965
    void addSecondKey(const SecondKey& secondKey) {
deba@2039
   966
      if(values.size() == 0){
deba@2039
   967
        return;
deba@2039
   968
      }
deba@2039
   969
      int id = _second_key_proxy.getNotifier()->id(secondKey);
deba@2039
   970
      if(id >= (int)values[0].size()){
deba@2039
   971
        for(int i=0;i!=(int)values.size();++i){
deba@2039
   972
          values[i].resize(id+1);
deba@2039
   973
        }
deba@2039
   974
      }
deba@2039
   975
    }
deba@2039
   976
        
deba@2039
   977
    ///\brief Adds more new SecondKeys to the map.
deba@2039
   978
    ///
deba@2039
   979
    ///It adds more new SecondKeys to the map. It called by the
deba@2039
   980
    ///observer class belongs to the SecondKey type.
deba@2039
   981
    void addSecondKeys(const std::vector<SecondKey>& secondKeys){
deba@2039
   982
      if(values.size() == 0){
deba@2039
   983
        return;
deba@2039
   984
      }
deba@2039
   985
      int max = values[0].size();
deba@2039
   986
      for(int i = 0; i != (int)secondKeys.size(); ++i){
deba@2039
   987
        int id = _second_key_proxy.getNotifier()->id(secondKeys[i]);
deba@2039
   988
        if(max < id){
deba@2039
   989
          max = id;
deba@2039
   990
        }
deba@2039
   991
      }
deba@2039
   992
      if(max > (int)values[0].size()){
deba@2039
   993
        for(int i = 0; i != (int)values.size(); ++i){
deba@2039
   994
          values[i].resize(max + 1);
deba@2039
   995
        }
deba@2039
   996
      }
deba@2039
   997
    }
deba@2039
   998
    
deba@2039
   999
    ///\brief Erase a FirstKey from the map.
deba@2039
  1000
    ///
deba@2039
  1001
    ///Erase a FirstKey from the map. It called by the observer
deba@2039
  1002
    ///class belongs to the FirstKey type.
deba@2039
  1003
    void eraseFirstKey(const FirstKey& first) {
deba@2039
  1004
      int id = _first_key_proxy.getNotifier()->id(first);
deba@2039
  1005
      for(int i = 0; i != (int)values[id].size(); ++i){
deba@2039
  1006
        values[id][i] = Value();
deba@2039
  1007
      }
deba@2039
  1008
    }
deba@2039
  1009
        
deba@2039
  1010
    ///\brief Erase more FirstKey from the map.
deba@2039
  1011
    ///
deba@2039
  1012
    ///Erase more FirstKey from the map. It called by the observer
deba@2039
  1013
    ///class belongs to the FirstKey type.
deba@2039
  1014
    void eraseFirstKeys(const std::vector<FirstKey>& firstKeys) {
deba@2039
  1015
      for(int j = 0; j != (int)firstKeys.size(); ++j){
deba@2039
  1016
        int id = _first_key_proxy.getNotifier()->id(firstKeys[j]);
deba@2039
  1017
        for(int i = 0; i != (int)values[id].size(); ++i){
deba@2039
  1018
          values[id][i] = Value();
deba@2039
  1019
        }
deba@2039
  1020
      }
deba@2039
  1021
    }
deba@2039
  1022
deba@2039
  1023
    ///\brief Erase a SecondKey from the map.
deba@2039
  1024
    ///
deba@2039
  1025
    ///Erase a SecondKey from the map. It called by the observer class
deba@2039
  1026
    ///belongs to the SecondKey type.
deba@2039
  1027
    void eraseSecondKey(const SecondKey& second) {
deba@2039
  1028
      if(values.size() == 0){
deba@2039
  1029
        return;
deba@2039
  1030
      }
deba@2039
  1031
      int id = _second_key_proxy.getNotifier()->id(second);
deba@2039
  1032
      for(int i = 0; i != (int)values.size(); ++i){
deba@2039
  1033
        values[i][id] = Value();
deba@2039
  1034
      }
deba@2039
  1035
    }
deba@2039
  1036
        
deba@2039
  1037
    ///\brief Erase more SecondKey from the map.
deba@2039
  1038
    ///
deba@2039
  1039
    ///Erase more SecondKey from the map. It called by the observer
deba@2039
  1040
    ///class belongs to the SecondKey type.
deba@2039
  1041
    void eraseSecondKeys(const std::vector<SecondKey>& secondKeys) {
deba@2039
  1042
      if(values.size() == 0){
deba@2039
  1043
        return;
deba@2039
  1044
      }
deba@2039
  1045
      for(int j = 0; j != (int)secondKeys.size(); ++j){
deba@2039
  1046
        int id = _second_key_proxy.getNotifier()->id(secondKeys[j]);
deba@2039
  1047
        for(int i = 0; i != (int)values.size(); ++i){
deba@2039
  1048
          values[i][id] = Value();
deba@2039
  1049
        }
deba@2039
  1050
      }
deba@2039
  1051
    }
deba@2039
  1052
deba@2039
  1053
    ///\brief Builds the map.
deba@2039
  1054
    ///
deba@2039
  1055
    ///It buildes the map. It is called by the observer class belongs
deba@2039
  1056
    ///to the FirstKey or SecondKey type.
deba@2039
  1057
    void build() {
deba@2039
  1058
      values.resize(_first_key_proxy.getNotifier()->maxId());
deba@2039
  1059
      for(int i=0; i!=(int)values.size(); ++i){
deba@2039
  1060
        values[i].resize(_second_key_proxy.getNotifier()->maxId());
deba@2039
  1061
      }
deba@2039
  1062
    }
deba@2039
  1063
    
deba@2039
  1064
    ///\brief Clear the map.
deba@2039
  1065
    ///
deba@2039
  1066
    ///It erases all items from the map. It is called by the observer class
deba@2039
  1067
    ///belongs to the FirstKey or SecondKey type.
deba@2039
  1068
    void clear() {
deba@2039
  1069
      for(int i=0; i!=(int)values.size(); ++i) {
deba@2039
  1070
        values[i].clear();
deba@2039
  1071
      }
deba@2039
  1072
      values.clear();
deba@2039
  1073
    }
deba@2039
  1074
 
deba@2039
  1075
  };
deba@2039
  1076
deba@2039
  1077
deba@1720
  1078
deba@1720
  1079
}
deba@1720
  1080
deba@1720
  1081
#endif