lemon/bits/default_map.h
author Balazs Dezso <deba@google.com>
Sat, 27 Oct 2018 13:00:48 +0200
changeset 1203 8c567e298d7f
parent 877 141f9c0db4a3
permissions -rw-r--r--
Paremeter to stop matching calculation when only single node is unmatched
alpar@209
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@57
     2
 *
alpar@209
     3
 * This file is a part of LEMON, a generic C++ optimization library.
deba@57
     4
 *
alpar@1092
     5
 * Copyright (C) 2003-2013
deba@57
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@57
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@57
     8
 *
deba@57
     9
 * Permission to use, modify and distribute this software is granted
deba@57
    10
 * provided that this copyright notice appears in all copies. For
deba@57
    11
 * precise terms see the accompanying LICENSE file.
deba@57
    12
 *
deba@57
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@57
    14
 * express or implied, and with no claim as to its suitability for any
deba@57
    15
 * purpose.
deba@57
    16
 *
deba@57
    17
 */
deba@57
    18
deba@57
    19
#ifndef LEMON_BITS_DEFAULT_MAP_H
deba@57
    20
#define LEMON_BITS_DEFAULT_MAP_H
deba@57
    21
alpar@502
    22
#include <lemon/config.h>
deba@57
    23
#include <lemon/bits/array_map.h>
deba@57
    24
#include <lemon/bits/vector_map.h>
deba@57
    25
//#include <lemon/bits/debug_map.h>
deba@57
    26
kpeter@314
    27
//\ingroup graphbits
kpeter@314
    28
//\file
kpeter@314
    29
//\brief Graph maps that construct and destruct their elements dynamically.
deba@57
    30
deba@57
    31
namespace lemon {
alpar@209
    32
alpar@209
    33
deba@57
    34
  //#ifndef LEMON_USE_DEBUG_MAP
deba@57
    35
deba@57
    36
  template <typename _Graph, typename _Item, typename _Value>
deba@57
    37
  struct DefaultMapSelector {
deba@57
    38
    typedef ArrayMap<_Graph, _Item, _Value> Map;
deba@57
    39
  };
deba@57
    40
deba@57
    41
  // bool
deba@57
    42
  template <typename _Graph, typename _Item>
deba@57
    43
  struct DefaultMapSelector<_Graph, _Item, bool> {
deba@57
    44
    typedef VectorMap<_Graph, _Item, bool> Map;
deba@57
    45
  };
deba@57
    46
deba@57
    47
  // char
deba@57
    48
  template <typename _Graph, typename _Item>
deba@57
    49
  struct DefaultMapSelector<_Graph, _Item, char> {
deba@57
    50
    typedef VectorMap<_Graph, _Item, char> Map;
deba@57
    51
  };
deba@57
    52
deba@57
    53
  template <typename _Graph, typename _Item>
deba@57
    54
  struct DefaultMapSelector<_Graph, _Item, signed char> {
deba@57
    55
    typedef VectorMap<_Graph, _Item, signed char> Map;
deba@57
    56
  };
deba@57
    57
deba@57
    58
  template <typename _Graph, typename _Item>
deba@57
    59
  struct DefaultMapSelector<_Graph, _Item, unsigned char> {
deba@57
    60
    typedef VectorMap<_Graph, _Item, unsigned char> Map;
deba@57
    61
  };
deba@57
    62
deba@57
    63
deba@57
    64
  // int
deba@57
    65
  template <typename _Graph, typename _Item>
deba@57
    66
  struct DefaultMapSelector<_Graph, _Item, signed int> {
deba@57
    67
    typedef VectorMap<_Graph, _Item, signed int> Map;
deba@57
    68
  };
deba@57
    69
deba@57
    70
  template <typename _Graph, typename _Item>
deba@57
    71
  struct DefaultMapSelector<_Graph, _Item, unsigned int> {
deba@57
    72
    typedef VectorMap<_Graph, _Item, unsigned int> Map;
deba@57
    73
  };
deba@57
    74
deba@57
    75
deba@57
    76
  // short
deba@57
    77
  template <typename _Graph, typename _Item>
deba@57
    78
  struct DefaultMapSelector<_Graph, _Item, signed short> {
deba@57
    79
    typedef VectorMap<_Graph, _Item, signed short> Map;
deba@57
    80
  };
deba@57
    81
deba@57
    82
  template <typename _Graph, typename _Item>
deba@57
    83
  struct DefaultMapSelector<_Graph, _Item, unsigned short> {
deba@57
    84
    typedef VectorMap<_Graph, _Item, unsigned short> Map;
deba@57
    85
  };
deba@57
    86
deba@57
    87
deba@57
    88
  // long
deba@57
    89
  template <typename _Graph, typename _Item>
deba@57
    90
  struct DefaultMapSelector<_Graph, _Item, signed long> {
deba@57
    91
    typedef VectorMap<_Graph, _Item, signed long> Map;
deba@57
    92
  };
deba@57
    93
deba@57
    94
  template <typename _Graph, typename _Item>
deba@57
    95
  struct DefaultMapSelector<_Graph, _Item, unsigned long> {
deba@57
    96
    typedef VectorMap<_Graph, _Item, unsigned long> Map;
deba@57
    97
  };
deba@57
    98
deba@57
    99
ladanyi@511
   100
#if defined LEMON_HAVE_LONG_LONG
deba@57
   101
deba@57
   102
  // long long
deba@57
   103
  template <typename _Graph, typename _Item>
deba@57
   104
  struct DefaultMapSelector<_Graph, _Item, signed long long> {
deba@57
   105
    typedef VectorMap<_Graph, _Item, signed long long> Map;
deba@57
   106
  };
deba@57
   107
deba@57
   108
  template <typename _Graph, typename _Item>
deba@57
   109
  struct DefaultMapSelector<_Graph, _Item, unsigned long long> {
deba@57
   110
    typedef VectorMap<_Graph, _Item, unsigned long long> Map;
deba@57
   111
  };
deba@57
   112
deba@57
   113
#endif
deba@57
   114
deba@57
   115
deba@57
   116
  // float
deba@57
   117
  template <typename _Graph, typename _Item>
deba@57
   118
  struct DefaultMapSelector<_Graph, _Item, float> {
deba@57
   119
    typedef VectorMap<_Graph, _Item, float> Map;
deba@57
   120
  };
deba@57
   121
deba@57
   122
deba@57
   123
  // double
deba@57
   124
  template <typename _Graph, typename _Item>
deba@57
   125
  struct DefaultMapSelector<_Graph, _Item, double> {
deba@57
   126
    typedef VectorMap<_Graph, _Item,  double> Map;
deba@57
   127
  };
deba@57
   128
deba@57
   129
deba@57
   130
  // long double
deba@57
   131
  template <typename _Graph, typename _Item>
deba@57
   132
  struct DefaultMapSelector<_Graph, _Item, long double> {
deba@57
   133
    typedef VectorMap<_Graph, _Item, long double> Map;
deba@57
   134
  };
deba@57
   135
deba@57
   136
deba@57
   137
  // pointer
deba@57
   138
  template <typename _Graph, typename _Item, typename _Ptr>
deba@57
   139
  struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
deba@57
   140
    typedef VectorMap<_Graph, _Item, _Ptr*> Map;
deba@57
   141
  };
