previous | start | next

A Class of Utility Functions

class MStd
{
public:
  /**
   * Opens file fname for input reads all the integers and returns
   * them in a vector.
   * @param fname - the input file name
   * @return - vector containing all integers in the input file. 
   *           If the file cannot be opened the returned vector
   *           has size 0.
   */
  static vector<int> readInts(const string& fname);

  /**
   * Linear search of the vector v for integer x.
   * @param x - integer to search for in v
   * @param v - vector of integers to search for x
   * @return  - the first index i such that v[i] == x
   *            or -1 if x is not in v.
   */
  static int lrank(int x, vector<int>& v);

  /**
   * Finds the substrings of s separated by 1 or more characters in
   * the delim string. These substrings are returned in a vector.
   * @param s - the string to split
   * @param delim - a string of characters treated as separators
   *                between the substrings to be returned.
   * @return - a vector consisting of the substrings found
   */
  static vector<string> split(const string& s, const string& delims);
};


previous | start | next