-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility.h
More file actions
44 lines (36 loc) · 845 Bytes
/
Utility.h
File metadata and controls
44 lines (36 loc) · 845 Bytes
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
#ifndef UTILITY_H
#define UTILITY_H
// DO NOT CHANGE THIS FILE
#include <stdexcept>
#include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <stdlib.h>
using std::string;
using std::vector;
using std::runtime_error;
using std::cout;
using std::endl;
using std::queue;
inline string printStyle(const string& s, size_t max_length) {
size_t buffer = max_length - s.size();
string retval("");
if (buffer % 2U != 0) {
retval += string(" ");
buffer--;
}
retval += string(buffer / 2U, ' ');
retval += s;
retval += string(buffer / 2U, ' ');
return retval;
}
inline size_t hashFunction(const string& username, size_t capacity) {
size_t retval = 0;
for (size_t i = 0; i < username.length(); i++) {
retval = 37 * retval + size_t(username[i]);
retval %= capacity;
}
return retval;
}
#endif // !UTILITY_H