deba@57
   142
alpar@209
   143
// #else
deba@57
   144
deba@57
   145
//   template <typename _Graph, typename _Item, typename _Value>
deba@57
   146
//   struct DefaultMapSelector {
deba@57
   147
//     typedef DebugMap<_Graph, _Item, _Value> Map;
deba@57
   148
//   };
deba@57
   149
alpar@209
   150
// #endif
deba@57
   151
kpeter@314
   152
  // DefaultMap class
deba@57
   153
  template <typename _Graph, typename _Item, typename _Value>
alpar@209
   154
  class DefaultMap
deba@57
   155
    : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
kpeter@617
   156
    typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
kpeter@617
   157
deba@57
   158
  public:
deba@57
   159
    typedef DefaultMap<_Graph, _Item, _Value> Map;
alpar@877
   160
kpeter@617
   161
    typedef typename Parent::GraphType GraphType;
deba@57
   162
    typedef typename Parent::Value Value;
deba@57
   163
kpeter@617
   164
    explicit DefaultMap(const GraphType& graph) : Parent(graph) {}
kpeter@617
   165
    DefaultMap(const GraphType& graph, const Value& value)
deba@57
   166
      : Parent(graph, value) {}
deba@57
   167
deba@57
   168
    DefaultMap& operator=(const DefaultMap& cmap) {
deba@57
   169
      return operator=<DefaultMap>(cmap);
deba@57
   170
    }
deba@57
   171
deba@57
   172
    template <typename CMap>
deba@57
   173
    DefaultMap& operator=(const CMap& cmap) {
deba@57
   174
      Parent::operator=(cmap);
deba@57
   175
      return *this;
deba@57
   176
    }
deba@57
   177
deba@57
   178
  };
deba@57
   179
deba@57
   180
}
deba@57
   181
deba@57
   182
#endif