begenning the refactor

This commit is contained in:
Kbz-8
2024-03-27 23:03:54 +01:00
parent b5983ac24b
commit 0e04356ea7
131 changed files with 2135 additions and 1192 deletions

69
runtime/Includes/Utils/ConstMap.h git.filemode.normal_file
View File

@@ -0,0 +1,69 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ConstMap.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 15:26:39 by maldavid #+# #+# */
/* Updated: 2024/03/27 21:59:35 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_CONST_MAP__
#define __MLX_CONST_MAP__
namespace mlx
{
template<typename Key, typename Value>
class ConstMap
{
public:
using ValueType = std::pair<Key, Value>;
using ContainerType = std::vector<ValueType>;
using iterator = typename ContainerType::const_iterator;
using const_iterator = iterator;
public:
ConstMap(std::initializer_list<ValueType> init) : m_container(init)
{
std::sort(m_container.begin(), m_container.end());
}
ConstMap(ContainerType container) : m_container(std::move(container))
{
std::sort(m_container.begin(), m_container.end());
}
inline const_iterator begin() const { return m_container.begin(); }
inline const_iterator end() const { return m_container.end(); }
template<typename K>
inline const_iterator Find(const K& key) const
{
const_iterator it = std::lower_bound(begin(), end(), key,
[](const ValueType& p, const K& key)
{
return p.first < key;
}
);
return it != end() && it->first == key ? it : end();
}
template<typename K>
inline bool Has(const K& key) const
{
return Find(key) != end();
}
inline std::size_t Size() const { return m_container.size(); }
~ConstMap() = default;
private:
ContainerType m_container;
};
}
#endif