File: utilityfunc.cpp

package info (click to toggle)
nxtrim 0.4.3%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 360 kB
  • sloc: cpp: 1,593; python: 142; sh: 97; makefile: 43
file content (35 lines) | stat: -rwxr-xr-x 549 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "utilityfunc.h"

using namespace std;

int argmax(vector<double> & x) {
  int maxind=0;
  for(int i=1;i<(int)x.size();i++) 
    if(x[i]>x[maxind]) maxind=i;
  return(maxind);
}


int which_max(int *x,int n) {
  int maxidx = 0;
  int maxval = x[maxidx];
  for(int i=0;i<n;i++) {
    if(x[i]>maxval) {
      maxidx = i;
      maxval = x[i];
    }
  }
  return maxidx;
}



bool fileexists(string fname){
  ifstream ifile(fname.c_str());
  return ifile.good();
}

void die(const string & err) {
  cerr << "ERROR: "<< err << endl;
  exit(1);
}