RDFS
The Rice Comp413 2017 class' continuation on the work of the 2016 RDFS.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
util.h
1 //
2 // Created by Nicholas Kwon on 11/5/16.
3 //
4 
5 #ifndef RICE_HDFS_UTIL_H
6 #define RICE_HDFS_UTIL_H
7 #include <boost/uuid/uuid.hpp>
8 #include <boost/uuid/uuid_generators.hpp>
9 
10 namespace util {
11 
18  inline void generate_block_id(std::uint64_t &uuid) {
19  auto bytes = boost::uuids::random_generator()();
20  memcpy((&uuid), &bytes, sizeof(std::uint64_t));
21  // mask with all 1s (63 1s). This effectively sets the 64th bit to 0.
22  uuid = uuid & ((1ull << 63) - 1);
23  }
24 
31  inline std::string concat_path(const std::string& str1, const std::string& str2){
32  std::string new_path = str1;
33 
34  if (str1.back() != '/' && str2.at(0) != '/'){
35  new_path += "/";
36  }
37  else if (str1.back() == '/' && str2.at(0) == '/'){
38  new_path = str1.substr(0, str1.size() - 1);
39  }
40  new_path += str2;
41  if (new_path.at(new_path.length() - 1) == '/'){
42  new_path.pop_back();
43  }
44  return new_path;
45  }
46 }
47 #endif //RICE_HDFS_UTIL_H