~drizzle-trunk/drizzle/development

1336.3.3 by Djellel E. Difallah
add file ./drizzled/optimizer/cost_vector.h
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
1336.3.3 by Djellel E. Difallah
add file ./drizzled/optimizer/cost_vector.h
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
20
#pragma once
1336.3.3 by Djellel E. Difallah
add file ./drizzled/optimizer/cost_vector.h
21
2318.8.7 by Olaf van der Spek
Add const
22
namespace drizzled {
23
namespace optimizer {
1336.3.3 by Djellel E. Difallah
add file ./drizzled/optimizer/cost_vector.h
24
2318.8.7 by Olaf van der Spek
Add const
25
class CostVector 
26
{
1336.3.3 by Djellel E. Difallah
add file ./drizzled/optimizer/cost_vector.h
27
public:
28
  CostVector() :
29
    io_count(0.0),
30
    avg_io_cost(1.0),
31
    cpu_cost(0.0),
32
    mem_cost(0.0),
33
    import_cost(0.0)
34
  {}
35
2318.8.7 by Olaf van der Spek
Add const
36
  double total_cost() const
1336.3.3 by Djellel E. Difallah
add file ./drizzled/optimizer/cost_vector.h
37
  {
38
    return IO_COEFF*io_count*avg_io_cost + CPU_COEFF * cpu_cost +
39
      MEM_COEFF*mem_cost + IMPORT_COEFF*import_cost;
40
  }
41
42
  void zero()
43
  {
44
    avg_io_cost= 1.0;
45
    io_count= cpu_cost= mem_cost= import_cost= 0.0;
46
  }
47
48
  void multiply(double m)
49
  {
50
    io_count *= m;
51
    cpu_cost *= m;
52
    import_cost *= m;
53
    /* Don't multiply mem_cost */
54
  }
55
56
  void add(const CostVector* cost)
57
  {
58
    double io_count_sum= io_count + cost->io_count;
59
    add_io(cost->io_count, cost->avg_io_cost);
60
    io_count= io_count_sum;
61
    cpu_cost += cost->cpu_cost;
62
  }
63
  void add_io(double add_io_cnt, double add_avg_cost)
64
  {
65
    double io_count_sum= io_count + add_io_cnt;
66
    avg_io_cost= (io_count * avg_io_cost +
67
                  add_io_cnt * add_avg_cost) / io_count_sum;
68
    io_count= io_count_sum;
69
  }
70
71
  /* accessor methods*/
72
  void setIOCount(double m)
73
  {
74
     io_count= m;
75
  }
76
  double getIOCount() const 
77
  {
78
     return io_count;
79
  }
80
  void setAvgIOCost(double m)
81
  {
82
     avg_io_cost= m;
83
  }
84
  double getAvgIOCost() const 
85
  {
86
     return avg_io_cost;
87
  }
88
  void setCpuCost(double m)
89
  { 
90
     cpu_cost= m;
91
  }
92
  double getCpuCost() const
93
  {
94
     return cpu_cost;
95
  }
96
  void setMemCost(double m)
97
  { 
98
     mem_cost= m;
99
  }
100
  double getMemCost() const
101
  {
102
     return mem_cost;
103
  }
104
  void setImportCost(double m)
105
  {
106
     import_cost= m;
107
  }
108
  double getImportCost() const
109
  {
110
     return import_cost;
111
  }
112
113
private:
114
115
  double io_count;     /* number of I/O                 */
116
  double avg_io_cost;  /* cost of an average I/O oper.  */
117
  double cpu_cost;     /* cost of operations in CPU     */
118
  double mem_cost;     /* cost of used memory           */
119
  double import_cost;  /* cost of remote operations     */
120
121
  static const uint32_t IO_COEFF=1;
122
  static const uint32_t CPU_COEFF=1;
123
  static const uint32_t MEM_COEFF=1;
124
  static const uint32_t IMPORT_COEFF=1;
125
126
};
127
} /* namespace optimizer */
128
} /* namespace drizzled */
129