Helper function to parse cache size string (e.g., "1mb", "1gb", "1024")
| 15 | |
| 16 | // Helper function to parse cache size string (e.g., "1mb", "1gb", "1024") |
| 17 | uint64_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 |
| 42 | cache_t* createCache(const std::string& algo, const common_cache_params_t& params) { |
no test coverage detected