This class contains miscellaneous utility methods.
More...
#include <Util.h>
List of all members.
Static Public Member Functions |
static bool | skipSpace (istream &in, bool=false) |
| Skip over space characters in input stream.
|
static bool | skipBlank (istream &in) |
| Advance to the first non-blank character, skipping over comments.
|
static bool | readWord (istream &, string &, bool=false) |
| Read next word from input stream.
|
static bool | readInt (istream &, int &, bool=false) |
| Read an integer from the input stream.
|
static bool | verify (istream &, char c, bool=false) |
| Verify the next non-space input character.
|
static bool | prefix (string &, string &) |
| Test if one string is a prefix of another.
|
static int | strnlen (char *, int) |
| Replacement for the missing strnlen function.
|
static void | genPerm (int, int *) |
| Create random permutation on integers 1..n and return in p.
|
static uint32_t | getTime () |
| Return time expressed as a free-running microsecond clock.
|
static void | warning (const string &) |
static void | fatal (const string &) |
static double | randfrac () |
| Generate a random fraction.
|
static int | randint (int, int) |
| Generate a random integer in a range.
|
static double | randexp (double) |
static int | randgeo (double) |
| Return a random number from a geometric distribution.
|
static int | randTruncGeo (double, int) |
| Return a random number from a truncated geometric distribution with mean 1/p and maximum value k.
|
static double | randpar (double, double) |
| Return a random number from a Pareto distribution with mean mu and shape s.
|
Static Public Attributes |
static const int32_t | BIGINT32 = 0x7ffffff |
Detailed Description
This class contains miscellaneous utility methods.
Definition at line 20 of file Util.h.
Member Function Documentation
uint32_t grafalgo::Util::getTime |
( |
| ) |
[static] |
Return time expressed as a free-running microsecond clock.
Uses the gettimeofday system call, but converts result to simple microsecond clock for greater convenience.
Definition at line 138 of file Util.cpp.
bool grafalgo::Util::prefix |
( |
string & |
s1, |
|
|
string & |
s2 |
|
) |
| [static] |
Test if one string is a prefix of another.
- Parameters:
-
s1 | is a reference to a string |
s2 | is a reference to another string |
- Returns:
- true if s1 is a non-empty prefix of s2, else false.
Definition at line 110 of file Util.cpp.
double grafalgo::Util::randfrac |
( |
| ) |
[inline, static] |
Generate a random fraction.
- Returns:
- a double in [0,1]
Definition at line 63 of file Util.h.
int grafalgo::Util::randgeo |
( |
double |
p | ) |
[inline, static] |
Return a random number from a geometric distribution.
- Parameters:
-
p | is success probability (so 1/p is mean) |
- Returns:
- a random value from the distribution
Definition at line 82 of file Util.h.
int grafalgo::Util::randint |
( |
int |
lo, |
|
|
int |
hi |
|
) |
| [inline, static] |
Generate a random integer in a range.
- Parameters:
-
lo | is the low end of the range |
hi | is the high end of the range |
- Returns:
- a random integer in [lo,hi]; the distribution is not very uniform for ranges larger than 10^7
Definition at line 71 of file Util.h.
bool grafalgo::Util::readInt |
( |
istream & |
in, |
|
|
int & |
i, |
|
|
bool |
sameline = false |
|
) |
| [static] |
Read an integer from the input stream.
- Parameters:
-
in | is an open input stream |
i | is an int in which result is returned |
sameline | is an optional argument; if it is true, do not scan past the end of the line; default is false |
- Returns:
- true on success, else false
Definition at line 75 of file Util.cpp.
bool grafalgo::Util::readWord |
( |
istream & |
in, |
|
|
string & |
s, |
|
|
bool |
sameline = false |
|
) |
| [static] |
Read next word from input stream.
A word is a non-blank string starting with an alpha and including alphas, digits, forward slashes and underscores.
- Parameters:
-
in | is an open input stream |
s | is a string in which result is returned |
sameline | is an optional argument; if it is true, do not scan past the end of the line; default is false |
- Returns:
- true on success, else false
Definition at line 55 of file Util.cpp.
bool grafalgo::Util::skipBlank |
( |
istream & |
in | ) |
[static] |
Advance to the first non-blank character, skipping over comments.
Leave the non-blank character in the input stream. A comment is anything that starts with the sharp sign '#' and continues to the end of the line. Return false on error or eof.
Definition at line 34 of file Util.cpp.
bool grafalgo::Util::skipSpace |
( |
istream & |
in, |
|
|
bool |
sameline = false |
|
) |
| [static] |
Skip over space characters in input stream.
- Parameters:
-
in | is an open input stream |
sameline | is an optional argument; if it is true, do not skip past the end of the line; the default is false |
- Returns:
- true if we find a non-space character before eof or error, else false
Definition at line 20 of file Util.cpp.
bool grafalgo::Util::verify |
( |
istream & |
in, |
|
|
char |
c, |
|
|
bool |
strict = false |
|
) |
| [static] |
Verify the next non-space input character.
- Parameters:
-
in | is an open input stream |
c | is the expected next non-blank character |
strict | is an optional flag; if true, then we don't skip over space characters; default is false |
- Returns:
- true if c is present in the input, else false; if c is found, it is read and discarded, otherwise the character checked is left in the input stream
Definition at line 96 of file Util.cpp.
The documentation for this class was generated from the following files:
- /Users/jst/src/grafalgo/cpp/include/Util.h
- /Users/jst/src/grafalgo/cpp/misc/Util.cpp