summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-12-01 02:36:49 -0500
committerAmlal El Mahrouss <amlal@nekernel.org>2025-12-01 02:36:49 -0500
commit2a60676b145280db364bfc048bce30b1ca64fa1e (patch)
tree3a48c80f984512ddf185e04150937ae434fda5de /include
parent3603b96c3cda0296fc64a591c375d007554bc579 (diff)
chore: source level patches of examples, library cleanup, and crc improvements.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/ocl/core/allocator_op.hpp2
-rw-r--r--include/ocl/core/config.hpp5
-rw-r--r--include/ocl/core/is_same.hpp4
-rw-r--r--include/ocl/fix/parser.hpp2
-rw-r--r--include/ocl/hashing/crc_hash.hpp (renamed from include/ocl/hashing/hash.hpp)34
5 files changed, 26 insertions, 21 deletions
diff --git a/include/ocl/core/allocator_op.hpp b/include/ocl/core/allocator_op.hpp
index 539c7e6..e25fc1c 100644
--- a/include/ocl/core/allocator_op.hpp
+++ b/include/ocl/core/allocator_op.hpp
@@ -60,7 +60,7 @@ namespace ocl
};
template <typename type>
- using allocator_type = allocator_op<type, global_new_op<type>, global_delete_op<type>>;
+ using allocator = allocator_op<type, global_new_op<type>, global_delete_op<type>>;
} // namespace ocl
#endif // ifndef _OCL_ALLOCATOR_SYSTEM_HPP \ No newline at end of file
diff --git a/include/ocl/core/config.hpp b/include/ocl/core/config.hpp
index c354672..a0ddd66 100644
--- a/include/ocl/core/config.hpp
+++ b/include/ocl/core/config.hpp
@@ -31,8 +31,3 @@
#define OCL_DECL
#define OCL_EXPORT_DECL
#endif
-
-namespace ocl
-{
- using char_type = char;
-} // namespace ocl \ No newline at end of file
diff --git a/include/ocl/core/is_same.hpp b/include/ocl/core/is_same.hpp
index e6f42c4..fdf80d7 100644
--- a/include/ocl/core/is_same.hpp
+++ b/include/ocl/core/is_same.hpp
@@ -10,7 +10,7 @@
#include <core/config.hpp>
/// @brief OCL equivalence namespace.
-namespace ocl::is_same
+namespace ocl
{
template <typename T>
struct basic_hash
@@ -103,4 +103,4 @@ namespace ocl::is_same
return left_ / right_ == 1;
}
};
-} // namespace ocl::is_same
+} // namespace ocl
diff --git a/include/ocl/fix/parser.hpp b/include/ocl/fix/parser.hpp
index 60a4f9a..9809bd5 100644
--- a/include/ocl/fix/parser.hpp
+++ b/include/ocl/fix/parser.hpp
@@ -9,7 +9,7 @@
#define _OCL_FIX_PARSER_HPP
#include <core/config.hpp>
-#include <hashing/hash.hpp>
+#include <hashing/crc_hash.hpp>
#include <io/print.hpp>
#include <algorithm>
#include <string>
diff --git a/include/ocl/hashing/hash.hpp b/include/ocl/hashing/crc_hash.hpp
index 3a29979..0322e65 100644
--- a/include/ocl/hashing/hash.hpp
+++ b/include/ocl/hashing/crc_hash.hpp
@@ -1,5 +1,5 @@
/*
- * File: hash.hpp
+ * File: crc_hash.hpp
* Purpose: Hashing module.
* Author: Amlal El Mahrouss,
* Copyright 2025, Amlal El Mahrouss, Licensed under the Boost Software License.
@@ -14,13 +14,15 @@
#include <string>
#include <cstddef>
#include <concepts>
+#include <cstring>
/// @brief Crc32 implementation in C++
/// @author Amlal El Mahrouss (amlal@nekernel.org)
namespace ocl
{
- struct hash_trait
+ /// @brief implements a trait object for crc hashing.
+ struct crc_hash_trait
{
static constexpr const std::uint16_t crc_sz_ = 256U;
@@ -59,31 +61,34 @@ namespace ocl
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d};
static std::size_t
- crc32(const char* in, size_t len) noexcept
+ crc32(const char* in, std::size_t len) noexcept
{
- if (!in || *in == 0)
+ if (!len)
return 0;
std::uint32_t crc = 0xffffffff;
+ std::size_t cnt = 0;
- while ((len--) > 0)
- crc = (crc >> 8) ^ crc_array_[(crc ^ *(in++)) & 0xFF];
+ while ((len--) > 0) {
+ crc = (crc >> 8) ^ crc_array_[(crc ^ in[cnt]) & 0xFF];
+ ++cnt;
+ }
return ~crc;
}
};
template <typename V>
- using string_hash_map = std::unordered_map<std::string, V, std::hash<ocl::hash_trait>>;
+ using string_hash_map = std::unordered_map<std::string, V, std::hash<ocl::crc_hash_trait>>;
template <typename K, typename V>
- using hash_map = std::unordered_map<K, V, std::hash<ocl::hash_trait>>;
+ using hash_map = std::unordered_map<K, V, std::hash<ocl::crc_hash_trait>>;
} // namespace ocl
namespace std
{
template <>
- struct hash<ocl::hash_trait> final
+ struct hash<ocl::crc_hash_trait> final
{
hash() = default;
~hash() = default;
@@ -91,12 +96,17 @@ namespace std
template <typename T>
inline std::size_t operator()(T* in_) const
{
- return ocl::hash_trait::crc32(reinterpret_cast<const char*>(in_), sizeof(T));
+ return ocl::crc_hash_trait::crc32(reinterpret_cast<const char*>(in_), sizeof(T));
+ }
+
+ inline std::size_t operator()(const char* in_) const
+ {
+ return ocl::crc_hash_trait::crc32(in_, strlen(in_));
}
inline std::size_t operator()(const std::string& in_) const
{
- return ocl::hash_trait::crc32(in_.c_str(), in_.size());
+ return ocl::crc_hash_trait::crc32(in_.c_str(), in_.size());
}
};
@@ -108,7 +118,7 @@ namespace std
struct is_invocable_hash : std::bool_constant <
requires(Fn fn, ArgTypes... arg_types)
{
- {std::forward<Fn>(fn)(std::forward<ArgTypes>(arg_types)...)}->std::same_as<hash<ocl::hash_trait>>;
+ {std::forward<Fn>(fn)(std::forward<ArgTypes>(arg_types)...)}->std::same_as<hash<ocl::crc_hash_trait>>;
}>{};
} // namespace std