Refactored descriptor ID generation and added IDs to peripherals, register groups and registers
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#include <iomanip>
|
||||
#include <ranges>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <mutex>
|
||||
|
||||
namespace Services
|
||||
{
|
||||
@@ -100,9 +102,16 @@ namespace Services
|
||||
return static_cast<std::uint8_t>(StringService::toUint64(str, base));
|
||||
}
|
||||
|
||||
std::size_t StringService::hash(const std::string& str) {
|
||||
static const auto hash = std::hash<std::string>{};
|
||||
return hash(str);
|
||||
std::size_t StringService::generateUniqueInteger(const std::string& str) {
|
||||
static auto mutex = std::mutex{};
|
||||
|
||||
static auto lastValue = std::size_t{0};
|
||||
static auto map = std::unordered_map<std::string, std::size_t>{};
|
||||
|
||||
const auto lock = std::unique_lock{mutex};
|
||||
|
||||
const auto valueIt = map.find(str);
|
||||
return valueIt != map.end() ? valueIt->second : map.emplace(str, ++lastValue).first->second;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> StringService::split(std::string_view str, char delimiter) {
|
||||
|
||||
@@ -29,7 +29,29 @@ namespace Services
|
||||
static std::uint16_t toUint16(const std::string& str, int base = 0);
|
||||
static std::uint8_t toUint8(const std::string& str, int base = 0);
|
||||
|
||||
static std::size_t hash(const std::string& str);
|
||||
/**
|
||||
* Generates a unique integer from a given string.
|
||||
*
|
||||
* This function will return the same value for matching strings.
|
||||
* That is: If strA == strB, then generateUniqueInteger(strA) == generateUniqueInteger(strB).
|
||||
*
|
||||
* This function does *not* return a hash of the string. We can't use hashes because they're not unique due to
|
||||
* collisions.
|
||||
*
|
||||
* The returned value will only be unique for the duration of the current execution cycle.
|
||||
* That means generateUniqueInteger(strA) != generateUniqueInteger(strA) if the functions are called within
|
||||
* different execution cycles.
|
||||
*
|
||||
* The generated value isn't actually derived from the string itself. It's just an integer that we produce and
|
||||
* keep record of, in a key-value store. See the implementation for more.
|
||||
*
|
||||
* The purpose of this function is to generate internal integer IDs for entities within Bloom, such as address
|
||||
* spaces and memory segments. These IDs have no meaning to the user or any other external entity.
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
static std::size_t generateUniqueInteger(const std::string& str);
|
||||
|
||||
static std::vector<std::string_view> split(std::string_view str, char delimiter);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user