field.cpp
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 2,240 行 · 第 1/5 页
CPP
2,240 行
void div(const ifield& a, int b, ifield& c, ifield& d){
const size_t l = a.Length();
c = ifield(l);
d = ifield(l);
for (register i=0; i<l; i++){
c[i] = a[i]/b;
d[i] = a[i]%b;
}
}
// @(#)i_div_ff.C 1.1 Release Date: 2/19/93
void div(const ifield& a, const ifield& b, ifield& c, ifield& d){
const size_t l = a.Length();
assert(l == b.Length());
c = ifield(l);
d = ifield(l);
for (register i=0; i<l; i++){
c[i] = a[i]/b[i];
d[i] = a[i]%b[i];
}
}
// @(#)i_eq.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield& ifield::operator=(const ifield& f){
if (!f.root){
Free();
root = NULL;
}else if (this == &f){
return *this;
}else if (f.ref_flag){
Free();
root = f.root->NewCopy();
}else{
Free();
root = f.root;
f.root->ref_count++;
}
ref_flag = 0;
return *this;
}
// @(#)i_eq_d.C 1.1 Release Date: 2/26/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield& ifield::operator=(INT fill){
if (root){
if (root->ref_count > 1) Private();
ref_flag = 0;
const size_t l = root->length;
for (register i=0; i<l; i++) root->data[i] = fill;
}
return *this;
}
// @(#)i_eq_i.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield& ifield::operator=(const field& f){
if (!f.root){
Free();
root = NULL;
}else{
Free();
root = new(f.root->length) __field_inode(f.root->length);
for (register i=0; i<root->length; i++)
root->data[i] = (int)f.root->data[i];
}
ref_flag = 0;
return *this;
}
// @(#)i_gather_1.C 1.1 Release Date: 2/19/93
ifield ifield::Gather(const ifield& ia) const {
size_t l = ia.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = root->data[ia[i]];
return rtn;
}
// @(#)i_gather_2.C 1.1 Release Date: 2/19/93
ifield ifield::Gather(size_t start, size_t end, size_t stride) const {
assert(end < root->length);
ifield rtn((end-start)/stride + 1);
INT *rp = rtn;
const INT* This = *this;
for (register i=start, j=0; i<end; i+=stride,j++) rp[j] = This[i];
return rtn;
}
// @(#)i_ge_df.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator>=(INT b, const ifield& a){
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = (b >= a.root->data[i]);
return rtn;
}
// @(#)i_ge_fd.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator>=(const ifield& a, INT b){
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = (a.root->data[i] >= b);
return rtn;
}
// @(#)i_ge_ff.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator>=(const ifield& a, const ifield& b){
size_t l = a.root->length;
assert(l == b.root->length);
ifield rtn(l);
for (register i=0; i<l; i++)
rtn.root->data[i] = (a.root->data[i] >= b.root->data[i]);
return rtn;
}
// @(#)i_gt_df.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator>(INT b, const ifield& a){
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = (b > a.root->data[i]);
return rtn;
}
// @(#)i_gt_fd.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator>(const ifield& a, INT b){
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = (a.root->data[i] > b);
return rtn;
}
// @(#)i_gt_ff.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator>(const ifield& a, const ifield& b){
size_t l = a.root->length;
assert(l == b.root->length);
ifield rtn(l);
for (register i=0; i<l; i++)
rtn.root->data[i] = (a.root->data[i] > b.root->data[i]);
return rtn;
}
// @(#)i_io.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
// I/O
size_t fread(ifield& f, FILE* d){
int length;
size_t rtn;
f.Free();
rtn = fread((char*)&length, sizeof(size_t), 1, d);
f.root = new(length) __field_inode(length);
rtn += fread((char*)f.root->data, sizeof(INT), length, d);
f.ref_flag = 0;
return (rtn == f.root->length+1? 1 : 0);
}
size_t fwrite(const ifield& f, FILE* d){
size_t rtn;
if (f.Length() != 0){
rtn = fwrite((char*)&f.root->length, sizeof(size_t), 1, d);
rtn += fwrite((char*)&(f.root->data[0]), sizeof(INT), f.root->length, d);
return (rtn == f.root->length+1? 1 : 0);
}else{
const size_t ZERO = 0;
rtn = fwrite((char*)&ZERO, sizeof(size_t), 1, d);
return (rtn == 1? 1 : 0);
}
}
// @(#)i_itof.C 1.2 Release Date: 2/19/93
ifield::ifield(const field& a) :
ref_flag(0)
{
if (a.root){
const size_t l = a.root->length;
root = new(l) __field_inode(l);
for (register i=0; i<l; i++) root->data[i] = (int)a.root->data[i];
}else{
root = NULL;
}
}
// @(#)i_land_df.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator&&(INT d, const ifield& a){
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = (a.root->data[i] && d);
return rtn;
}
// @(#)i_land_fd.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator&&(const ifield& a, INT d){
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = (a.root->data[i] && d);
return rtn;
}
// @(#)i_land_ff.C 1.2 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator&&(const ifield& a, const ifield& b){
assert(a.root->length == b.root->length);
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++)
rtn.root->data[i] = (a.root->data[i] && b.root->data[i]);
return rtn;
}
// @(#)i_le_df.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator<=(INT b, const ifield& a){
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = (b <= a.root->data[i]);
return rtn;
}
// @(#)i_le_fd.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator<=(const ifield& a, INT b){
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = (a.root->data[i] <= b);
return rtn;
}
// @(#)i_le_ff.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator<=(const ifield& a, const ifield& b){
size_t l = a.root->length;
assert(l == b.root->length);
ifield rtn(l);
for (register i=0; i<l; i++)
rtn.root->data[i] = (a.root->data[i] <= b.root->data[i]);
return rtn;
}
// @(#)i_leq_df.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator==(INT b, const ifield& a){
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = (b == a.root->data[i]);
return rtn;
}
// @(#)i_leq_fd.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator==(const ifield& a, INT b){
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = (a.root->data[i] == b);
return rtn;
}
// @(#)i_leq_ff.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator==(const ifield& a, const ifield& b){
size_t l = a.root->length;
assert(l == b.root->length);
ifield rtn(l);
for (register i=0; i<l; i++)
rtn.root->data[i] = (a.root->data[i] == b.root->data[i]);
return rtn;
}
// @(#)i_lne_df.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator!=(INT b, const ifield& a){
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = (b != a.root->data[i]);
return rtn;
}
// @(#)i_lne_fd.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator!=(const ifield& a, INT b){
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = (a.root->data[i] != b);
return rtn;
}
// @(#)i_lne_ff.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator!=(const ifield& a, const ifield& b){
size_t l = a.root->length;
assert(l == b.root->length);
ifield rtn(l);
for (register i=0; i<l; i++)
rtn.root->data[i] = (a.root->data[i] != b.root->data[i]);
return rtn;
}
// @(#)i_lor_df.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator||(INT d, const ifield& a){
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = (a.root->data[i] || d);
return rtn;
}
// @(#)i_lor_fd.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator||(const ifield& a, INT d){
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = (a.root->data[i] || d);
return rtn;
}
// @(#)i_lor_ff.C 1.2 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator||(const ifield& a, const ifield& b){
assert(a.root->length == b.root->length);
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++)
rtn.root->data[i] = (a.root->data[i] || b.root->data[i]);
return rtn;
}
// @(#)i_ls_d.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield& ifield::operator<<=(INT d){
assert(root!=NULL);
Private();
size_t l = root->length;
for (register i=0; i<l; i++) root->data[i] <<= d;
return *this;
}
// @(#)i_ls_df.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield operator<<(INT d, const ifield& a){
size_t l = a.root->length;
ifield rtn(l);
for (register i=0; i<l; i++) rtn.root->data[i] = (d << a.root->data[i]);
return rtn;
}
// @(#)i_ls_f.C 1.1 Release Date: 2/19/93
// Author: Kent G. Budge,
// Computational Physics Research and Development (1431)
// Sandia National Laboratories
ifield& ifield::operator<<=(const i
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?