Drizzled Public API Documentation

cost_vector.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #pragma once
00021 
00022 namespace drizzled {
00023 namespace optimizer {
00024 
00025 class CostVector 
00026 {
00027 public:
00028   CostVector() :
00029     io_count(0.0),
00030     avg_io_cost(1.0),
00031     cpu_cost(0.0),
00032     mem_cost(0.0),
00033     import_cost(0.0)
00034   {}
00035 
00036   double total_cost() const
00037   {
00038     return IO_COEFF*io_count*avg_io_cost + CPU_COEFF * cpu_cost +
00039       MEM_COEFF*mem_cost + IMPORT_COEFF*import_cost;
00040   }
00041 
00042   void zero()
00043   {
00044     avg_io_cost= 1.0;
00045     io_count= cpu_cost= mem_cost= import_cost= 0.0;
00046   }
00047 
00048   void multiply(double m)
00049   {
00050     io_count *= m;
00051     cpu_cost *= m;
00052     import_cost *= m;
00053     /* Don't multiply mem_cost */
00054   }
00055 
00056   void add(const CostVector* cost)
00057   {
00058     double io_count_sum= io_count + cost->io_count;
00059     add_io(cost->io_count, cost->avg_io_cost);
00060     io_count= io_count_sum;
00061     cpu_cost += cost->cpu_cost;
00062   }
00063   void add_io(double add_io_cnt, double add_avg_cost)
00064   {
00065     double io_count_sum= io_count + add_io_cnt;
00066     avg_io_cost= (io_count * avg_io_cost +
00067                   add_io_cnt * add_avg_cost) / io_count_sum;
00068     io_count= io_count_sum;
00069   }
00070 
00071   /* accessor methods*/
00072   void setIOCount(double m)
00073   {
00074      io_count= m;
00075   }
00076   double getIOCount() const 
00077   {
00078      return io_count;
00079   }
00080   void setAvgIOCost(double m)
00081   {
00082      avg_io_cost= m;
00083   }
00084   double getAvgIOCost() const 
00085   {
00086      return avg_io_cost;
00087   }
00088   void setCpuCost(double m)
00089   { 
00090      cpu_cost= m;
00091   }
00092   double getCpuCost() const
00093   {
00094      return cpu_cost;
00095   }
00096   void setMemCost(double m)
00097   { 
00098      mem_cost= m;
00099   }
00100   double getMemCost() const
00101   {
00102      return mem_cost;
00103   }
00104   void setImportCost(double m)
00105   {
00106      import_cost= m;
00107   }
00108   double getImportCost() const
00109   {
00110      return import_cost;
00111   }
00112 
00113 private:
00114 
00115   double io_count;     /* number of I/O                 */
00116   double avg_io_cost;  /* cost of an average I/O oper.  */
00117   double cpu_cost;     /* cost of operations in CPU     */
00118   double mem_cost;     /* cost of used memory           */
00119   double import_cost;  /* cost of remote operations     */
00120 
00121   static const uint32_t IO_COEFF=1;
00122   static const uint32_t CPU_COEFF=1;
00123   static const uint32_t MEM_COEFF=1;
00124   static const uint32_t IMPORT_COEFF=1;
00125 
00126 };
00127 } /* namespace optimizer */
00128 } /* namespace drizzled */
00129