BAN: Add math to its own namespace
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
#include <BAN/String.h>
|
||||
#include <BAN/StringView.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace BAN
|
||||
@@ -200,7 +199,7 @@ namespace BAN
|
||||
{
|
||||
if (m_capasity >= size)
|
||||
return {};
|
||||
size_type new_cap = BAN::max<size_type>(size, m_capasity * 1.5f);
|
||||
size_type new_cap = BAN::Math::max<size_type>(size, m_capasity * 1.5f);
|
||||
void* new_data = BAN::allocator(new_cap);
|
||||
if (new_data == nullptr)
|
||||
return Error::FromString("String: Could not allocate memory");
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include <BAN/StringView.h>
|
||||
#include <BAN/Vector.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace BAN
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <BAN/Errors.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace BAN
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace BAN
|
||||
namespace BAN::Math
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
@@ -21,4 +21,23 @@ namespace BAN
|
||||
return x < min ? min : x > max ? max : x;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T gcd(T a, T b)
|
||||
{
|
||||
T t;
|
||||
while (b)
|
||||
{
|
||||
t = b;
|
||||
b = a % b;
|
||||
a = t;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T lcm(T a, T b)
|
||||
{
|
||||
return a / gcd(a, b) * b;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,11 +9,11 @@
|
||||
namespace BAN
|
||||
{
|
||||
#if defined(__is_kernel)
|
||||
static constexpr auto& allocator = kmalloc;
|
||||
static constexpr auto& deallocator = kfree;
|
||||
static constexpr void*(&allocator)(size_t) = kmalloc;
|
||||
static constexpr void(&deallocator)(void*) = kfree;
|
||||
#else
|
||||
static constexpr auto& allocator = malloc;
|
||||
static constexpr auto& deallocator = free;
|
||||
static constexpr void*(&allocator)(size_t) = malloc;
|
||||
static constexpr void(&deallocator)(void*) = free;
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <BAN/Math.h>
|
||||
#include <BAN/Memory.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -96,7 +95,7 @@ namespace BAN
|
||||
if (m_capacity > size)
|
||||
return {};
|
||||
|
||||
size_type new_cap = BAN::max<size_type>(m_capacity * 1.5f, m_capacity + 1);
|
||||
size_type new_cap = BAN::Math::max<size_type>(m_capacity * 1.5f, m_capacity + 1);
|
||||
void* new_data = BAN::allocator(new_cap * sizeof(T));
|
||||
if (new_data == nullptr)
|
||||
return Error::FromString("Queue: Could not allocate memory");
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <BAN/Math.h>
|
||||
#include <BAN/Memory.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace BAN
|
||||
@@ -208,7 +207,7 @@ namespace BAN
|
||||
{
|
||||
if (m_capasity >= size)
|
||||
return {};
|
||||
size_type new_cap = BAN::max<size_type>(size, m_capasity * 1.5f);
|
||||
size_type new_cap = BAN::Math::max<size_type>(size, m_capasity * 1.5f);
|
||||
void* new_data = BAN::allocator(new_cap * sizeof(T));
|
||||
if (new_data == nullptr)
|
||||
return Error::FromString("Vector: Could not allocate memory");
|
||||
|
||||
Reference in New Issue
Block a user