Exemple #1
0
// This function takes a column value and if necessary adjusts it based on rules defined in the requirements.
// The values are adjusted so that one can be subtracted from another to find a range, compare, etc.
uint64_t RowEstimator::adjustValue(const execplan::CalpontSystemCatalog::ColType& ct,
							   const uint64_t& value)
{
	switch(ct.colDataType)
	{
		// Use day precision for dates.  We'll use day relative to the year 0 without worrying about leap
		// years.  This is for row count estimation and we are close enough for hand grenades.
		case CalpontSystemCatalog::DATE:
		{
			dataconvert::Date dt(value);
			return dt.year * 365 + daysThroughMonth(dt.month - 1) + dt.day;
		}

		// Use second precision for datetime estimates.  We'll use number of seconds since the year 0
		// without worrying about leap years.
		case CalpontSystemCatalog::DATETIME:
		{
			dataconvert::DateTime dtm(value);
			// 86,400 seconds in a day.
			return (dtm.year * 365 + daysThroughMonth(dtm.month - 1) + dtm.day - 1) * 86400 +
					dtm.hour * 3600 + dtm.minute * 60 + dtm.second;
		}

		// Use the first character only for estimating chars and varchar ranges.
        	// TODO:  Use dictionary column HWM for dictionary columns.
		case CalpontSystemCatalog::CHAR:
		case CalpontSystemCatalog::VARCHAR:
			// Last byte is the first character in the string.
			return (0xFF & value);
		default:
			return value;
	}
}
Exemple #2
0
void find_bridges(const Graph &g, UnaryFunction output_bridge) {

  const size_t num_v = g.num_vertices();
  size_t time = 0;
  std::vector<size_t> pred(num_v, SIZE_MAX);
  std::vector<size_t> dtm(num_v);
  std::vector<size_t> low(num_v);

  std::function<void(size_t)> dfs_visit;
  dfs_visit = [&](const size_t src) {
    low[src] = dtm[src] = ++time;
    for (const auto e : g.out_edges(src)) {
      const size_t tgt = (src == g.source(e)) ? g.target(e) : g.source(e);
      if (!dtm[tgt]) {
        pred[tgt] = src;
        dfs_visit(tgt);
        low[src] = std::min(low[src], low[tgt]);
        if (low[tgt] > dtm[src])
          output_bridge(e);
      } else if (tgt != pred[src])
        low[src] = std::min(low[src], dtm[tgt]);
    }
  };

  for (size_t v = 0; v != num_v; ++v)
    if (!dtm[v])
      dfs_visit(v);
}