mp_sketching
Supreme sketching
utils.h File Reference

Support functions that the autograder will have access to You should not modify this file (it wont be included in your submission) More...

Functions

std::string file_to_string (const std::string &filename)
 Takes a filename and reads in all the text from the file Newline characters are also just characters in ASCII. More...
 
std::string trim_right (const std::string &str)
 Functions for the removal of whitespace to the left or right of a string (or both) More...
 
std::string trim_left (const std::string &str)
 
std::string trim (const std::string &str)
 
int split_string (const std::string &str1, char sep, std::vector< std::string > &fields)
 Given a string and character, split the string by the character and store in a vector A 'split' string treats the character as a breakpoint and creates a separate item in the output vector for each substring. More...
 
std::vector< int > readFile (std::string fname)
 Given a filename to a line-separated text file, create a vector of integers where each row in the text file is an entry in the vector. More...
 
uint64_t hash_seeded (const int *key, uint64_t seed)
 Built using MurmurHash3 A generalizable hash function that can be passed different seed inputs. More...
 
uint64_t hash_1 (int key)
 Built using MurmurHash3 Specific hash functions that can be used without specifying seeds The autograder will be built around these to limit the args that need to be passed. More...
 
uint64_t hash_2 (int key)
 
uint64_t hash_3 (int key)
 
uint64_t hash_4 (int key)
 
uint64_t hash_5 (int key)
 
uint64_t hash_6 (int key)
 
uint64_t hash_500 (int key)
 
uint64_t hash_1000 (int key)
 
uint64_t simple (int key)
 

Detailed Description

Support functions that the autograder will have access to You should not modify this file (it wont be included in your submission)

Function Documentation

◆ file_to_string()

std::string file_to_string ( const std::string &  filename)

Takes a filename and reads in all the text from the file Newline characters are also just characters in ASCII.

Parameters
filenameThe name of the file that will fill the string
Returns
A string containing the whole text of the given file

◆ hash_1()

uint64_t hash_1 ( int  key)

Built using MurmurHash3 Specific hash functions that can be used without specifying seeds The autograder will be built around these to limit the args that need to be passed.

Ex: You should expect hash functions to take in one arg (an int) and return a hash value.

Parameters
keyThe integer being hashed
Returns
A uint64_t hash encoding of the key.

◆ hash_seeded()

uint64_t hash_seeded ( const int *  key,
uint64_t  seed 
)

Built using MurmurHash3 A generalizable hash function that can be passed different seed inputs.

Will likely be good (but not great) since using only 64-bits of a 128-bit hash.

Parameters
keyThe integer being hashed
seedThe uint64_t defining the seed of the hash.
Returns
A uint64_t hash encoding of the key.

◆ readFile()

std::vector< int > readFile ( std::string  fname)

Given a filename to a line-separated text file, create a vector of integers where each row in the text file is an entry in the vector.

You may assume the text file contains only numbers.

Your vector should match the exact structure of the input file – so the first row of the file should correspond to the 0th index of the vector.

Parameters
filenameThe filename of the text file.
Returns
A vector of integers whose order matches the input file

◆ split_string()

int split_string ( const std::string &  str1,
char  sep,
std::vector< std::string > &  fields 
)

Given a string and character, split the string by the character and store in a vector A 'split' string treats the character as a breakpoint and creates a separate item in the output vector for each substring.

NOTE: The separator character is not included in the substrings.

The total number of substrings created (the length of fields) is returned

Parameters
str1The string being split
sepThe separator character
fieldsThe string vector storing all substrings created by the split
Returns
The number of substrings created

◆ trim_right()

std::string trim_right ( const std::string &  str)

Functions for the removal of whitespace to the left or right of a string (or both)

Parameters
strThe string being processed
Returns
The processed string