Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
Documented the Utils.cpp file.
  • Loading branch information
DuarteSAssuncao committed Oct 26, 2023
1 parent 4bfbd46 commit 00049d9
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/Utils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#include "Utils.hpp"
// djb2 hash : https://theartincode.stanis.me/008-djb2/

/**
* @file
* This file defines some functions that are gonna be useful in other classes
*/


/**
* This function converts a string to a 8 bit hash.
* This algorithm (djb2 hash) is better explained here: https://theartincode.stanis.me/008-djb2/
* @param s
* @tparam std::string
* @return the string converted to hash
*/
uint8_t hash_str(std::string s) {
uint64_t hash = 5381;
for (char c : s) {
Expand All @@ -8,8 +21,22 @@ uint8_t hash_str(std::string s) {
return (uint8_t)(hash % 256);
}

/**
* This function checks if a given character in a number.
* @param c
* @tparam uint32_t
* @return bool
*/
bool isnum(uint32_t c) { return (c >= '0' && c <= '9'); }

/**
* This function reads a line of the csv file given in the parameter std::string s and appends to the vector passed
* by reference res the comma separated values of the line
* @param s
* @tparam std::string
* @param res
* @tparam std::vector<std::string>
*/
void parse_csv_line(std::string s, std::vector<std::string> &res) {
std::stringstream line(s);
std::string buf;
Expand Down

0 comments on commit 00049d9

Please sign in to comment.