qsmall.cpp

来自「算断裂的」· C++ 代码 · 共 181 行

CPP
181
字号
// ------------------------------------------------------------------// qsmall.cpp//// This file contains member functions associated with the small// classes in qsmall.h.// ------------------------------------------------------------------// Author: Stephen A. Vavasis// Copyright (c) 1999 by Cornell University.  All rights reserved.// // See the accompanying file 'Copyright' for authorship information,// the terms of the license governing this software, and disclaimers// concerning this software.// ------------------------------------------------------------------// This file is part of the QMG software.  // Version 2.0 of QMG, release date September 3, 1999.// ------------------------------------------------------------------#include "qsmall.h"namespace {  using namespace QMG;  using namespace QMG::MG;    // not used  void k_d_tree_scramble(const IntCoord& b2,     UInt32 dest[MAXDIM],    int di) {      {        for (int i = 0; i < di; ++i) {          dest[i] = 0;        }      }      {        for (int i = 0; i < di; ++i) {          for (int j = 0; j < 32; ++j) {            int p = (31 - j) * di + i;            int i1 = p >> 5;            int j1 = p & 31;            if (b2[i] & (1 << j))              dest[i1] |= (1 << (31 - j1));          }        }      }  }}namespace QMG {  namespace MG {    void small_initialize_static_data(int di);  }}QMG::MG::Base3 QMG::MG::Base3::merge(Base3 a, Base3 b) {  Base3 result = 0;  for (int i = 0; i < di_; ++i)    if (a[i] != b[i])      result.set_digit(i,2);    else      result.set_digit(i,b[i]);    return result;}void QMG::MG::Base3::output(ostream& os, int dim) const {  for (int i = 0; i < dim; ++i)    os << (*this)[i];}void QMG::MG::Mask::initialize_static_data(int di) {  zero = 0;  di_ = di;  if (di < 0 || di > MAXDIM)    throw_error("Could not initialize Mask static data; embedded_dim out of range");  diexp_ = 1 << di;  for (Mask i = 0; i < diexp_; ++i) {    r_dims_[i] = 0;    for (int j = 0; j < di; j++) {      if (i[j] == 0)        r_dims_[i]++;    }  }}// ------------------------------------------------------------------// initialize_static_data (static member function)// This routine initializes static data associated with// Base-3 conversion.// ------------------------------------------------------------------void QMG::MG::Base3::initialize_static_data(int di) {  di_ = di;  if (di < 0 || di > MAXDIM)    throw_error("Could not initialize Base3 static data; embedded_dim out of range");    int k = 1;  {    for (int i = 0; i <= di; i++) {      powers_3_[i] = k;      k *= 3;    }  }  di3exp_ = powers_3_[di];  for (Base3 rindex = 0; rindex < di3exp_; ++rindex) {    UInt32 rindex1 = rindex;    r_flatdims[rindex] = 0;    r_dims[rindex] = 0;    for (int i = 0; i < di; i++) {      int dig = rindex1 % 3;      base_3_digits[rindex][i] = dig;      rindex1 /= 3;      if (dig < 2)        r_flatdims[rindex].set_bit(i);      else        r_dims[rindex]++;    }  }}/*int QMG::MG::IntCoord::compare(const IntCoord& a, const IntCoord& b) {  UInt32 a_kd[MAXDIM], b_kd[MAXDIM];  k_d_tree_scramble(a, a_kd, di_);  k_d_tree_scramble(b, b_kd, di_);  if (a_kd[0] < b_kd[0]) return -1;  if (a_kd[0] > b_kd[0]) return 1;  if (a_kd[1] < b_kd[1]) return -1;  if (a_kd[1] > b_kd[1]) return 1;  if (di_ == 2) return 0;  if (a_kd[2] < b_kd[2]) return -1;  if (a_kd[2] > b_kd[2]) return 1;  return 0;}  */int QMG::MG::IntCoord::compare(const IntCoord& a, const IntCoord& b) {  if (a[0] < b[0]) return -1;  if (a[0] > b[0]) return 1;  if (a[1] < b[1]) return -1;  if (a[1] > b[1]) return 1;  if (di_ == 2) return 0;  if (a[2] < b[2]) return -1;  if (a[2] > b[2]) return 1;  return 0;}void QMG::MG::IntCoord::increment(int dim, int level) {#ifdef RANGECHECK  if (dim < 0 || dim >= di_ ||     level < 0 || level > MAXLEV)    throw_error("argument out of range in IntCoord::increment");#endif  intcoord_[dim] += (1 << (MAXLEV - level));}void QMG::MG::small_initialize_static_data(int di) {  Mask::initialize_static_data(di);  Base3::initialize_static_data(di);  IntCoord::initialize_static_data(di);}int QMG::MG::Base3::base_3_digits[MAXDIM_3EXP][MAXDIM];QMG::UInt32 QMG::MG::Base3::powers_3_[MAXDIM + 1];int QMG::MG::Base3::r_dims[MAXDIM_3EXP];QMG::MG::Mask QMG::MG::Base3::r_flatdims[MAXDIM_3EXP];int QMG::MG::Base3::di_;QMG::UInt32 QMG::MG::Base3::di3exp_;int QMG::MG::Mask::r_dims_[MAXDIM_EXP];QMG::UInt32 QMG::MG::Mask::diexp_;int QMG::MG::Mask::di_;QMG::MG::Mask QMG::MG::Mask::zero;int QMG::MG::IntCoord::di_;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?