char data[len]
バイナリファイルから読み取られた解凍済みデータからデータが取り込まれています。data
はこれらのタイプのみであることがわかっています: char, uchar, short, ushort, int, uint, float, double
( ) を表すのに必要な正確なビット数を知っていelesize = {8, 16, 32, 64}
ます。
max()
データリストをトラバースして、たとえば、min()
特定の数値の出現回数を見つけたいだけです。メモリ空間の問題のために別の配列を作成せずにこれを行いたいです。
私は次のことを思いつきましたが、たとえば遅いですlen == 34560000
だから、誰かが「ワンライナー」またはこれを行うためのより効率的な方法(CまたはC ++のいずれか)を持っているかどうか疑問に思っていました。
char data[len];
double mymax = -std::numeric_limits<double>::max()
for (size_t i=0; i<len; i += elesize)
{
double x;
char *r = data+i;
if (elementtype == "char")
x = static_cast<double>(*r);
else if (elementtype == "uchar")
x = static_cast<double>(*((unsigned char *)r));
else if (elementtype == "short")
x = static_cast<double>(*((int16_t *)r));
else if (elementtype == "ushort")
x = static_cast<double>(*((uint16_t *)r));
else if (elementtype == "int")
x = static_cast<double>(*((int32_t *)r));
else if (elementtype == "uint")
x = static_cast<double>(*((uint32_t *)r));
else if (elementtype == "float")
x = static_cast<double>(*((float *)r));
else if (elementtype == "double")
x = *((double *)r);
if (x > mymax)
mymax = x;
}