-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandard.hpp
More file actions
77 lines (69 loc) · 2.87 KB
/
standard.hpp
File metadata and controls
77 lines (69 loc) · 2.87 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Graduate student @ Thomas J. Watson College of Engineering and Applied
* Sciences, Binghamton University.
*
* author: Gregory Maldonado
* email : gmaldonado@cs.binghamton.edu
* date : 2024-02-14
*
* Copyright 2024 GREGORY MALDONADO
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <iostream>
#include <map>
#include <vector>
#include <string>
//======== GM ========================================================== 80 ====
/**
* Parses a single line of text into the "key" part and the "value" part. The
* requirements are that the key is a string wrapped within quotations. The
* value part is an integer value with r'[0]*' leading and/or trailing.
* #parse(string, map<string, vector<string>*>*) modifies the
* unordred_map parameter.
* This implementation is deemed "standard" and utilized the C++ standard lib
* for computation. Although the C++ standard lib is convient, there is massive
* overhead. This implementation could be deemed "slow" for the C++ standard lib
* overhead.
*
* @param line: const std::string& => text to be parsed.
*
* @param parse_map: std::map<std::string,
std::vector<std::string>* >*
=> map containing parsed lines.
@note: parse_map is mutated.
*/
void parse(const std::string& line,
std::map<std::string, std::vector<std::string>*,
std::less<std::string> >* parse_map);
/**
* Reduces a map containing { key, vector<int> } to { key, int }. The reduction
* is a max_element on the vector.
*
* @param parse_map: std::map<std::string, std::vector<std::string>*,
std::less<std::string>>*
=> map containing parsed lines.
@returns reduced parsed_map to a single max integer.
*/
std::map<std::string, std::string>
reduce(std::map<std::string, std::vector<std::string>*,
std::less<std::string>>* parse_map);
/**
* Cout operator overload for a resulting map.
*
* @param map: std::ostream& oss, std::map<std::string, std::string,
std::less<std::string>>
=> resulting map to be written to stdout.
*
* @returns ostream.
*/
std::ostream& operator<<(std::ostream& oss,
std::map<std::string, std::string,
std::less<std::string>> map);
//======== GM ========================================================== 80 ====