-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.h
More file actions
59 lines (47 loc) · 1.45 KB
/
util.h
File metadata and controls
59 lines (47 loc) · 1.45 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef UTIL_H
#define UTIL_H
#include <string>
#include <iostream>
#include <set>
/** Complete the setIntersection and setUnion functions below
* in this header file (since they are templates).
* Both functions should run in time O(n*log(n)) and not O(n^2)
*/
template <typename T>
std::set<T> setIntersection(std::set<T>& s1, std::set<T>& s2)
{
typename std::set<T> iset;
typename std::set<T>::iterator it;
for(it = s1.begin(); it != s1.end(); ++it){
if(s2.find(*it) != s2.end()){
iset.insert(*it);
}
}
return iset;
}
template <typename T>
std::set<T> setUnion(std::set<T>& s1, std::set<T>& s2)
{
typename std::set<T> uset;
typename std::set<T>::iterator it;
for(it = s1.begin(); it != s1.end(); ++it){
uset.insert(*it);
}
for(it = s2.begin(); it != s2.end(); ++it){
uset.insert(*it);
}
return uset;
}
/***********************************************/
/* Prototypes of functions defined in util.cpp */
/***********************************************/
std::string convToLower(std::string src);
std::set<std::string> parseStringToWords(std::string line);
// Used from http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring
// Removes any leading whitespace
std::string <rim(std::string &s) ;
// Removes any trailing whitespace
std::string &rtrim(std::string &s) ;
// Removes leading and trailing whitespace
std::string &trim(std::string &s) ;
#endif