MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / parseCacheSize

Function parseCacheSize

libCacheSim-node/binding.cc:17–39  ·  view source on GitHub ↗

Helper function to parse cache size string (e.g., "1mb", "1gb", "1024")

Source from the content-addressed store, hash-verified

15
16// Helper function to parse cache size string (e.g., "1mb", "1gb", "1024")
17uint64_t parseCacheSize(const std::string& sizeStr) {
18 if (sizeStr.empty()) return 0;
19
20 std::string lower = sizeStr;
21 std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
22
23 // Extract number and unit
24 size_t pos = 0;
25 while (pos < lower.length() && (isdigit(lower[pos]) || lower[pos] == '.')) {
26 pos++;
27 }
28
29 double value = std::stod(lower.substr(0, pos));
30 std::string unit = lower.substr(pos);
31
32 uint64_t multiplier = 1;
33 if (unit == "kb" || unit == "k") multiplier = 1024;
34 else if (unit == "mb" || unit == "m") multiplier = 1024 * 1024;
35 else if (unit == "gb" || unit == "g") multiplier = 1024 * 1024 * 1024;
36 else if (unit == "tb" || unit == "t") multiplier = 1024ULL * 1024 * 1024 * 1024;
37
38 return (uint64_t)(value * multiplier);
39}
40
41// Helper function to get cache constructor by algorithm name
42cache_t* createCache(const std::string& algo, const common_cache_params_t& params) {

Callers 1

runSimulationFunction · 0.85

Calls 3

emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected