Browse Source

Use size_t

Kajetan Johannes Hammerle 1 week ago
parent
commit
902f82114b
50 changed files with 640 additions and 633 deletions
  1. 6 7
      include/core/data/Array.hpp
  2. 11 13
      include/core/data/ArrayList.hpp
  3. 10 10
      include/core/data/Components.hpp
  4. 15 12
      include/core/data/HashMap.hpp
  5. 2 2
      include/core/data/LinkedList.hpp
  6. 28 26
      include/core/data/List.hpp
  7. 22 20
      include/core/data/ProbingHashMap.hpp
  8. 12 12
      include/core/data/RingBuffer.hpp
  9. 2 2
      include/core/data/Stack.hpp
  10. 3 2
      include/core/math/BufferedValue.hpp
  11. 1 1
      include/core/math/Matrix.hpp
  12. 1 1
      include/core/math/MatrixStack.hpp
  13. 17 18
      include/core/math/Vector.hpp
  14. 6 5
      include/core/utils/AlignedData.hpp
  15. 40 39
      include/core/utils/ArrayString.hpp
  16. 8 10
      include/core/utils/Buffer.hpp
  17. 2 2
      include/core/utils/Clock.hpp
  18. 12 22
      include/core/utils/Color.hpp
  19. 23 17
      include/core/utils/Error.hpp
  20. 15 15
      include/core/utils/HashCode.hpp
  21. 8 9
      include/core/utils/HashedString.hpp
  22. 4 2
      include/core/utils/Logger.hpp
  23. 8 4
      include/core/utils/Random.hpp
  24. 1 0
      include/core/utils/Types.hpp
  25. 17 21
      include/core/utils/Utility.hpp
  26. 1 1
      performance/Main.cpp
  27. 77 87
      src/ArrayString.cpp
  28. 3 1
      src/BitArray.cpp
  29. 3 3
      src/Box.cpp
  30. 8 5
      src/Buffer.cpp
  31. 5 2
      src/Error.cpp
  32. 3 2
      src/ErrorSimulator.cpp
  33. 4 4
      src/Matrix.cpp
  34. 3 2
      src/Mutex.cpp
  35. 34 8
      src/Random.cpp
  36. 6 5
      src/Thread.cpp
  37. 19 32
      src/Utility.cpp
  38. BIN
      test/.Test.hpp.swo
  39. 2 2
      test/Main.cpp
  40. 2 2
      test/Test.hpp
  41. 42 42
      test/modules/ArrayListTests.cpp
  42. 18 18
      test/modules/ArrayStringTests.cpp
  43. 13 12
      test/modules/ArrayTests.cpp
  44. 4 4
      test/modules/BufferTests.cpp
  45. 27 25
      test/modules/ErrorTests.cpp
  46. 1 1
      test/modules/HashedStringTests.cpp
  47. 39 39
      test/modules/LinkedListTests.cpp
  48. 41 42
      test/modules/ListTests.cpp
  49. 8 8
      test/modules/RandomTests.cpp
  50. 3 14
      test/modules/UtilityTests.cpp

+ 6 - 7
include/core/data/Array.hpp

@@ -4,10 +4,9 @@
 #include "core/utils/ArrayString.hpp"
 
 namespace Core {
-    template<typename T, i64 N>
+    template<typename T, size_t N>
     class Array final {
-        static_assert(N > 0, "Array size must be positive");
-        T data[static_cast<u64>(N)];
+        T data[N];
 
     public:
         constexpr Array() = default;
@@ -17,16 +16,16 @@ namespace Core {
         }
 
         constexpr void fill(const T& t) {
-            for(i64 i = 0; i < N; i++) {
+            for(size_t i = 0; i < N; i++) {
                 data[i] = t;
             }
         }
 
-        constexpr T& operator[](i64 index) {
+        constexpr T& operator[](size_t index) {
             return data[index];
         }
 
-        constexpr const T& operator[](i64 index) const {
+        constexpr const T& operator[](size_t index) const {
             return data[index];
         }
 
@@ -46,7 +45,7 @@ namespace Core {
             return data + N;
         }
 
-        static constexpr i64 getLength() {
+        static constexpr size_t getLength() {
             return N;
         }
 

+ 11 - 13
include/core/data/ArrayList.hpp

@@ -5,12 +5,10 @@
 #include "core/utils/ArrayString.hpp"
 
 namespace Core {
-    template<typename T, i64 N>
+    template<typename T, size_t N>
     class ArrayList final {
-        static_assert(N > 0, "ArrayList size must be positive");
-
-        AlignedType<T> data[static_cast<u64>(N)];
-        i64 length;
+        AlignedType<T> data[N];
+        size_t length;
 
     public:
         ArrayList() : length(0) {
@@ -77,27 +75,27 @@ namespace Core {
             return put(t, Core::forward<Args>(args)...);
         }
 
-        T& operator[](i64 index) {
+        T& operator[](size_t index) {
             return begin()[index];
         }
 
-        const T& operator[](i64 index) const {
+        const T& operator[](size_t index) const {
             return begin()[index];
         }
 
-        i64 getLength() const {
+        size_t getLength() const {
             return length;
         }
 
         void clear() {
-            for(i64 i = 0; i < length; i++) {
+            for(size_t i = 0; i < length; i++) {
                 begin()[i].~T();
             }
             length = 0;
         }
 
-        check_return Error removeBySwap(i64 index) {
-            if(index < 0 || index >= length) {
+        check_return Error removeBySwap(size_t index) {
+            if(index >= length) {
                 return ErrorCode::INVALID_INDEX;
             }
             length--;
@@ -119,13 +117,13 @@ namespace Core {
 
     private:
         void copy(const ArrayList& other) {
-            for(i64 i = 0; i < other.length; i++) {
+            for(size_t i = 0; i < other.length; i++) {
                 (void)add(other[i]);
             }
         }
 
         void move(ArrayList&& other) {
-            for(i64 i = 0; i < other.length; i++) {
+            for(size_t i = 0; i < other.length; i++) {
                 (void)add(Core::move(other[i]));
             }
         }

+ 10 - 10
include/core/data/Components.hpp

@@ -8,7 +8,7 @@ namespace Core {
 
     template<typename T>
     class Components final {
-        HashMap<Entity, i64> entityToIndex{};
+        HashMap<Entity, size_t> entityToIndex{};
         List<Entity> indexToEntity{};
         List<T> components{};
 
@@ -22,10 +22,10 @@ namespace Core {
         template<typename C, typename R>
         class EntityIterator final {
             C& components;
-            i64 index;
+            size_t index;
 
         public:
-            EntityIterator(C& components_, i64 index_)
+            EntityIterator(C& components_, size_t index_)
                 : components(components_), index(index_) {
             }
 
@@ -60,8 +60,8 @@ namespace Core {
 
         template<typename... Args>
         check_return Error put(T*& t, Entity ent, Args&&... args) {
-            i64 index = components.getLength();
-            i64* indexP = nullptr;
+            size_t index = components.getLength();
+            size_t* indexP = nullptr;
             CORE_RETURN_ERROR(entityToIndex.tryEmplace(indexP, ent, index));
             Error e = ErrorCode::NONE;
             if(checkError(e, indexToEntity.add(ent))) {
@@ -82,12 +82,12 @@ namespace Core {
         }
 
         check_return Error remove(Entity ent) {
-            i64* indexP = entityToIndex.search(ent);
+            size_t* indexP = entityToIndex.search(ent);
             if(indexP == nullptr) {
                 return ErrorCode::NOT_FOUND;
             }
-            i64 lastIndex = components.getLength() - 1;
-            i64 index = *indexP;
+            size_t lastIndex = components.getLength() - 1;
+            size_t index = *indexP;
             CORE_RETURN_ERROR(entityToIndex.remove(ent));
             CORE_RETURN_ERROR(components.removeBySwap(index));
             if(index == lastIndex) {
@@ -99,7 +99,7 @@ namespace Core {
         }
 
         T* search(Entity e) {
-            i64* index = entityToIndex.search(e);
+            size_t* index = entityToIndex.search(e);
             if(index == nullptr) {
                 return nullptr;
             }
@@ -107,7 +107,7 @@ namespace Core {
         }
 
         const T* search(Entity e) const {
-            const i64* index = entityToIndex.search(e);
+            const size_t* index = entityToIndex.search(e);
             if(index == nullptr) {
                 return nullptr;
             }

+ 15 - 12
include/core/data/HashMap.hpp

@@ -127,16 +127,21 @@ namespace Core {
             return ErrorCode::NONE;
         }
 
-        check_return Error rehash(i64 minCapacity) {
+        check_return Error rehash(size_t minCapacity) {
             if(minCapacity <= nodePointers.getLength()) {
                 return ErrorCode::NONE;
             }
             HashMap<K, V> map;
-            i64 l = 1l << Math::roundUpLog2(Core::Math::max(minCapacity, 8l));
+            size_t shifts =
+                Math::roundUpLog2(Core::Math::max(minCapacity, 8lu));
+            if(shifts >= 48) {
+                return ErrorCode::CAPACITY_REACHED;
+            }
+            size_t l = 1lu << shifts;
             CORE_RETURN_ERROR(map.nodePointers.resize(l));
             for(NodePointerList& list : nodePointers) {
                 for(NodePointer& n : list) {
-                    i64 h = map.hashIndex(n->data.key);
+                    size_t h = map.hashIndex(n->data.key);
                     CORE_RETURN_ERROR(map.nodePointers[h].add(n));
                 }
             }
@@ -147,7 +152,7 @@ namespace Core {
         template<typename... Args>
         check_return Error tryEmplace(V*& v, const K& key, Args&&... args) {
             CORE_RETURN_ERROR(rehash(nodes.getLength() + 1));
-            i64 h = hashIndex(key);
+            size_t h = hashIndex(key);
             v = searchList(key, h);
             if(v != nullptr) {
                 return ErrorCode::EXISTING_KEY;
@@ -166,7 +171,7 @@ namespace Core {
         template<typename VA>
         check_return Error put(V*& v, const K& key, VA&& value) {
             CORE_RETURN_ERROR(rehash(nodes.getLength() + 1));
-            i64 h = hashIndex(key);
+            size_t h = hashIndex(key);
             v = searchList(key, h);
             if(v != nullptr) {
                 *v = Core::forward<VA>(value);
@@ -191,7 +196,7 @@ namespace Core {
 
         check_return Error remove(const K& key) {
             NodePointerList& list = nodePointers[hashIndex(key)];
-            for(i64 i = 0; i < list.getLength(); i++) {
+            for(size_t i = 0; i < list.getLength(); i++) {
                 if(list[i]->data.key == key) {
                     nodes.remove(list[i]);
                     return list.removeBySwap(i);
@@ -255,13 +260,11 @@ namespace Core {
 
     private:
         template<typename H>
-        i64 hashIndex(const H& key) const {
-            return static_cast<i64>(
-                hashCode(key) &
-                (static_cast<u64>(nodePointers.getLength()) - 1));
+        size_t hashIndex(const H& key) const {
+            return hashCode(key) & (nodePointers.getLength() - 1);
         }
 
-        const V* searchList(const K& key, i64 h) const {
+        const V* searchList(const K& key, size_t h) const {
             if(nodePointers.getLength() == 0) {
                 return nullptr;
             }
@@ -273,7 +276,7 @@ namespace Core {
             return nullptr;
         }
 
-        V* searchList(const K& key, i64 h) {
+        V* searchList(const K& key, size_t h) {
             return const_cast<V*>(
                 static_cast<const HashMap*>(this)->searchList(key, h));
         }

+ 2 - 2
include/core/data/LinkedList.hpp

@@ -48,7 +48,7 @@ namespace Core {
     private:
         Node* first;
         Node* last;
-        i64 length;
+        size_t length;
 
     public:
         LinkedList() : first(nullptr), last(nullptr), length(0) {
@@ -120,7 +120,7 @@ namespace Core {
             return {nullptr};
         }
 
-        i64 getLength() const {
+        size_t getLength() const {
             return length;
         }
 

+ 28 - 26
include/core/data/List.hpp

@@ -4,13 +4,14 @@
 #include "core/math/Math.hpp"
 #include "core/utils/AlignedData.hpp"
 #include "core/utils/ArrayString.hpp"
+#include "core/utils/Error.hpp"
 #include "core/utils/New.hpp"
 
 namespace Core {
     template<typename T>
     class List final {
-        i64 length;
-        i64 capacity;
+        size_t length;
+        size_t capacity;
         T* data;
 
     public:
@@ -39,7 +40,7 @@ namespace Core {
             List copy;
             CORE_RETURN_ERROR(allocate(copy.data, other.capacity));
             copy.capacity = other.capacity;
-            for(i64 i = 0; i < other.length; i++) {
+            for(size_t i = 0; i < other.length; i++) {
                 copy.unsafeAdd(other[i]);
             }
             swap(copy);
@@ -62,7 +63,7 @@ namespace Core {
             return data + length;
         }
 
-        check_return Error reserve(i64 n) {
+        check_return Error reserve(size_t n) {
             if(n <= capacity) {
                 return ErrorCode::NONE;
             }
@@ -76,14 +77,14 @@ namespace Core {
             return setSize(length);
         }
 
-        check_return Error resize(i64 n, const T& t) {
+        check_return Error resize(size_t n, const T& t) {
             if(length < n) {
                 CORE_RETURN_ERROR(reserve(n));
-                for(i64 i = n - length; i != 0; i--) {
+                for(size_t i = n - length; i != 0; i--) {
                     unsafeAdd(t);
                 }
             } else if(length > n) {
-                for(i64 i = n; i < length; i++) {
+                for(size_t i = n; i < length; i++) {
                     data[i].~T();
                 }
                 length = n;
@@ -91,14 +92,14 @@ namespace Core {
             return ErrorCode::NONE;
         }
 
-        check_return Error resize(i64 n) {
+        check_return Error resize(size_t n) {
             if(length < n) {
                 CORE_RETURN_ERROR(reserve(n));
-                for(i64 i = n - length; i != 0; i--) {
+                for(size_t i = n - length; i != 0; i--) {
                     unsafeAdd(T());
                 }
             } else if(length > n) {
-                for(i64 i = n; i < length; i++) {
+                for(size_t i = n; i < length; i++) {
                     data[i].~T();
                 }
                 length = n;
@@ -119,31 +120,31 @@ namespace Core {
             return put(t, Core::forward<Args>(args)...);
         }
 
-        T& operator[](i64 index) {
+        T& operator[](size_t index) {
             return data[index];
         }
 
-        const T& operator[](i64 index) const {
+        const T& operator[](size_t index) const {
             return data[index];
         }
 
-        i64 getLength() const {
+        size_t getLength() const {
             return length;
         }
 
-        i64 getCapacity() const {
+        size_t getCapacity() const {
             return capacity;
         }
 
         void clear() {
-            for(i64 i = 0; i < length; i++) {
+            for(size_t i = 0; i < length; i++) {
                 data[i].~T();
             }
             length = 0;
         }
 
-        check_return Error removeBySwap(i64 index) {
-            if(index < 0 || index >= length) {
+        check_return Error removeBySwap(size_t index) {
+            if(index >= length) {
                 return ErrorCode::INVALID_INDEX;
             }
             length--;
@@ -154,8 +155,8 @@ namespace Core {
             return ErrorCode::NONE;
         }
 
-        check_return Error remove(i64 index) {
-            if(index < 0 || index >= length) {
+        check_return Error remove(size_t index) {
+            if(index >= length) {
                 return ErrorCode::INVALID_INDEX;
             }
             length--;
@@ -186,19 +187,20 @@ namespace Core {
         }
 
     private:
-        static Error allocate(T*& t, i64 n) {
-            if(n <= 0) {
+        static Error allocate(T*& t, size_t n) {
+            if(n > (1lu << 48)) {
+                return ErrorCode::CAPACITY_REACHED;
+            } else if(n <= 0) {
                 return ErrorCode::NONE;
             }
-            t = reinterpret_cast<T*>(new(noThrow)
-                                         AlignedType<T>[static_cast<u64>(n)]);
+            t = reinterpret_cast<T*>(new(noThrow) AlignedType<T>[n]);
             return t == nullptr ? ErrorCode::OUT_OF_MEMORY : ErrorCode::NONE;
         }
 
         check_return Error ensureCapacity() {
             return length < capacity
                        ? ErrorCode::NONE
-                       : reserve(capacity + Core::Math::max(4l, capacity / 4));
+                       : reserve(capacity + Math::max(4lu, capacity / 4));
         }
 
         // does not check for capacity
@@ -207,11 +209,11 @@ namespace Core {
             return new(data + length++) T(Core::forward<Args>(args)...);
         }
 
-        check_return Error setSize(i64 n) {
+        check_return Error setSize(size_t n) {
             List copy;
             CORE_RETURN_ERROR(allocate(copy.data, n));
             copy.capacity = n;
-            for(i64 i = 0; i < length; i++) {
+            for(size_t i = 0; i < length; i++) {
                 copy.unsafeAdd(Core::move(data[i]));
             }
             swap(copy);

+ 22 - 20
include/core/data/ProbingHashMap.hpp

@@ -4,9 +4,11 @@
 #include "core/data/List.hpp"
 #include "core/utils/AlignedData.hpp"
 #include "core/utils/ArrayString.hpp"
+#include "core/utils/Error.hpp"
 #include "core/utils/HashCode.hpp"
 #include "core/utils/Logger.hpp"
 #include "core/utils/New.hpp"
+#include "core/utils/Types.hpp"
 
 namespace Core {
     template<typename K, typename V>
@@ -123,7 +125,7 @@ namespace Core {
     private:
         List<K> keys;
         V* values;
-        i64 entries;
+        size_t entries;
 
     public:
         ProbingHashMap() : keys(), values(nullptr), entries(0) {
@@ -136,7 +138,7 @@ namespace Core {
         }
 
         ~ProbingHashMap() {
-            for(i64 i = 0; i < keys.getLength(); i++) {
+            for(size_t i = 0; i < keys.getLength(); i++) {
                 if(keys[i] != emptyValue<K>()) {
                     values[i].~V();
                 }
@@ -160,23 +162,23 @@ namespace Core {
             return ErrorCode::NONE;
         }
 
-        check_return Error rehash(i64 minCapacity) {
+        check_return Error rehash(size_t minCapacity) {
             if(minCapacity <= keys.getLength()) {
                 return ErrorCode::NONE;
             }
             ProbingHashMap<K, V> map;
-            i64 shifts = Math::roundUpLog2(Core::Math::max(minCapacity, 8l));
+            size_t shifts =
+                Math::roundUpLog2(Core::Math::max(minCapacity, 8lu));
             if(shifts >= 48) {
                 return ErrorCode::CAPACITY_REACHED;
             }
-            i64 l = 1l << shifts;
+            size_t l = 1lu << shifts;
             CORE_RETURN_ERROR(map.keys.resize(l, emptyValue<K>()));
-            map.values = reinterpret_cast<V*>(
-                new(noThrow) AlignedType<V>[static_cast<u64>(l)]);
+            map.values = reinterpret_cast<V*>(new(noThrow) AlignedType<V>[l]);
             if(map.values == nullptr) {
                 return ErrorCode::OUT_OF_MEMORY;
             }
-            for(i64 i = 0; i < keys.getLength(); i++) {
+            for(size_t i = 0; i < keys.getLength(); i++) {
                 if(keys[i] != emptyValue<K>()) {
                     CORE_RETURN_ERROR(map.add(keys[i], values[i]));
                 }
@@ -190,7 +192,7 @@ namespace Core {
             if(key == emptyValue<K>()) {
                 return ErrorCode::INVALID_ARGUMENT;
             }
-            i64 index = 0;
+            size_t index = 0;
             CORE_RETURN_ERROR(searchSlot(index, key));
             if(keys[index] == key) {
                 return ErrorCode::EXISTING_KEY;
@@ -206,7 +208,7 @@ namespace Core {
             if(key == emptyValue<K>()) {
                 return ErrorCode::INVALID_ARGUMENT;
             }
-            i64 index = 0;
+            size_t index = 0;
             CORE_RETURN_ERROR(searchSlot(index, key));
             if(keys[index] == key) {
                 values[index] = Core::forward<VA>(value);
@@ -283,15 +285,15 @@ namespace Core {
         }
 
     private:
-        check_return Error searchSlot(i64& slot, const K& key) {
-            i64 rehashFactor = 2;
+        check_return Error searchSlot(size_t& slot, const K& key) {
+            size_t rehashFactor = 2;
             while(true) {
                 CORE_RETURN_ERROR(rehash(entries * rehashFactor + 1));
-                u64 baseHash = hashCode(key) * 514685581u;
-                u64 end = static_cast<u64>(keys.getLength()) - 1;
+                size_t baseHash = hashCode(key) * 514685581u;
+                size_t end = keys.getLength() - 1;
                 // rehash on bad clustering
-                for(u64 i = 0; i <= 5; i++) {
-                    i64 hash = static_cast<i64>((baseHash + i) & end);
+                for(size_t i = 0; i <= 5; i++) {
+                    size_t hash = (baseHash + i) & end;
                     if(keys[hash] == emptyValue<K>() || keys[hash] == key) {
                         slot = hash;
                         return Core::ErrorCode::NONE;
@@ -304,10 +306,10 @@ namespace Core {
         template<typename Value>
         Value* searchValue(const K& key) const {
             if(keys.getLength() != 0) {
-                u64 baseHash = hashCode(key) * 514685581u;
-                u64 end = static_cast<u64>(keys.getLength()) - 1;
-                for(u32 i = 0; i <= end; i++) [[unlikely]] {
-                    i64 hash = static_cast<i64>((baseHash + i) & end);
+                size_t baseHash = hashCode(key) * 514685581u;
+                size_t end = static_cast<u64>(keys.getLength()) - 1;
+                for(size_t i = 0; i <= end; i++) [[unlikely]] {
+                    size_t hash = (baseHash + i) & end;
                     if(keys[hash] == key) [[likely]] {
                         return values + hash;
                     } else if(keys[hash] == emptyValue<K>()) {

+ 12 - 12
include/core/data/RingBuffer.hpp

@@ -5,14 +5,14 @@
 #include "core/utils/ArrayString.hpp"
 
 namespace Core {
-    template<typename T, i64 N>
+    template<typename T, size_t N>
     class RingBuffer final {
         static_assert(N > 0, "RingBuffer size must be positive");
 
         AlignedType<T> data[static_cast<u64>(N)];
-        i64 writeIndex;
-        i64 readIndex;
-        i64 values;
+        size_t writeIndex;
+        size_t readIndex;
+        size_t values;
 
     public:
         RingBuffer() : writeIndex(0), readIndex(0), values(0) {
@@ -65,15 +65,15 @@ namespace Core {
             return put(t, Core::forward<Args>(args)...);
         }
 
-        T& operator[](i64 index) {
+        T& operator[](size_t index) {
             return reinterpret_cast<T*>(data)[(index + readIndex) % N];
         }
 
-        const T& operator[](i64 index) const {
+        const T& operator[](size_t index) const {
             return reinterpret_cast<const T*>(data)[(index + readIndex) % N];
         }
 
-        i64 getLength() const {
+        size_t getLength() const {
             return values;
         }
 
@@ -82,7 +82,7 @@ namespace Core {
         }
 
         void clear() {
-            for(i64 i = 0; i < getLength(); i++) {
+            for(size_t i = 0; i < getLength(); i++) {
                 (*this)[i].~T();
             }
             writeIndex = 0;
@@ -103,10 +103,10 @@ namespace Core {
         template<typename String>
         check_return Error toString(String& s) const {
             CORE_RETURN_ERROR(s.append("["));
-            i64 end = getLength();
+            size_t end = getLength();
             if(end > 0) {
                 end--;
-                for(i64 i = 0; i < end; i++) {
+                for(size_t i = 0; i < end; i++) {
                     CORE_RETURN_ERROR(s.append((*this)[i]));
                     CORE_RETURN_ERROR(s.append(", "));
                 }
@@ -117,13 +117,13 @@ namespace Core {
 
     private:
         void copy(const RingBuffer& other) {
-            for(i64 i = 0; i < other.getLength(); i++) {
+            for(size_t i = 0; i < other.getLength(); i++) {
                 (void)add(other[i]);
             }
         }
 
         void move(RingBuffer&& other) {
-            for(i64 i = 0; i < other.getLength(); i++) {
+            for(size_t i = 0; i < other.getLength(); i++) {
                 (void)add(Core::move(other[i]));
             }
         }

+ 2 - 2
include/core/data/Stack.hpp

@@ -21,7 +21,7 @@ namespace Core {
             }
 
             check_return Error pop() {
-                i64 index = data.getLength();
+                size_t index = data.getLength();
                 if(index <= 0) {
                     return ErrorCode::INVALID_STATE;
                 }
@@ -50,7 +50,7 @@ namespace Core {
     template<typename T>
     using ListStack = Internal::BaseStack<T, List<T>>;
 
-    template<typename T, int N>
+    template<typename T, size_t N>
     using ArrayStack = Internal::BaseStack<T, ArrayList<T, N>>;
 }
 

+ 3 - 2
include/core/math/BufferedValue.hpp

@@ -2,6 +2,7 @@
 #define CORE_BUFFERED_VALUE_HPP
 
 #include "core/math/Math.hpp"
+#include "core/utils/Types.hpp"
 
 namespace Core {
     template<typename T>
@@ -75,11 +76,11 @@ namespace Core {
             return -current;
         }
 
-        auto& operator[](int index) {
+        auto& operator[](size_t index) {
             return current[index];
         }
 
-        const auto& operator[](int index) const {
+        const auto& operator[](size_t index) const {
             return current[index];
         }
 

+ 1 - 1
include/core/math/Matrix.hpp

@@ -13,7 +13,7 @@ namespace Core {
 
         Matrix& unit();
 
-        Matrix& set(int index, const Vector4& v);
+        Matrix& set(size_t index, const Vector4& v);
 
         Matrix transpose();
 

+ 1 - 1
include/core/math/MatrixStack.hpp

@@ -5,7 +5,7 @@
 #include "core/math/Matrix.hpp"
 
 namespace Core {
-    template<int N>
+    template<size_t N>
     class MatrixStack final {
         ArrayList<Matrix, N> stack;
 

+ 17 - 18
include/core/math/Vector.hpp

@@ -5,14 +5,13 @@
 #include "core/utils/ArrayString.hpp"
 
 namespace Core {
-    template<int N, typename T>
+    template<size_t N, typename T>
     class alignas(sizeof(T) * (Math::isPowerOf2(N) ? N : 1)) Vector final {
-        static_assert(N > 0, "Vector size must be positive");
-        T values[static_cast<unsigned int>(N)];
+        T values[N];
 
     public:
         Vector() {
-            for(int i = 0; i < N; i++) {
+            for(size_t i = 0; i < N; i++) {
                 values[i] = static_cast<T>(0);
             }
         }
@@ -29,7 +28,7 @@ namespace Core {
         Vector cross(const Vector&) const = delete;
 
         Vector& operator+=(const Vector& other) {
-            for(int i = 0; i < N; i++) {
+            for(size_t i = 0; i < N; i++) {
                 values[i] += other.values[i];
             }
             return *this;
@@ -42,7 +41,7 @@ namespace Core {
         }
 
         Vector& operator-=(const Vector& other) {
-            for(int i = 0; i < N; i++) {
+            for(size_t i = 0; i < N; i++) {
                 values[i] -= other.values[i];
             }
             return *this;
@@ -50,7 +49,7 @@ namespace Core {
 
         Vector operator-() const {
             Vector v = *this;
-            for(int i = 0; i < N; i++) {
+            for(size_t i = 0; i < N; i++) {
                 v.values[i] = -v.values[i];
             }
             return v;
@@ -63,14 +62,14 @@ namespace Core {
         }
 
         Vector& operator*=(T factor) {
-            for(int i = 0; i < N; i++) {
+            for(size_t i = 0; i < N; i++) {
                 values[i] *= factor;
             }
             return *this;
         }
 
         Vector& operator*=(const Vector& other) {
-            for(int i = 0; i < N; i++) {
+            for(size_t i = 0; i < N; i++) {
                 values[i] *= other.values[i];
             }
             return *this;
@@ -89,14 +88,14 @@ namespace Core {
         }
 
         Vector& operator/=(T factor) {
-            for(int i = 0; i < N; i++) {
+            for(size_t i = 0; i < N; i++) {
                 values[i] /= factor;
             }
             return *this;
         }
 
         Vector& operator/=(const Vector& other) {
-            for(int i = 0; i < N; i++) {
+            for(size_t i = 0; i < N; i++) {
                 values[i] /= other.values[i];
             }
             return *this;
@@ -116,7 +115,7 @@ namespace Core {
 
         T dot(const Vector& v) const {
             T length = 0.0f;
-            for(int i = 0; i < N; i++) {
+            for(size_t i = 0; i < N; i++) {
                 length += values[i] * v.values[i];
             }
             return length;
@@ -139,17 +138,17 @@ namespace Core {
             return *this;
         }
 
-        T& operator[](int index) {
+        T& operator[](size_t index) {
             return values[index];
         }
 
-        const T& operator[](int index) const {
+        const T& operator[](size_t index) const {
             return values[index];
         }
 
         Vector<N, int> toInt() const {
             Vector<N, int> cast;
-            for(int i = 0; i < N; i++) {
+            for(size_t i = 0; i < N; i++) {
                 cast[i] = static_cast<int>(values[i]);
             }
             return cast;
@@ -157,7 +156,7 @@ namespace Core {
 
         Vector<N, float> toFloat() const {
             Vector<N, float> cast;
-            for(int i = 0; i < N; i++) {
+            for(size_t i = 0; i < N; i++) {
                 cast[i] = static_cast<float>(values[i]);
             }
             return cast;
@@ -166,7 +165,7 @@ namespace Core {
         template<typename String>
         check_return Error toString(String& s) const {
             CORE_RETURN_ERROR(s.append("["));
-            for(int i = 0; i < N - 1; i++) {
+            for(size_t i = 0; i < N - 1; i++) {
                 CORE_RETURN_ERROR(s.append(values[i]));
                 CORE_RETURN_ERROR(s.append(", "));
             }
@@ -206,7 +205,7 @@ namespace Core {
     Vector3 Vector3::cross(const Vector3& other) const;
 }
 
-template<int N, typename T>
+template<size_t N, typename T>
 Core::Vector<N, T> operator*(T factor, const Core::Vector<N, T>& v) {
     return v * factor;
 }

+ 6 - 5
include/core/utils/AlignedData.hpp

@@ -1,6 +1,8 @@
 #ifndef CORE_ALIGNED_DATA_HPP
 #define CORE_ALIGNED_DATA_HPP
 
+#include "core/utils/Types.hpp"
+
 #define CORE_ASSERT_ALIGNED_DATA(var, type)                                    \
     static_assert(sizeof(var) == sizeof(type), "aligned data size missmatch"); \
     static_assert(decltype(var)::getSize() >= decltype(var)::getAlignment(),   \
@@ -9,10 +11,9 @@
                   "aligned data alignment missmatch");
 
 namespace Core {
-    template<int SIZE, int ALIGNMENT>
+    template<size_t SIZE, size_t ALIGNMENT>
     class alignas(ALIGNMENT) AlignedData final {
-        static_assert(SIZE > 0, "size must be positive");
-        char buffer[static_cast<unsigned int>(SIZE)] = {};
+        char buffer[SIZE] = {};
 
     public:
         template<typename T>
@@ -25,11 +26,11 @@ namespace Core {
             return reinterpret_cast<T*>(this);
         }
 
-        static consteval int getSize() {
+        static consteval size_t getSize() {
             return SIZE;
         }
 
-        static consteval int getAlignment() {
+        static consteval size_t getAlignment() {
             return ALIGNMENT;
         }
     };

+ 40 - 39
include/core/utils/ArrayString.hpp

@@ -1,6 +1,8 @@
 #ifndef CORE_ARRAY_STRING_HPP
 #define CORE_ARRAY_STRING_HPP
 
+#include <string.h>
+
 #include "core/utils/Error.hpp"
 #include "core/utils/Meta.hpp"
 #include "core/utils/Types.hpp"
@@ -22,9 +24,9 @@ namespace Core {
         }
 
         template<typename S, typename T, typename... Args>
-        CError formatR(const S& f, S& s, int index, const T& t,
+        CError formatR(const S& f, S& s, size_t index, const T& t,
                        Args&&... args) {
-            i32 l = f.getLength();
+            size_t l = f.getLength();
             while(index < l) {
                 auto u = f[index++];
                 if(u == '#') {
@@ -59,12 +61,12 @@ namespace Core {
 
     class CharString {
     protected:
-        i32 length;
-        i32 capacity;
+        size_t length;
+        size_t capacity;
         char* data;
 
     public:
-        CharString(char* buffer, i32 bufferSize);
+        CharString(char* buffer, size_t bufferSize);
         CharString(const CharString&) = delete;
         CharString& operator=(const CharString&) = delete;
         CError copyFrom(const CharString& s);
@@ -72,9 +74,9 @@ namespace Core {
         bool operator==(const CharString& other) const;
         bool operator!=(const char* s) const;
         bool operator!=(const CharString& other) const;
-        char operator[](int index) const;
-        int getLength() const;
-        int getCapacity() const;
+        char operator[](size_t index) const;
+        size_t getLength() const;
+        size_t getCapacity() const;
         CError append(char c);
         CError append(signed char c);
         CError append(unsigned char c);
@@ -94,21 +96,21 @@ namespace Core {
         CError toString(CharString& s) const;
         CError toString(Char32String& s) const;
         void clear();
-        CError print() const;
-        CError printLine() const;
+        void print() const;
+        void printLine() const;
 
         template<typename... Args>
         CError format(CharString& s, Args&&... args) {
             return copyFormat(*this, s, Core::forward<Args>(args)...);
         }
 
-        bool startsWith(const CharString& other, int from = 0) const;
-        int search(const CharString& other, int from = 0) const;
-        bool contains(const CharString& other, int from = 0) const;
-        int search(char u, int from = 0) const;
-        bool contains(char u, int from = 0) const;
-        CError substring(CharString& s, int from, int to) const;
-        CError substring(CharString& s, int from = 0) const;
+        bool startsWith(const CharString& other, size_t from = 0) const;
+        size_t search(const CharString& other, size_t from = 0) const;
+        bool contains(const CharString& other, size_t from = 0) const;
+        size_t search(char u, size_t from = 0) const;
+        bool contains(char u, size_t from = 0) const;
+        CError substring(CharString& s, size_t from, size_t to) const;
+        CError substring(CharString& s, size_t from = 0) const;
         CError replace(CharString& s, const CharString& search,
                        const CharString& replace);
         void replace(char search, char replace);
@@ -117,12 +119,12 @@ namespace Core {
 
     class Char32String {
     protected:
-        i32 length;
-        i32 capacity;
+        size_t length;
+        size_t capacity;
         c32* data;
 
     public:
-        Char32String(c32* buffer, i32 bufferSize);
+        Char32String(c32* buffer, size_t bufferSize);
         Char32String(const Char32String&) = delete;
         Char32String& operator=(const Char32String&) = delete;
         Error copyFrom(const Char32String& s);
@@ -130,9 +132,9 @@ namespace Core {
         bool operator==(const Char32String& other) const;
         bool operator!=(const c32* s) const;
         bool operator!=(const Char32String& other) const;
-        c32 operator[](int index) const;
-        int getLength() const;
-        int getCapacity() const;
+        c32 operator[](size_t index) const;
+        size_t getLength() const;
+        size_t getCapacity() const;
         CError append(char c);
         CError append(signed char c);
         CError append(unsigned char c);
@@ -152,44 +154,43 @@ namespace Core {
         CError toString(CharString& s) const;
         CError toString(Char32String& s) const;
         void clear();
-        CError print() const;
-        CError printLine() const;
+        void print() const;
+        void printLine() const;
 
         template<typename... Args>
         CError format(Char32String& s, Args&&... args) {
             return copyFormat(*this, s, Core::forward<Args>(args)...);
         }
 
-        bool startsWith(const Char32String& other, int from = 0) const;
-        int search(const Char32String& other, int from = 0) const;
-        bool contains(const Char32String& other, int from = 0) const;
-        int search(c32 u, int from = 0) const;
-        bool contains(c32 u, int from = 0) const;
-        CError substring(Char32String& s, int from, int to) const;
-        CError substring(Char32String& s, int from = 0) const;
+        bool startsWith(const Char32String& other, size_t from = 0) const;
+        size_t search(const Char32String& other, size_t from = 0) const;
+        bool contains(const Char32String& other, size_t from = 0) const;
+        size_t search(c32 u, size_t from = 0) const;
+        bool contains(c32 u, size_t from = 0) const;
+        CError substring(Char32String& s, size_t from, size_t to) const;
+        CError substring(Char32String& s, size_t from = 0) const;
         CError replace(Char32String& s, const Char32String& search,
                        const Char32String& replace);
         void replace(c32 search, c32 replace);
         operator const c32*() const;
     };
 
-    template<int N, typename C, typename B>
+    template<size_t N, typename C, typename B>
     class ArrayString final : public B {
-        static_assert(N > 0, "size of array string must be positive");
-        C data[static_cast<unsigned int>(N)];
+        C data[N];
 
     public:
         ArrayString() : B(data, N) {
         }
 
         ArrayString(const ArrayString& other) : B(data, N) {
-            Core::memoryCopy(data, other.data, sizeof(data));
+            memcpy(data, other.data, sizeof(data));
             B::length = other.length;
         }
 
         ArrayString& operator=(const ArrayString& other) {
             if(this != &other) {
-                Core::memoryCopy(data, other.data, sizeof(data));
+                memcpy(data, other.data, sizeof(data));
                 B::length = other.length;
             }
             return *this;
@@ -224,10 +225,10 @@ namespace Core {
         return s.append("]");
     }
 
-    template<int N>
+    template<size_t N>
     using String8 = ArrayString<N, char, CharString>;
 
-    template<int N>
+    template<size_t N>
     using String32 = ArrayString<N, c32, Char32String>;
 }
 

+ 8 - 10
include/core/utils/Buffer.hpp

@@ -3,38 +3,36 @@
 
 #include "core/utils/Check.hpp"
 #include "core/utils/Error.hpp"
+#include "core/utils/Types.hpp"
 
 namespace Core {
     class Buffer final {
-        int length;
-        int capacity;
+        size_t length;
+        size_t capacity;
         char* buffer;
 
     public:
-        Buffer(int initialSize = 32);
+        Buffer(size_t initialSize = 32);
         Buffer(const Buffer& other) = delete;
         Buffer(Buffer&& other);
         ~Buffer();
         Buffer& operator=(const Buffer& other) = delete;
         Buffer& operator=(Buffer&& other);
 
-        check_return Error copyFrom(const Buffer& other);
-
-        check_return Error add(const void* data, int size);
+        CError copyFrom(const Buffer& other);
+        CError add(const void* data, size_t size);
 
         template<typename T>
         check_return Error add(const T& t) {
             return add(&t, sizeof(T));
         }
 
-        int getLength() const;
+        size_t getLength() const;
         operator const char*() const;
         const char* getData() const;
-
         void clear();
-
         void swap(Buffer& other);
     };
 }
 
-#endif
+#endif

+ 2 - 2
include/core/utils/Clock.hpp

@@ -10,7 +10,7 @@ namespace Core {
         using Nanos = i64;
 
     private:
-        int index;
+        size_t index;
         Nanos last;
         Nanos sum;
         Array<Nanos, 1 << 7> time;
@@ -27,4 +27,4 @@ namespace Core {
     };
 }
 
-#endif
+#endif

+ 12 - 22
include/core/utils/Color.hpp

@@ -1,46 +1,36 @@
 #ifndef CORE_COLOR_HPP
 #define CORE_COLOR_HPP
 
+#include "core/utils/Types.hpp"
+
 namespace Core {
     using ColorChannel = unsigned char;
 
-    template<int N>
+    template<size_t N>
     class Color final {
         static_assert(N >= 1 && N <= 4, "a color has 1 to 4 channels");
-
-        ColorChannel data[static_cast<unsigned int>(N)] = {};
+        ColorChannel data[N] = {};
 
     public:
         Color() = default;
 
         template<typename OT, typename... Args>
-        Color(OT a, Args&&... args) {
-            init<0>(a, args...);
-        }
-
-    private:
-        template<int I>
-        void init() {
-            static_assert(I == N,
+        Color(OT a, Args&&... args)
+            : data(static_cast<ColorChannel>(a),
+                   static_cast<ColorChannel>(args)...) {
+            static_assert(sizeof...(args) + 1 == N,
                           "color channel parameters do not match its size");
         }
 
-        template<int I, typename OT, typename... Args>
-        void init(OT a, Args&&... args) {
-            data[I] = static_cast<ColorChannel>(a);
-            init<I + 1>(args...);
-        }
-
-    public:
-        float asFloat(int index) const {
+        float asFloat(size_t index) const {
             return data[index] * (1.0f / 255.0f);
         }
 
-        ColorChannel& operator[](int index) {
+        ColorChannel& operator[](size_t index) {
             return data[index];
         }
 
-        const ColorChannel& operator[](int index) const {
+        const ColorChannel& operator[](size_t index) const {
             return data[index];
         }
     };
@@ -51,4 +41,4 @@ namespace Core {
     using Color1 = Color<1>;
 }
 
-#endif
+#endif

+ 23 - 17
include/core/utils/Error.hpp

@@ -2,6 +2,7 @@
 #define CORE_ERROR_HPP
 
 #include "core/utils/Check.hpp"
+#include "core/utils/Types.hpp"
 
 namespace Core {
     struct Error {
@@ -37,29 +38,34 @@ namespace Core {
             e |= *this;
             return e;
         }
+
+        operator Code() const {
+            return code;
+        }
     };
 
     namespace ErrorCode {
         static constexpr Error NONE = 0;
-        static constexpr Error NEGATIVE_ARGUMENT = 1 << 0;
-        static constexpr Error CAPACITY_REACHED = 1 << 1;
-        static constexpr Error BLOCKED_STDOUT = 1 << 2;
-        static constexpr Error OUT_OF_MEMORY = 1 << 3;
-        static constexpr Error INVALID_CHAR = 1 << 4;
-        static constexpr Error NOT_FOUND = 1 << 5;
-        static constexpr Error INVALID_STATE = 1 << 6;
-        static constexpr Error INVALID_INDEX = 1 << 7;
-        static constexpr Error INVALID_ARGUMENT = 1 << 8;
-        static constexpr Error TIME_NOT_AVAILABLE = 1 << 9;
-        static constexpr Error SLEEP_INTERRUPTED = 1 << 10;
-        static constexpr Error THREAD_ERROR = 1 << 11;
-        static constexpr Error MUTEX_ERROR = 1 << 12;
-        static constexpr Error EXISTING_KEY = 1 << 13;
-        static constexpr Error CANNOT_OPEN_FILE = 1 << 14;
-        static constexpr Error END_OF_FILE = 1 << 15;
+        static constexpr Error ERROR = 1 << 0;
+        static constexpr Error NEGATIVE_ARGUMENT = 1 << 1;
+        static constexpr Error CAPACITY_REACHED = 1 << 2;
+        static constexpr Error BLOCKED_STDOUT = 1 << 3;
+        static constexpr Error OUT_OF_MEMORY = 1 << 4;
+        static constexpr Error INVALID_CHAR = 1 << 5;
+        static constexpr Error NOT_FOUND = 1 << 6;
+        static constexpr Error INVALID_STATE = 1 << 7;
+        static constexpr Error INVALID_INDEX = 1 << 8;
+        static constexpr Error INVALID_ARGUMENT = 1 << 9;
+        static constexpr Error TIME_NOT_AVAILABLE = 1 << 10;
+        static constexpr Error SLEEP_INTERRUPTED = 1 << 11;
+        static constexpr Error THREAD_ERROR = 1 << 12;
+        static constexpr Error MUTEX_ERROR = 1 << 13;
+        static constexpr Error EXISTING_KEY = 1 << 14;
+        static constexpr Error CANNOT_OPEN_FILE = 1 << 15;
+        static constexpr Error END_OF_FILE = 1 << 16;
     }
 
-    CError toString(Error e, char* buffer, int size);
+    CError toString(Error e, char* buffer, size_t size);
 
     inline bool checkError(Error& storage, Error e) {
         return (storage = e).check();

+ 15 - 15
include/core/utils/HashCode.hpp

@@ -8,57 +8,57 @@
 
 namespace Core {
     template<typename H>
-    inline u64 hashCode(const H& key) {
+    inline size_t hashCode(const H& key) {
         return key.hashCode();
     }
 
     template<typename T>
-    inline u64 hashNumber(T t) {
-        static_assert(sizeof(t) <= 8);
-        return static_cast<u64>(t);
+    inline size_t hashNumber(T t) {
+        static_assert(sizeof(t) <= sizeof(size_t));
+        return static_cast<size_t>(t);
     }
 
-    inline u64 hashCode(char key) {
+    inline size_t hashCode(char key) {
         return hashNumber(key);
     }
 
-    inline u64 hashCode(signed char key) {
+    inline size_t hashCode(signed char key) {
         return hashNumber(key);
     }
 
-    inline u64 hashCode(signed short key) {
+    inline size_t hashCode(signed short key) {
         return hashNumber(key);
     }
 
-    inline u64 hashCode(signed int key) {
+    inline size_t hashCode(signed int key) {
         return hashNumber(key);
     }
 
-    inline u64 hashCode(signed long key) {
+    inline size_t hashCode(signed long key) {
         return hashNumber(key);
     }
 
-    inline u64 hashCode(signed long long key) {
+    inline size_t hashCode(signed long long key) {
         return hashNumber(key);
     }
 
-    inline u64 hashCode(unsigned char key) {
+    inline size_t hashCode(unsigned char key) {
         return hashNumber(key);
     }
 
-    inline u64 hashCode(unsigned short key) {
+    inline size_t hashCode(unsigned short key) {
         return hashNumber(key);
     }
 
-    inline u64 hashCode(unsigned int key) {
+    inline size_t hashCode(unsigned int key) {
         return hashNumber(key);
     }
 
-    inline u64 hashCode(unsigned long key) {
+    inline size_t hashCode(unsigned long key) {
         return hashNumber(key);
     }
 
-    inline u64 hashCode(unsigned long long key) {
+    inline size_t hashCode(unsigned long long key) {
         return hashNumber(key);
     }
 

+ 8 - 9
include/core/utils/HashedString.hpp

@@ -7,24 +7,23 @@
 
 namespace Core {
     struct StringHash {
-        i32 length = 0;
-        u32 hash = 0;
+        size_t length = 0;
+        size_t hash = 0;
     };
 
     constexpr StringHash hashString(const char* s) {
         StringHash h;
         while(*s != '\0') {
             h.length++;
-            h.hash = 2120251889u * h.hash + static_cast<u32>(*(s++));
+            h.hash = 2120251889lu * h.hash + static_cast<size_t>(*(s++));
         }
         return h;
     }
 
-    template<i32 N>
+    template<size_t N>
     class HashedString {
-        static_assert(N > 0, "length of hashed string must be positive");
         StringHash hash;
-        char data[static_cast<u32>(N)];
+        char data[N];
 
     public:
         HashedString() : hash() {
@@ -44,15 +43,15 @@ namespace Core {
             return !(*this == other);
         }
 
-        i32 getLength() const {
+        size_t getLength() const {
             return hash.length;
         }
 
-        constexpr i32 getCapacity() const {
+        constexpr size_t getCapacity() const {
             return N - 1;
         }
 
-        u32 hashCode() const {
+        size_t hashCode() const {
             return hash.hash;
         }
 

+ 4 - 2
include/core/utils/Logger.hpp

@@ -32,9 +32,10 @@ namespace Core::Logger {
            filterError(s.append("#:# | ")) ||
            filterError(s.format(file, line)) || filterError(s.append(format)) ||
            filterError(s.format(Core::forward<Args>(args)...)) ||
-           filterError(s.append(COLOR_RESET)) || filterError(s.printLine())) {
+           filterError(s.append(COLOR_RESET))) {
             CORE_EXIT(1); // CoverageIgnore
         }
+        s.printLine();
     }
 
     template<typename... Args>
@@ -42,9 +43,10 @@ namespace Core::Logger {
         Core::String32<2048> s;
         if(filterError(s.append(prefix)) || filterError(s.append(format)) ||
            filterError(s.format(Core::forward<Args>(args)...)) ||
-           filterError(s.append(COLOR_RESET)) || filterError(s.printLine())) {
+           filterError(s.append(COLOR_RESET))) {
             CORE_EXIT(1); // CoverageIgnore
         }
+        s.printLine();
     }
 }
 

+ 8 - 4
include/core/utils/Random.hpp

@@ -10,13 +10,17 @@ namespace Core {
 
     private:
         Array<Seed, 25> data;
-        int index;
+        size_t index;
 
     public:
         Random(Seed seed);
 
-        int next();
-        int next(int min, int inclusiveMax);
+        Seed next();
+        Seed next(Seed min, Seed inclusiveMax);
+        i32 nextI32();
+        i32 nextI32(i32 min, i32 inclusiveMax);
+        size_t nextSize();
+        size_t nextSize(size_t min, size_t inclusiveMax);
         bool nextBool();
         float nextFloat();
         float nextFloat(float min, float exclusiveMax);
@@ -26,4 +30,4 @@ namespace Core {
     };
 }
 
-#endif
+#endif

+ 1 - 0
include/core/utils/Types.hpp

@@ -12,5 +12,6 @@ using u32 = uint32_t;
 using u16 = uint16_t;
 using u8 = uint8_t;
 using c32 = char32_t;
+using size_t = decltype(sizeof(int));
 
 #endif

+ 17 - 21
include/core/utils/Utility.hpp

@@ -13,7 +13,7 @@ namespace Core {
         static constexpr C map[16] = {0, 1, 1, 2, 1, 2, 2, 3,
                                       1, 2, 2, 3, 2, 3, 3, 4};
         C sum = 0;
-        for(int i = 0; i < CORE_SIZE(T) * 8; i += 4) {
+        for(size_t i = 0; i < sizeof(T) * 8; i += 4) {
             sum += map[(t >> i) & 0xF];
         }
         return sum;
@@ -25,26 +25,22 @@ namespace Core {
 #define CORE_EXIT(exitValue)                                                   \
     Core::exitWithHandler(__FILE__, __LINE__, exitValue)
 
-    check_return Error toString(signed short s, char* buffer, int size);
-    check_return Error toString(unsigned short s, char* buffer, int size);
-    check_return Error toString(signed int i, char* buffer, int size);
-    check_return Error toString(unsigned int i, char* buffer, int size);
-    check_return Error toString(signed long l, char* buffer, int size);
-    check_return Error toString(unsigned long l, char* buffer, int size);
-    check_return Error toString(signed long long ll, char* buffer, int size);
-    check_return Error toString(unsigned long long ll, char* buffer, int size);
-    check_return Error toString(float f, char* buffer, int size);
-    check_return Error toString(double d, char* buffer, int size);
-    check_return Error toString(long double ld, char* buffer, int size);
-
-    check_return Error putChar(int c);
-    check_return Error putChars(const char* s);
-
-    void memorySet(void* p, int c, i64 n);
-    void memoryCopy(void* dest, const void* src, i64 n);
-    bool memoryCompare(const void* a, const void* b, i64 n);
-    check_return Error reallocate(char*& p, i64 n);
-    void free(void* p);
+    CError toString(signed short s, char* buffer, size_t size);
+    CError toString(unsigned short s, char* buffer, size_t size);
+    CError toString(signed int i, char* buffer, size_t size);
+    CError toString(unsigned int i, char* buffer, size_t size);
+    CError toString(signed long l, char* buffer, size_t size);
+    CError toString(unsigned long l, char* buffer, size_t size);
+    CError toString(signed long long ll, char* buffer, size_t size);
+    CError toString(unsigned long long ll, char* buffer, size_t size);
+    CError toString(float f, char* buffer, size_t size);
+    CError toString(double d, char* buffer, size_t size);
+    CError toString(long double ld, char* buffer, size_t size);
+
+    void print(int c);
+    void print(const char* s);
+    void printLine(const char* s);
+    CError reallocate(char*& p, size_t n);
 }
 
 #endif

+ 1 - 1
performance/Main.cpp

@@ -60,7 +60,7 @@ template<typename Map>
 static void fillChaos(Map& m) {
     Core::Random random(0);
     for(int i = 0; i < 10000; i++) {
-        int r = random.next(0, 9999);
+        int r = random.nextI32(0, 9999);
         CORE_TEST_ERROR(m.add(r, r * r));
     }
 }

+ 77 - 87
src/ArrayString.cpp

@@ -2,7 +2,6 @@
 
 #include <limits.h>
 #include <stdlib.h>
-#include <string.h>
 #include <uchar.h>
 
 #include "core/data/Array.hpp"
@@ -15,10 +14,10 @@ using Char32String = Core::Char32String;
 using Error = Core::Error;
 namespace ErrorCode = Core::ErrorCode;
 
-constexpr int stringLength(const c32* c) {
+constexpr size_t stringLength(const c32* c) {
     const c32* i = c + 1;
     while(*(c++) != '\0') {}
-    return static_cast<int>(c - i);
+    return static_cast<size_t>(c - i);
 }
 
 static Error readUnicode(c32& u, const char*& s) {
@@ -35,15 +34,15 @@ using C32Buffer = Core::Array<char, MB_LEN_MAX + 1>;
 
 static Error convertC32(C32Buffer& buffer, c32 c) {
     size_t n = c32rtomb(buffer.begin(), c, nullptr);
-    if(n >= static_cast<size_t>(buffer.getLength())) {
+    if(n >= buffer.getLength()) {
         return ErrorCode::INVALID_CHAR;
     }
-    buffer[static_cast<i64>(n)] = '\0';
+    buffer[n] = '\0';
     return ErrorCode::NONE;
 }
 
-CharString::CharString(char* buffer, i32 bufferSize)
-    : length(0), capacity(bufferSize), data(buffer) {
+CharString::CharString(char* buffer, size_t bufferSize)
+    : length(0), capacity(bufferSize <= 0 ? 0 : bufferSize - 1), data(buffer) {
     data[0] = '\0';
 }
 
@@ -68,20 +67,20 @@ bool CharString::operator!=(const CharString& other) const {
     return !((*this) == other);
 }
 
-char CharString::operator[](int index) const {
+char CharString::operator[](size_t index) const {
     return data[index];
 }
 
-int CharString::getLength() const {
+size_t CharString::getLength() const {
     return length;
 }
 
-int CharString::getCapacity() const {
-    return capacity - 1;
+size_t CharString::getCapacity() const {
+    return capacity;
 }
 
 Error CharString::append(char c) {
-    if(length >= capacity - 1) {
+    if(length >= capacity) {
         return ErrorCode::CAPACITY_REACHED;
     }
     data[length++] = c;
@@ -117,7 +116,7 @@ Error CharString::append(const char* s) {
 
 Error CharString::append(const c32* s) {
     // stringLength as s could be some part of data
-    for(int i = stringLength(s); i > 0; i--) {
+    for(size_t i = stringLength(s); i > 0; i--) {
         CORE_RETURN_ERROR(append(*(s++)));
     }
     return ErrorCode::NONE;
@@ -136,8 +135,8 @@ Error CharString::append(bool b) {
 }
 
 Error CharString::toString(CharString& s) const {
-    int l = length; // length changes if &s == this
-    for(int i = 0; i < l; i++) {
+    size_t l = length; // length changes if &s == this
+    for(size_t i = 0; i < l; i++) {
         CORE_RETURN_ERROR(s.append(data[i]));
     }
     return ErrorCode::NONE;
@@ -152,62 +151,53 @@ void CharString::clear() {
     data[0] = '\0';
 }
 
-Error CharString::print() const {
-    return Core::putChars(data);
+void CharString::print() const {
+    Core::print(data);
 }
 
-Error CharString::printLine() const {
-    CORE_RETURN_ERROR(print());
-    return Core::putChar('\n');
+void CharString::printLine() const {
+    Core::printLine(data);
 }
 
-bool CharString::startsWith(const CharString& other, int from) const {
-    return from >= 0 && length - from >= other.getLength() &&
-           strncmp(data + from, other.data,
-                   static_cast<size_t>(other.getLength())) == 0;
+bool CharString::startsWith(const CharString& other, size_t from) const {
+    return length >= from + other.getLength() &&
+           strncmp(data + from, other.data, other.getLength()) == 0;
 }
 
-int CharString::search(const CharString& other, int from) const {
-    if(from < 0) {
-        return false;
-    }
+size_t CharString::search(const CharString& other, size_t from) const {
     char* f = strstr(data + from, other.data);
-    return f == nullptr ? -1 : static_cast<int>(f - data);
+    return f == nullptr ? SIZE_MAX : static_cast<size_t>(f - data);
 }
 
-bool CharString::contains(const CharString& other, int from) const {
-    return search(other, from) >= 0;
+bool CharString::contains(const CharString& other, size_t from) const {
+    return search(other, from) != SIZE_MAX;
 }
 
-int CharString::search(char u, int from) const {
-    if(from < 0) {
-        return false;
-    }
+size_t CharString::search(char u, size_t from) const {
     char* f = strchr(data + from, u);
-    return f == nullptr ? -1 : static_cast<int>(f - data);
+    return f == nullptr ? SIZE_MAX : static_cast<size_t>(f - data);
 }
 
-bool CharString::contains(char u, int from) const {
-    return search(u, from) >= 0;
+bool CharString::contains(char u, size_t from) const {
+    return search(u, from) != SIZE_MAX;
 }
 
-Error CharString::substring(CharString& s, int from, int to) const {
+Error CharString::substring(CharString& s, size_t from, size_t to) const {
     s.clear();
-    from = Math::max(from, 0);
-    to = Math::min(to, length - 1);
-    for(int i = from; i <= to; i++) {
+    to = Math::min(to + 1, length);
+    for(size_t i = from; i < to; i++) {
         CORE_RETURN_ERROR(s.append(data[i]));
     }
     return ErrorCode::NONE;
 }
 
-Error CharString::substring(CharString& s, int from) const {
+Error CharString::substring(CharString& s, size_t from) const {
     return substring(s, from, length - 1);
 }
 
 Error CharString::replace(CharString& s, const CharString& search,
                           const CharString& replace) {
-    int i = 0;
+    size_t i = 0;
     while(i < length) {
         if(startsWith(search, i)) {
             CORE_RETURN_ERROR(s.append(replace));
@@ -221,7 +211,7 @@ Error CharString::replace(CharString& s, const CharString& search,
 }
 
 void CharString::replace(char search, char replace) {
-    for(int i = 0; i < length; i++) {
+    for(size_t i = 0; i < length; i++) {
         if(data[i] == search) {
             data[i] = replace;
         }
@@ -232,8 +222,8 @@ CharString::operator const char*() const {
     return data;
 }
 
-Char32String::Char32String(c32* buffer, i32 bufferSize)
-    : length(0), capacity(bufferSize), data(buffer) {
+Char32String::Char32String(c32* buffer, size_t bufferSize)
+    : length(0), capacity(bufferSize <= 0 ? 0 : bufferSize - 1), data(buffer) {
     data[0] = '\0';
 }
 
@@ -255,7 +245,7 @@ bool Char32String::operator==(const Char32String& other) const {
     if(length != other.getLength()) {
         return false;
     }
-    for(int i = 0; i < length; i++) {
+    for(size_t i = 0; i < length; i++) {
         if(data[i] != other[i]) {
             return false;
         }
@@ -271,16 +261,16 @@ bool Char32String::operator!=(const Char32String& other) const {
     return !((*this) == other);
 }
 
-c32 Char32String::operator[](int index) const {
+c32 Char32String::operator[](size_t index) const {
     return data[index];
 }
 
-int Char32String::getLength() const {
+size_t Char32String::getLength() const {
     return length;
 }
 
-int Char32String::getCapacity() const {
-    return capacity - 1;
+size_t Char32String::getCapacity() const {
+    return capacity;
 }
 
 Error Char32String::append(char c) {
@@ -300,7 +290,7 @@ Error Char32String::append(wchar_t c) {
 }
 
 Error Char32String::append(c32 c) {
-    if(length >= capacity - 1) {
+    if(length >= capacity) {
         return ErrorCode::CAPACITY_REACHED;
     }
     data[length++] = c;
@@ -321,7 +311,7 @@ Error Char32String::append(const char* s) {
 
 Error Char32String::append(const c32* s) {
     // stringLength as s could be some part of data
-    for(int i = stringLength(s); i > 0; i--) {
+    for(size_t i = stringLength(s); i > 0; i--) {
         CORE_RETURN_ERROR(append(*(s++)));
     }
     return ErrorCode::NONE;
@@ -340,16 +330,16 @@ Error Char32String::append(bool b) {
 }
 
 Error Char32String::toString(CharString& s) const {
-    int l = length; // length changes if &s == this
-    for(int i = 0; i < l; i++) {
+    size_t l = length; // length changes if &s == this
+    for(size_t i = 0; i < l; i++) {
         CORE_RETURN_ERROR(s.append(data[i]));
     }
     return ErrorCode::NONE;
 }
 
 Error Char32String::toString(Char32String& s) const {
-    int l = length; // length changes if &s == this
-    for(int i = 0; i < l; i++) {
+    size_t l = length; // length changes if &s == this
+    for(size_t i = 0; i < l; i++) {
         CORE_RETURN_ERROR(s.append(data[i]));
     }
     return ErrorCode::NONE;
@@ -360,26 +350,27 @@ void Char32String::clear() {
     data[0] = '\0';
 }
 
-Error Char32String::print() const {
-    for(int i = 0; i < length; i++) {
+void Char32String::print() const {
+    for(size_t i = 0; i < length; i++) {
         C32Buffer buffer;
-        CORE_RETURN_ERROR(convertC32(buffer, data[i]));
-        CORE_RETURN_ERROR(putChars(buffer.begin()));
+        if(convertC32(buffer, data[i]).check()) {
+            Core::print('?');
+        } else {
+            Core::print(buffer.begin());
+        }
     }
-    return ErrorCode::NONE;
 }
 
-Error Char32String::printLine() const {
-    CORE_RETURN_ERROR(print());
-    CORE_RETURN_ERROR(Core::putChar('\n'));
-    return ErrorCode::NONE;
+void Char32String::printLine() const {
+    print();
+    Core::print('\n');
 }
 
-bool Char32String::startsWith(const Char32String& other, int from) const {
-    if(from > length - other.getLength()) {
+bool Char32String::startsWith(const Char32String& other, size_t from) const {
+    if(from + other.getLength() > length) {
         return false;
     }
-    for(int i = 0; i < other.getLength(); i++) {
+    for(size_t i = 0; i < other.getLength(); i++) {
         if(data[from + i] != other[i]) {
             return false;
         }
@@ -387,49 +378,48 @@ bool Char32String::startsWith(const Char32String& other, int from) const {
     return true;
 }
 
-int Char32String::search(const Char32String& other, int from) const {
-    for(int i = from; i < length; i++) {
+size_t Char32String::search(const Char32String& other, size_t from) const {
+    for(size_t i = from; i < length; i++) {
         if(startsWith(other, i)) {
             return i;
         }
     }
-    return -1;
+    return SIZE_MAX;
 }
 
-bool Char32String::contains(const Char32String& other, int from) const {
-    return search(other, from) >= 0;
+bool Char32String::contains(const Char32String& other, size_t from) const {
+    return search(other, from) != SIZE_MAX;
 }
 
-int Char32String::search(c32 u, int from) const {
-    for(int i = from; i < length; i++) {
+size_t Char32String::search(c32 u, size_t from) const {
+    for(size_t i = from; i < length; i++) {
         if(data[i] == u) {
             return i;
         }
     }
-    return -1;
+    return SIZE_MAX;
 }
 
-bool Char32String::contains(c32 u, int from) const {
-    return search(u, from) >= 0;
+bool Char32String::contains(c32 u, size_t from) const {
+    return search(u, from) != SIZE_MAX;
 }
 
-Error Char32String::substring(Char32String& s, int from, int to) const {
+Error Char32String::substring(Char32String& s, size_t from, size_t to) const {
     s.clear();
-    from = Math::max(from, 0);
-    to = Math::min(to, length - 1);
-    for(int i = from; i <= to; i++) {
+    to = Math::min(to + 1, length);
+    for(size_t i = from; i < to; i++) {
         CORE_RETURN_ERROR(s.append(data[i]));
     }
     return ErrorCode::NONE;
 }
 
-Error Char32String::substring(Char32String& s, int from) const {
+Error Char32String::substring(Char32String& s, size_t from) const {
     return substring(s, from, length - 1);
 }
 
 Error Char32String::replace(Char32String& s, const Char32String& search,
                             const Char32String& replace) {
-    int i = 0;
+    size_t i = 0;
     while(i < length) {
         if(startsWith(search, i)) {
             CORE_RETURN_ERROR(s.append(replace));
@@ -443,7 +433,7 @@ Error Char32String::replace(Char32String& s, const Char32String& search,
 }
 
 void Char32String::replace(c32 search, c32 replace) {
-    for(int i = 0; i < length; i++) {
+    for(size_t i = 0; i < length; i++) {
         if(data[i] == search) {
             data[i] = replace;
         }

+ 3 - 1
src/BitArray.cpp

@@ -1,5 +1,7 @@
 #include "core/data/BitArray.hpp"
 
+#include <string.h>
+
 #include "core/math/Math.hpp"
 #include "core/utils/New.hpp"
 
@@ -143,7 +145,7 @@ check_return Core::Error Core::BitArray::resize(u64 newLength, u64 newBits) {
     if(newData == nullptr) {
         return ErrorCode::OUT_OF_MEMORY;
     }
-    Core::memorySet(newData, 0, static_cast<i64>(arrayLength) * CORE_SIZE(int));
+    memset(newData, 0, arrayLength * sizeof(int));
 
     u64 end = Math::min(getLength(), newLength);
     for(u64 i = 0; i < end; i++) {

+ 3 - 3
src/Box.cpp

@@ -5,7 +5,7 @@ Core::Box::Box(const Vector3& min_, const Vector3& max_)
 }
 
 Core::Box::Box(const Vector3& size) : min(), max() {
-    for(int i = 0; i < 3; i++) {
+    for(size_t i = 0; i < 3; i++) {
         if(size[i] < 0.0f) {
             min[i] = size[i];
         } else {
@@ -38,7 +38,7 @@ Core::Box Core::Box::grow(const Vector3& growth) const {
     Vector3 half = growth * 0.5f;
     Vector3 nMin = min - half;
     Vector3 nMax = max + half;
-    for(int i = 0; i < 3; i++) {
+    for(size_t i = 0; i < 3; i++) {
         if(nMin[i] > nMax[i]) {
             nMin[i] = (min[i] + max[i]) * 0.5f;
             nMax[i] = nMin[i];
@@ -53,4 +53,4 @@ const Core::Vector3& Core::Box::getMin() const {
 
 const Core::Vector3& Core::Box::getMax() const {
     return max;
-}
+}

+ 8 - 5
src/Buffer.cpp

@@ -1,9 +1,12 @@
 #include "core/utils/Buffer.hpp"
 
+#include <stdlib.h>
+#include <string.h>
+
 #include "core/math/Math.hpp"
 #include "core/utils/Utility.hpp"
 
-Core::Buffer::Buffer(int initialSize)
+Core::Buffer::Buffer(size_t initialSize)
     : length(0), capacity(initialSize <= 0 ? 1 : initialSize), buffer(nullptr) {
 }
 
@@ -25,19 +28,19 @@ Core::Error Core::Buffer::copyFrom(const Buffer& other) {
     return add(other.getData(), other.length);
 }
 
-Core::Error Core::Buffer::add(const void* data, int size) {
+Core::Error Core::Buffer::add(const void* data, size_t size) {
     if(length + size > capacity || buffer == nullptr) {
         while(length + size > capacity) {
-            capacity += Math::max(4, capacity / 4);
+            capacity += Math::max<size_t>(4, capacity / 4);
         }
         CORE_RETURN_ERROR(reallocate(buffer, capacity));
     }
-    memoryCopy(buffer + length, data, size);
+    memcpy(buffer + length, data, size);
     length += size;
     return ErrorCode::NONE;
 }
 
-int Core::Buffer::getLength() const {
+size_t Core::Buffer::getLength() const {
     return length;
 }
 

+ 5 - 2
src/Error.cpp

@@ -1,7 +1,10 @@
 #include "core/utils/Error.hpp"
 
-CError Core::toString(Error e, char* buffer, int size) {
-    int index = 0;
+CError Core::toString(Error e, char* buffer, size_t size) {
+    if(size <= 0) {
+        return ErrorCode::CAPACITY_REACHED;
+    }
+    size_t index = 0;
     Error::Code c = e.code;
     size--;
     while(true) {

+ 3 - 2
src/ErrorSimulator.cpp

@@ -1,6 +1,7 @@
+#ifdef ERROR_SIMULATOR
 #include "ErrorSimulator.hpp"
 
-#ifdef ERROR_SIMULATOR
+#include <stdlib.h>
 
 #include "core/utils/Utility.hpp"
 
@@ -10,7 +11,7 @@ bool Core::Fail::timeGet = false;
 int Core::Fail::leftAllocations = -1;
 
 bool Core::Fail::freeAndReturn(void* p) {
-    Core::free(p);
+    free(p);
     return true;
 }
 

+ 4 - 4
src/Matrix.cpp

@@ -10,15 +10,15 @@ Core::Matrix& Core::Matrix::unit() {
     return translateTo(Vector3(0.0f, 0.0f, 0.0f));
 }
 
-Core::Matrix& Core::Matrix::set(int index, const Vector4& v) {
+Core::Matrix& Core::Matrix::set(size_t index, const Vector4& v) {
     data[index] = v;
     return *this;
 }
 
 Core::Matrix Core::Matrix::transpose() {
     Matrix m;
-    for(int x = 0; x < 4; x++) {
-        for(int y = 0; y < 4; y++) {
+    for(size_t x = 0; x < 4; x++) {
+        for(size_t y = 0; y < 4; y++) {
             m.data[x][y] = data[y][x];
         }
     }
@@ -122,4 +122,4 @@ Core::Matrix& Core::Matrix::rotate(const Quaternion& q) {
     set(1, Vector4(a[1], b[1], c[1], d[1]));
     set(2, Vector4(a[2], b[2], c[2], d[2]));
     return *this;
-}
+}

+ 3 - 2
src/Mutex.cpp

@@ -1,12 +1,13 @@
 #include "core/thread/Mutex.hpp"
 
+#include <string.h>
 #include <threads.h>
 
 #include "core/utils/Meta.hpp"
 #include "core/utils/Utility.hpp"
 
 static void reset(mtx_t* m) {
-    Core::memorySet(m, 0, sizeof(mtx_t));
+    memset(m, 0, sizeof(mtx_t));
 }
 
 Core::Mutex::Mutex() : mutex() {
@@ -16,7 +17,7 @@ Core::Mutex::Mutex() : mutex() {
 
 static bool doesExist(mtx_t* t) {
     mtx_t zero{};
-    return !Core::memoryCompare(&zero, t, sizeof(mtx_t));
+    return memcmp(&zero, t, sizeof(mtx_t)) != 0;
 }
 
 Core::Mutex::~Mutex() {

+ 34 - 8
src/Random.cpp

@@ -5,7 +5,7 @@
 constexpr static int M = 7;
 
 Core::Random::Random(Seed seed) : data(), index(0) {
-    for(int i = 0; i < data.getLength(); i++) {
+    for(size_t i = 0; i < data.getLength(); i++) {
         data[i] = seed;
         seed = seed * 7 + 31;
     }
@@ -13,17 +13,17 @@ Core::Random::Random(Seed seed) : data(), index(0) {
 
 void Core::Random::update() {
     static const Seed map[2] = {0, 0x8EBFD028};
-    for(int i = 0; i < data.getLength() - M; i++) {
+    for(size_t i = 0; i < data.getLength() - M; i++) {
         data[i] = data[i + M] ^ (data[i] >> 1) ^ map[data[i] & 1];
     }
-    for(int i = data.getLength() - M; i < data.getLength(); i++) {
+    for(size_t i = data.getLength() - M; i < data.getLength(); i++) {
         data[i] = data[i + (M - data.getLength())] ^ (data[i] >> 1) ^
                   map[data[i] & 1];
     }
     index = 0;
 }
 
-int Core::Random::next() {
+Core::Random::Seed Core::Random::next() {
     if(index >= data.getLength()) {
         update();
     }
@@ -31,11 +31,37 @@ int Core::Random::next() {
     r ^= (r << 7) & 0x2B5B2500;
     r ^= (r << 15) & 0xDB8B0000;
     r ^= (r >> 16);
-    return static_cast<int>(r >> 1);
+    return r;
 }
 
-int Core::Random::next(int min, int inclusiveMax) {
-    return min + next() % (inclusiveMax - min + 1);
+template<typename T>
+T limit(T value, T min, T inclusiveMax) {
+    return min + value % (inclusiveMax - min + 1);
+}
+
+Core::Random::Seed Core::Random::next(Seed min, Seed inclusiveMax) {
+    return limit(next(), min, inclusiveMax);
+}
+
+i32 Core::Random::nextI32() {
+    return static_cast<i32>(next() >> 1);
+}
+
+i32 Core::Random::nextI32(i32 min, i32 inclusiveMax) {
+    return limit(nextI32(), min, inclusiveMax);
+}
+
+size_t Core::Random::nextSize() {
+    if constexpr(sizeof(size_t) <= sizeof(Seed)) {
+        return static_cast<size_t>(next());
+    } else {
+        return static_cast<size_t>(next()) |
+               (static_cast<size_t>(next()) >> 32);
+    }
+}
+
+size_t Core::Random::nextSize(size_t min, size_t inclusiveMax) {
+    return limit(nextSize(), min, inclusiveMax);
 }
 
 bool Core::Random::nextBool() {
@@ -50,4 +76,4 @@ float Core::Random::nextFloat() {
 
 float Core::Random::nextFloat(float min, float exclusiveMax) {
     return min + nextFloat() * (exclusiveMax - min);
-}
+}

+ 6 - 5
src/Thread.cpp

@@ -1,12 +1,13 @@
 #include "core/thread/Thread.hpp"
 
+#include <string.h>
 #include <threads.h>
 
 #include "core/utils/Meta.hpp"
 #include "core/utils/Utility.hpp"
 
 static void reset(thrd_t* t) {
-    Core::memorySet(t, 0, sizeof(thrd_t));
+    memset(t, 0, sizeof(thrd_t));
 }
 
 Core::Thread::Thread() : thread() {
@@ -20,7 +21,7 @@ Core::Thread::Thread(Thread&& other) : thread() {
 
 static bool doesExist(thrd_t* t) {
     thrd_t zero{};
-    return !Core::memoryCompare(&zero, t, sizeof(thrd_t));
+    return memcmp(&zero, t, sizeof(thrd_t)) != 0;
 }
 
 Core::Thread::~Thread() {
@@ -54,7 +55,7 @@ check_return Core::Error Core::Thread::join(int* returnValue) {
 
 void Core::Thread::swap(Thread& other) {
     thrd_t tmp;
-    memoryCopy(&tmp, thread.as<thrd_t>(), sizeof(thrd_t));
-    memoryCopy(thread.as<thrd_t>(), other.thread.as<thrd_t>(), sizeof(thrd_t));
-    memoryCopy(other.thread.as<thrd_t>(), &tmp, sizeof(thrd_t));
+    memcpy(&tmp, thread.as<thrd_t>(), sizeof(thrd_t));
+    memcpy(thread.as<thrd_t>(), other.thread.as<thrd_t>(), sizeof(thrd_t));
+    memcpy(other.thread.as<thrd_t>(), &tmp, sizeof(thrd_t));
 }

+ 19 - 32
src/Utility.cpp

@@ -5,6 +5,7 @@
 #include <string.h>
 
 #include "ErrorSimulator.hpp"
+#include "core/utils/Error.hpp"
 #include "core/utils/Logger.hpp"
 
 static Core::ExitHandler exitHandler = nullptr;
@@ -28,14 +29,13 @@ void Core::setExitHandler(ExitHandler eh, void* data) {
 }
 
 #define CORE_TO_STRING(type, cast, format)                                     \
-    check_return Core::Error Core::toString(type t, char* buffer, int size) {  \
-        if(size < 0) {                                                         \
-            return ErrorCode::NEGATIVE_ARGUMENT;                               \
+    CError Core::toString(type t, char* buffer, size_t size) {                 \
+        int w = snprintf(buffer, size, format, static_cast<cast>(t));          \
+        if(w < 0) {                                                            \
+            return ErrorCode::ERROR;                                           \
         }                                                                      \
-        return snprintf(buffer, static_cast<unsigned int>(size), format,       \
-                        static_cast<cast>(t)) >= size                          \
-                   ? ErrorCode::CAPACITY_REACHED                               \
-                   : ErrorCode::NONE;                                          \
+        return static_cast<size_t>(w) >= size ? ErrorCode::CAPACITY_REACHED    \
+                                              : ErrorCode::NONE;               \
     }
 
 CORE_TO_STRING(signed short, signed short, "%hd")
@@ -50,47 +50,34 @@ CORE_TO_STRING(float, double, "%.2f")
 CORE_TO_STRING(double, double, "%.2lf")
 CORE_TO_STRING(long double, long double, "%.2Lf")
 
-Core::Error Core::putChar(int c) {
-    return putchar(c) == EOF ? ErrorCode::BLOCKED_STDOUT : ErrorCode::NONE;
-}
-
-Core::Error Core::putChars(const char* s) {
-    return fputs(s, stdout) == EOF ? ErrorCode::BLOCKED_STDOUT
-                                   : ErrorCode::NONE;
-}
-
-void Core::memorySet(void* p, int c, i64 n) {
-    if(n <= 0) {
-        return;
+void Core::print(int c) {
+    if(putchar(c) < 0) {
+        CORE_EXIT(static_cast<int>(ErrorCode::BLOCKED_STDOUT));
     }
-    memset(p, c, static_cast<u64>(n));
 }
 
-void Core::memoryCopy(void* dest, const void* src, i64 n) {
-    if(n <= 0) {
-        return;
+void Core::print(const char* s) {
+    if(fputs(s, stdout) < 0) {
+        CORE_EXIT(static_cast<int>(ErrorCode::BLOCKED_STDOUT));
     }
-    memcpy(dest, src, static_cast<u64>(n));
 }
 
-bool Core::memoryCompare(const void* a, const void* b, i64 n) {
-    return n <= 0 ? true : memcmp(a, b, static_cast<u64>(n)) == 0;
+void Core::printLine(const char* s) {
+    if(puts(s) < 0) {
+        CORE_EXIT(static_cast<int>(ErrorCode::BLOCKED_STDOUT));
+    }
 }
 
-Core::Error Core::reallocate(char*& p, i64 n) {
+Core::Error Core::reallocate(char*& p, size_t n) {
     if(n <= 0) {
         free(p);
         p = nullptr;
         return ErrorCode::NONE;
     }
-    char* newP = static_cast<char*>(realloc(p, static_cast<u64>(n)));
+    char* newP = static_cast<char*>(realloc(p, n));
     if(newP == nullptr || CORE_REALLOC_FAIL(newP)) {
         return ErrorCode::OUT_OF_MEMORY;
     }
     p = newP;
     return ErrorCode::NONE;
 }
-
-void Core::free(void* p) {
-    ::free(p);
-}

BIN
test/.Test.hpp.swo


+ 2 - 2
test/Main.cpp

@@ -11,10 +11,10 @@ static void onExit(int code, void* data) {
     Core::String32<1024> s;
     CORE_TEST_ERROR(s.append("Hello from exit #: #"));
     CORE_TEST_ERROR(s.format(code, i));
-    CORE_TEST_ERROR(s.printLine());
+    s.printLine();
     Core::String8<64> s8;
     CORE_TEST_ERROR(s8.append("Hello from exit"));
-    CORE_TEST_ERROR(s8.printLine());
+    s8.printLine();
     Core::Test::finalize();
 }
 

+ 2 - 2
test/Test.hpp

@@ -66,12 +66,12 @@ namespace Core::Test {
         bool checkFloat(const char* file, int line, float wanted, float actual,
                         float error);
 
-        template<int N, typename T>
+        template<size_t N, typename T>
         bool checkVector(const char* file, int line,
                          const Core::Vector<N, T>& wanted,
                          const Core::Vector<N, T>& actual, float error) {
             bool result = true;
-            for(int i = 0; i < N; i++) {
+            for(size_t i = 0; i < N; i++) {
                 result &= checkFloat(file, line, static_cast<float>(wanted[i]),
                                      static_cast<float>(actual[i]), error);
             }

+ 42 - 42
test/modules/ArrayListTests.cpp

@@ -1,12 +1,12 @@
 #include "../Tests.hpp"
 #include "core/data/ArrayList.hpp"
 
-template class Core::ArrayList<int, 20>;
-using IntList = Core::ArrayList<int, 20>;
+template class Core::ArrayList<size_t, 20>;
+using IntList = Core::ArrayList<size_t, 20>;
 
 static void testAdd() {
     IntList list;
-    CORE_TEST_ERROR(list.add(5));
+    CORE_TEST_ERROR(list.add(5u));
 
     CORE_TEST_EQUAL(5, list[0]);
     CORE_TEST_EQUAL(1, list.getLength());
@@ -14,9 +14,9 @@ static void testAdd() {
 
 static void testMultipleAdd() {
     IntList list;
-    CORE_TEST_ERROR(list.add(4));
-    CORE_TEST_ERROR(list.add(3));
-    CORE_TEST_ERROR(list.add(2));
+    CORE_TEST_ERROR(list.add(4u));
+    CORE_TEST_ERROR(list.add(3u));
+    CORE_TEST_ERROR(list.add(2u));
     CORE_TEST_EQUAL(4, list[0]);
     CORE_TEST_EQUAL(3, list[1]);
     CORE_TEST_EQUAL(2, list[2]);
@@ -25,65 +25,65 @@ static void testMultipleAdd() {
 
 static void testAddReplace() {
     IntList list;
-    CORE_TEST_ERROR(list.add(5));
+    CORE_TEST_ERROR(list.add(5u));
     list[0] = 3;
     CORE_TEST_EQUAL(3, list[0]);
 }
 
 static void testClear() {
     IntList list;
-    CORE_TEST_ERROR(list.add(5));
-    CORE_TEST_ERROR(list.add(4));
+    CORE_TEST_ERROR(list.add(5u));
+    CORE_TEST_ERROR(list.add(4u));
     list.clear();
     CORE_TEST_EQUAL(0, list.getLength());
 }
 
 static void testOverflow(bool light) {
     IntList list;
-    for(int i = 0; i < 20; i++) {
+    for(size_t i = 0; i < 20; i++) {
         CORE_TEST_ERROR(list.add(i));
     }
-    int limit = light ? 1000 : 100000;
-    for(int i = 0; i < limit; i++) {
+    size_t limit = light ? 1000 : 100000;
+    for(size_t i = 0; i < limit; i++) {
         CORE_TEST_EQUAL(Core::ErrorCode::CAPACITY_REACHED, list.add(i));
     }
-    for(int i = 0; i < list.getLength(); i++) {
+    for(size_t i = 0; i < list.getLength(); i++) {
         CORE_TEST_EQUAL(i, list[i]);
     }
 }
 
 static void testCopy() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
-    CORE_TEST_ERROR(list.add(2));
-    CORE_TEST_ERROR(list.add(3));
+    CORE_TEST_ERROR(list.add(1u));
+    CORE_TEST_ERROR(list.add(2u));
+    CORE_TEST_ERROR(list.add(3u));
 
     IntList copy(list);
     CORE_TEST_EQUAL(list.getLength(), copy.getLength());
-    for(int i = 0; i < copy.getLength() && i < list.getLength(); i++) {
+    for(size_t i = 0; i < copy.getLength() && i < list.getLength(); i++) {
         CORE_TEST_EQUAL(list[i], copy[i]);
     }
 }
 
 static void testCopyAssignment() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
-    CORE_TEST_ERROR(list.add(2));
-    CORE_TEST_ERROR(list.add(3));
+    CORE_TEST_ERROR(list.add(1u));
+    CORE_TEST_ERROR(list.add(2u));
+    CORE_TEST_ERROR(list.add(3u));
 
     IntList copy;
     copy = list;
     CORE_TEST_EQUAL(list.getLength(), copy.getLength());
-    for(int i = 0; i < copy.getLength() && i < list.getLength(); i++) {
+    for(size_t i = 0; i < copy.getLength() && i < list.getLength(); i++) {
         CORE_TEST_EQUAL(list[i], copy[i]);
     }
 }
 
 static void testMove() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
-    CORE_TEST_ERROR(list.add(2));
-    CORE_TEST_ERROR(list.add(3));
+    CORE_TEST_ERROR(list.add(1u));
+    CORE_TEST_ERROR(list.add(2u));
+    CORE_TEST_ERROR(list.add(3u));
 
     IntList move(Core::move(list));
     CORE_TEST_EQUAL(0, list.getLength());
@@ -95,9 +95,9 @@ static void testMove() {
 
 static void testMoveAssignment() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
-    CORE_TEST_ERROR(list.add(2));
-    CORE_TEST_ERROR(list.add(3));
+    CORE_TEST_ERROR(list.add(1u));
+    CORE_TEST_ERROR(list.add(2u));
+    CORE_TEST_ERROR(list.add(3u));
 
     IntList move;
     move = Core::move(list);
@@ -110,15 +110,15 @@ static void testMoveAssignment() {
 
 static void testToString1() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
-    CORE_TEST_ERROR(list.add(243));
-    CORE_TEST_ERROR(list.add(-423));
-    CORE_TEST_STRING("[1, 243, -423]", list);
+    CORE_TEST_ERROR(list.add(1u));
+    CORE_TEST_ERROR(list.add(243u));
+    CORE_TEST_ERROR(list.add(423u));
+    CORE_TEST_STRING("[1, 243, 423]", list);
 }
 
 static void testToString2() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
+    CORE_TEST_ERROR(list.add(1u));
     CORE_TEST_STRING("[1]", list);
 }
 
@@ -129,16 +129,16 @@ static void testToString3() {
 
 static void testRemove() {
     IntList list;
-    CORE_TEST_ERROR(list.add(4));
-    CORE_TEST_ERROR(list.add(3));
-    CORE_TEST_ERROR(list.add(2));
+    CORE_TEST_ERROR(list.add(4u));
+    CORE_TEST_ERROR(list.add(3u));
+    CORE_TEST_ERROR(list.add(2u));
     CORE_TEST_ERROR(list.removeBySwap(0));
     CORE_TEST_EQUAL(2, list[0]);
     CORE_TEST_EQUAL(3, list[1]);
     CORE_TEST_EQUAL(2, list.getLength());
     CORE_TEST_EQUAL(Core::ErrorCode::INVALID_INDEX, list.removeBySwap(4));
-    CORE_TEST_EQUAL(Core::ErrorCode::INVALID_INDEX, list.removeBySwap(-1));
-    CORE_TEST_EQUAL(Core::ErrorCode::INVALID_INDEX, list.removeBySwap(-5));
+    CORE_TEST_EQUAL(Core::ErrorCode::INVALID_INDEX, list.removeBySwap(3654));
+    CORE_TEST_EQUAL(Core::ErrorCode::INVALID_INDEX, list.removeBySwap(756756));
     CORE_TEST_EQUAL(2, list[0]);
     CORE_TEST_EQUAL(3, list[1]);
     CORE_TEST_EQUAL(2, list.getLength());
@@ -151,13 +151,13 @@ static void testRemove() {
 
 static void testForRange() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
-    CORE_TEST_ERROR(list.add(2));
-    CORE_TEST_ERROR(list.add(3));
-    for(int& i : list) {
+    CORE_TEST_ERROR(list.add(1u));
+    CORE_TEST_ERROR(list.add(2u));
+    CORE_TEST_ERROR(list.add(3u));
+    for(size_t& i : list) {
         i++;
     }
-    for(int i = 0; i < list.getLength(); i++) {
+    for(size_t i = 0; i < list.getLength(); i++) {
         CORE_TEST_EQUAL(i + 2, list[i]);
     }
 }

+ 18 - 18
test/modules/ArrayStringTests.cpp

@@ -198,7 +198,7 @@ static void testIntOverflow8() {
     CORE_TEST_EQUAL(Core::ErrorCode::CAPACITY_REACHED, s.append(123456));
 
     String8 o;
-    for(int i = 0; i < s.getCapacity(); i++) {
+    for(size_t i = 0; i < s.getCapacity(); i++) {
         CORE_TEST_ERROR(o.append(i + 1));
     }
 
@@ -285,16 +285,16 @@ static void testSearch8() {
     CORE_TEST_EQUAL(1, s.search(s2));
     CORE_TEST_EQUAL(2, s.search(s3));
     CORE_TEST_EQUAL(7, s.search(s4));
-    CORE_TEST_EQUAL(-1, s.search(s5));
+    CORE_TEST_EQUAL(SIZE_MAX, s.search(s5));
     CORE_TEST_EQUAL(0, s.search(s6));
-    CORE_TEST_EQUAL(-1, s.search(s7));
+    CORE_TEST_EQUAL(SIZE_MAX, s.search(s7));
 
-    CORE_TEST_EQUAL(-1, s.search(s2, 3));
-    CORE_TEST_EQUAL(-1, s.search(s3, 3));
+    CORE_TEST_EQUAL(SIZE_MAX, s.search(s2, 3));
+    CORE_TEST_EQUAL(SIZE_MAX, s.search(s3, 3));
     CORE_TEST_EQUAL(7, s.search(s4, 3));
-    CORE_TEST_EQUAL(-1, s.search(s5, 3));
+    CORE_TEST_EQUAL(SIZE_MAX, s.search(s5, 3));
     CORE_TEST_EQUAL(3, s.search(s6, 3));
-    CORE_TEST_EQUAL(-1, s.search(s7, 3));
+    CORE_TEST_EQUAL(SIZE_MAX, s.search(s7, 3));
 }
 
 static void testContains8() {
@@ -344,7 +344,7 @@ static void testSubString8() {
     CORE_TEST_ERROR(s.append("01üää3ä"));
 
     String8 sub;
-    CORE_TEST_ERROR(s.substring(sub, -2));
+    CORE_TEST_ERROR(s.substring(sub, 0));
     CORE_TEST_STRING("01üää3ä", sub);
     CORE_TEST_ERROR(s.substring(sub, 2));
     CORE_TEST_STRING("üää3ä", sub);
@@ -436,7 +436,7 @@ static void testPrint8() {
     CORE_TEST_ERROR(s.append(L'\u8000'));
     CORE_TEST_ERROR(s.append(U'\U00100000'));
     CORE_TEST_EQUAL(build("\u0040\u0400\u8000\U00100000"), s);
-    CORE_TEST_ERROR(s.print());
+    s.print();
 }
 
 static void testKeepHash8() {
@@ -649,7 +649,7 @@ static void testIntOverflow32() {
     CORE_TEST_EQUAL(Core::ErrorCode::CAPACITY_REACHED, s.append(123456));
 
     String32 o;
-    for(int i = 0; i < s.getCapacity(); i++) {
+    for(size_t i = 0; i < s.getCapacity(); i++) {
         CORE_TEST_ERROR(o.append(i + 1));
     }
 
@@ -736,16 +736,16 @@ static void testSearch32() {
     CORE_TEST_EQUAL(1, s.search(s2));
     CORE_TEST_EQUAL(2, s.search(s3));
     CORE_TEST_EQUAL(7, s.search(s4));
-    CORE_TEST_EQUAL(-1, s.search(s5));
+    CORE_TEST_EQUAL(SIZE_MAX, s.search(s5));
     CORE_TEST_EQUAL(0, s.search(s6));
-    CORE_TEST_EQUAL(-1, s.search(s7));
+    CORE_TEST_EQUAL(SIZE_MAX, s.search(s7));
 
-    CORE_TEST_EQUAL(-1, s.search(s2, 3));
-    CORE_TEST_EQUAL(-1, s.search(s3, 3));
+    CORE_TEST_EQUAL(SIZE_MAX, s.search(s2, 3));
+    CORE_TEST_EQUAL(SIZE_MAX, s.search(s3, 3));
     CORE_TEST_EQUAL(7, s.search(s4, 3));
-    CORE_TEST_EQUAL(-1, s.search(s5, 3));
+    CORE_TEST_EQUAL(SIZE_MAX, s.search(s5, 3));
     CORE_TEST_EQUAL(3, s.search(s6, 3));
-    CORE_TEST_EQUAL(-1, s.search(s7, 3));
+    CORE_TEST_EQUAL(SIZE_MAX, s.search(s7, 3));
 }
 
 static void testContains32() {
@@ -804,7 +804,7 @@ static void testSubString32() {
     CORE_TEST_ERROR(s.append(U"01üää3ä"));
 
     String32 sub;
-    CORE_TEST_ERROR(s.substring(sub, -2));
+    CORE_TEST_ERROR(s.substring(sub, 0));
     CORE_TEST_STRING(U"01üää3ä", sub);
     CORE_TEST_ERROR(s.substring(sub, 1));
     CORE_TEST_STRING(U"1üää3ä", sub);
@@ -898,7 +898,7 @@ static void testPrint32() {
     CORE_TEST_ERROR(s.append(L'\u8000'));
     CORE_TEST_ERROR(s.append(U'\U00100000'));
     CORE_TEST_EQUAL(build(U"\u0040\u0400\u8000\U00100000"), s);
-    CORE_TEST_ERROR(s.print());
+    s.print();
 }
 
 static void testVariousUnicode32() {

+ 13 - 12
test/modules/ArrayTests.cpp

@@ -1,14 +1,15 @@
 #include "../Tests.hpp"
 #include "core/data/Array.hpp"
 
-template class Core::Array<int, 3>;
+template class Core::Array<size_t, 3>;
+using TestArray = Core::Array<size_t, 3>;
 
 static void testToString1() {
-    Core::Array<int, 3> a;
+    TestArray a;
     a[0] = 1;
     a[1] = 243;
-    a[2] = -423;
-    CORE_TEST_STRING("[1, 243, -423]", a);
+    a[2] = 423;
+    CORE_TEST_STRING("[1, 243, 423]", a);
 }
 
 static void testToString2() {
@@ -18,25 +19,25 @@ static void testToString2() {
 }
 
 static void testReadConst() {
-    Core::Array<int, 3> a;
-    for(int i = 0; i < a.getLength(); i++) {
+    TestArray a;
+    for(size_t i = 0; i < a.getLength(); i++) {
         a[i] = i;
     }
-    const Core::Array<int, 3>& c = a;
-    for(int i = 0; i < c.getLength(); i++) {
+    const TestArray& c = a;
+    for(size_t i = 0; i < c.getLength(); i++) {
         CORE_TEST_EQUAL(i, c[i]);
     }
 }
 
 static void testRangeFor() {
-    Core::Array<int, 3> a;
-    for(int i = 0; i < a.getLength(); i++) {
+    TestArray a;
+    for(size_t i = 0; i < a.getLength(); i++) {
         a[i] = i;
     }
-    for(int& i : a) {
+    for(size_t& i : a) {
         i++;
     }
-    for(int i = 0; i < a.getLength(); i++) {
+    for(size_t i = 0; i < a.getLength(); i++) {
         CORE_TEST_EQUAL(i + 1, a[i]);
     }
 }

+ 4 - 4
test/modules/BufferTests.cpp

@@ -1,13 +1,13 @@
 #include "../Tests.hpp"
 #include "core/utils/Buffer.hpp"
 
-static constexpr int SIZE_TYPES =
+static constexpr size_t SIZE_TYPES =
     sizeof(int) + sizeof(long) + sizeof(float) + sizeof(double);
 
 static void testAdd(bool light) {
     Core::Buffer buffer(10);
-    int limit = light ? 1000 : 100000;
-    for(int i = 0; i < limit; i++) {
+    size_t limit = light ? 1000 : 100000;
+    for(size_t i = 0; i < limit; i++) {
         CORE_TEST_ERROR(buffer.add(5));
         CORE_TEST_ERROR(buffer.add(5L));
         CORE_TEST_ERROR(buffer.add(5.0f));
@@ -28,7 +28,7 @@ static void testCopy() {
     CORE_TEST_ERROR(buffer2.copyFrom(buffer));
     if(CORE_TEST_EQUAL(SIZE_TYPES * 10, buffer.getLength()) &&
        CORE_TEST_EQUAL(SIZE_TYPES * 10, buffer2.getLength())) {
-        CORE_TEST_TRUE(Core::memoryCompare(buffer, buffer2, SIZE_TYPES * 10));
+        CORE_TEST_TRUE(memcmp(buffer, buffer2, SIZE_TYPES * 10) == 0);
     }
 }
 

+ 27 - 25
test/modules/ErrorTests.cpp

@@ -3,33 +3,35 @@
 
 void Core::testError() {
     CORE_TEST_STRING("0", ErrorCode::NONE);
-    CORE_TEST_STRING("1", ErrorCode::NEGATIVE_ARGUMENT);
-    CORE_TEST_STRING("01", ErrorCode::CAPACITY_REACHED);
-    CORE_TEST_STRING("001", ErrorCode::BLOCKED_STDOUT);
-    CORE_TEST_STRING("0001", ErrorCode::OUT_OF_MEMORY);
-    CORE_TEST_STRING("00001", ErrorCode::INVALID_CHAR);
-    CORE_TEST_STRING("000001", ErrorCode::NOT_FOUND);
-    CORE_TEST_STRING("0000001", ErrorCode::INVALID_STATE);
-    CORE_TEST_STRING("00000001", ErrorCode::INVALID_INDEX);
-    CORE_TEST_STRING("000000001", ErrorCode::INVALID_ARGUMENT);
-    CORE_TEST_STRING("0000000001", ErrorCode::TIME_NOT_AVAILABLE);
-    CORE_TEST_STRING("00000000001", ErrorCode::SLEEP_INTERRUPTED);
-    CORE_TEST_STRING("000000000001", ErrorCode::THREAD_ERROR);
-    CORE_TEST_STRING("0000000000001", ErrorCode::MUTEX_ERROR);
-    CORE_TEST_STRING("00000000000001", ErrorCode::EXISTING_KEY);
-    CORE_TEST_STRING("000000000000001", ErrorCode::CANNOT_OPEN_FILE);
-    CORE_TEST_STRING("0000000000000001", ErrorCode::END_OF_FILE);
+    CORE_TEST_STRING("1", ErrorCode::ERROR);
+    CORE_TEST_STRING("01", ErrorCode::NEGATIVE_ARGUMENT);
+    CORE_TEST_STRING("001", ErrorCode::CAPACITY_REACHED);
+    CORE_TEST_STRING("0001", ErrorCode::BLOCKED_STDOUT);
+    CORE_TEST_STRING("00001", ErrorCode::OUT_OF_MEMORY);
+    CORE_TEST_STRING("000001", ErrorCode::INVALID_CHAR);
+    CORE_TEST_STRING("0000001", ErrorCode::NOT_FOUND);
+    CORE_TEST_STRING("00000001", ErrorCode::INVALID_STATE);
+    CORE_TEST_STRING("000000001", ErrorCode::INVALID_INDEX);
+    CORE_TEST_STRING("0000000001", ErrorCode::INVALID_ARGUMENT);
+    CORE_TEST_STRING("00000000001", ErrorCode::TIME_NOT_AVAILABLE);
+    CORE_TEST_STRING("000000000001", ErrorCode::SLEEP_INTERRUPTED);
+    CORE_TEST_STRING("0000000000001", ErrorCode::THREAD_ERROR);
+    CORE_TEST_STRING("00000000000001", ErrorCode::MUTEX_ERROR);
+    CORE_TEST_STRING("000000000000001", ErrorCode::EXISTING_KEY);
+    CORE_TEST_STRING("0000000000000001", ErrorCode::CANNOT_OPEN_FILE);
+    CORE_TEST_STRING("00000000000000001", ErrorCode::END_OF_FILE);
 
     CORE_TEST_STRING(
-        "1111111111111111",
-        ErrorCode::NEGATIVE_ARGUMENT | ErrorCode::CAPACITY_REACHED |
-            ErrorCode::BLOCKED_STDOUT | ErrorCode::OUT_OF_MEMORY |
-            ErrorCode::INVALID_CHAR | ErrorCode::NOT_FOUND |
-            ErrorCode::INVALID_STATE | ErrorCode::INVALID_INDEX |
-            ErrorCode::INVALID_ARGUMENT | ErrorCode::TIME_NOT_AVAILABLE |
-            ErrorCode::SLEEP_INTERRUPTED | ErrorCode::THREAD_ERROR |
-            ErrorCode::MUTEX_ERROR | ErrorCode::EXISTING_KEY |
-            ErrorCode::CANNOT_OPEN_FILE | ErrorCode::END_OF_FILE);
+        "11111111111111111",
+        ErrorCode::ERROR | ErrorCode::NEGATIVE_ARGUMENT |
+            ErrorCode::CAPACITY_REACHED | ErrorCode::BLOCKED_STDOUT |
+            ErrorCode::OUT_OF_MEMORY | ErrorCode::INVALID_CHAR |
+            ErrorCode::NOT_FOUND | ErrorCode::INVALID_STATE |
+            ErrorCode::INVALID_INDEX | ErrorCode::INVALID_ARGUMENT |
+            ErrorCode::TIME_NOT_AVAILABLE | ErrorCode::SLEEP_INTERRUPTED |
+            ErrorCode::THREAD_ERROR | ErrorCode::MUTEX_ERROR |
+            ErrorCode::EXISTING_KEY | ErrorCode::CANNOT_OPEN_FILE |
+            ErrorCode::END_OF_FILE);
 
     char buffer[4];
     CORE_TEST_EQUAL(

+ 1 - 1
test/modules/HashedStringTests.cpp

@@ -39,7 +39,7 @@ static void testLength() {
 static void testHashCode() {
     HString a;
     HString b("wusi");
-    CORE_TEST_EQUAL(a.hashCode(), 0u);
+    CORE_TEST_EQUAL(a.hashCode(), 0lu);
     CORE_TEST_TRUE(b.hashCode() != 0u);
 }
 

+ 39 - 39
test/modules/LinkedListTests.cpp

@@ -2,8 +2,8 @@
 #include "../Tests.hpp"
 #include "core/data/LinkedList.hpp"
 
-template struct Core::LinkedList<int>;
-using IntList = Core::LinkedList<int>;
+template struct Core::LinkedList<size_t>;
+using IntList = Core::LinkedList<size_t>;
 
 struct LinkedListTester final {
     int a;
@@ -22,7 +22,7 @@ static void testWithoutCopyOrMove() {
 
 static void testAdd() {
     IntList list;
-    CORE_TEST_ERROR(list.add(5));
+    CORE_TEST_ERROR(list.add(5u));
     auto iter = list.begin();
     if(CORE_TEST_TRUE(iter != list.end())) {
         CORE_TEST_EQUAL(5, *iter);
@@ -32,9 +32,9 @@ static void testAdd() {
 
 static void testMultipleAdd() {
     IntList list;
-    CORE_TEST_ERROR(list.add(4));
-    CORE_TEST_ERROR(list.add(3));
-    CORE_TEST_ERROR(list.add(2));
+    CORE_TEST_ERROR(list.add(4u));
+    CORE_TEST_ERROR(list.add(3u));
+    CORE_TEST_ERROR(list.add(2u));
     auto iter = list.begin();
     CORE_TEST_EQUAL(4, *iter);
     CORE_TEST_EQUAL(3, *(++iter));
@@ -44,21 +44,21 @@ static void testMultipleAdd() {
 
 static void testClear() {
     IntList list;
-    CORE_TEST_ERROR(list.add(5));
-    CORE_TEST_ERROR(list.add(4));
+    CORE_TEST_ERROR(list.add(5u));
+    CORE_TEST_ERROR(list.add(4u));
     list.clear();
     CORE_TEST_EQUAL(0, list.getLength());
     CORE_TEST_FALSE(list.begin() != list.end());
 }
 
 static void testBigAdd(bool light) {
-    int limit = light ? 10000 : 100000;
+    size_t limit = light ? 10000 : 100000;
     IntList list;
-    for(int i = 0; i < limit; i++) {
+    for(size_t i = 0; i < limit; i++) {
         CORE_TEST_ERROR(list.add(i));
     }
     auto iter = list.begin();
-    for(int i = 0; i < list.getLength(); i++) {
+    for(size_t i = 0; i < list.getLength(); i++) {
         CORE_TEST_EQUAL(i, *iter);
         ++iter;
     }
@@ -67,16 +67,16 @@ static void testBigAdd(bool light) {
 
 static void testCopy() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
-    CORE_TEST_ERROR(list.add(2));
-    CORE_TEST_ERROR(list.add(3));
+    CORE_TEST_ERROR(list.add(1u));
+    CORE_TEST_ERROR(list.add(2u));
+    CORE_TEST_ERROR(list.add(3u));
 
     IntList copy;
     CORE_TEST_ERROR(copy.copyFrom(list));
     CORE_TEST_EQUAL(list.getLength(), copy.getLength());
     auto iterA = list.begin();
     auto iterB = copy.begin();
-    for(int i = 0; i < copy.getLength() && i < list.getLength(); i++) {
+    for(size_t i = 0; i < copy.getLength() && i < list.getLength(); i++) {
         CORE_TEST_EQUAL(*iterA, *iterB);
         ++iterA;
         ++iterB;
@@ -85,9 +85,9 @@ static void testCopy() {
 
 static void testMove() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
-    CORE_TEST_ERROR(list.add(2));
-    CORE_TEST_ERROR(list.add(3));
+    CORE_TEST_ERROR(list.add(1u));
+    CORE_TEST_ERROR(list.add(2u));
+    CORE_TEST_ERROR(list.add(3u));
 
     const IntList move(Core::move(list));
     CORE_TEST_EQUAL(0, list.getLength());
@@ -100,9 +100,9 @@ static void testMove() {
 
 static void testMoveAssignment() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
-    CORE_TEST_ERROR(list.add(2));
-    CORE_TEST_ERROR(list.add(3));
+    CORE_TEST_ERROR(list.add(1u));
+    CORE_TEST_ERROR(list.add(2u));
+    CORE_TEST_ERROR(list.add(3u));
 
     IntList move;
     move = Core::move(list);
@@ -116,15 +116,15 @@ static void testMoveAssignment() {
 
 static void testToString1() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
-    CORE_TEST_ERROR(list.add(243));
-    CORE_TEST_ERROR(list.add(-423));
-    CORE_TEST_STRING("[1, 243, -423]", list);
+    CORE_TEST_ERROR(list.add(1u));
+    CORE_TEST_ERROR(list.add(243u));
+    CORE_TEST_ERROR(list.add(423u));
+    CORE_TEST_STRING("[1, 243, 423]", list);
 }
 
 static void testToString2() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
+    CORE_TEST_ERROR(list.add(1u));
     CORE_TEST_STRING("[1]", list);
 }
 
@@ -139,10 +139,10 @@ static void testRemove() {
     IntList::Node* b = nullptr;
     IntList::Node* c = nullptr;
     IntList::Node* d = nullptr;
-    CORE_TEST_ERROR(list.put(a, 4));
-    CORE_TEST_ERROR(list.put(b, 3));
-    CORE_TEST_ERROR(list.put(c, 2));
-    CORE_TEST_ERROR(list.put(d, 1));
+    CORE_TEST_ERROR(list.put(a, 4u));
+    CORE_TEST_ERROR(list.put(b, 3u));
+    CORE_TEST_ERROR(list.put(c, 2u));
+    CORE_TEST_ERROR(list.put(d, 1u));
     CORE_TEST_NOT_NULL(a);
     CORE_TEST_NOT_NULL(b);
     CORE_TEST_NOT_NULL(c);
@@ -178,10 +178,10 @@ static void testRemove() {
 
 static void testRemoveFirst() {
     IntList list;
-    CORE_TEST_ERROR(list.add(4));
-    CORE_TEST_ERROR(list.add(3));
-    CORE_TEST_ERROR(list.add(2));
-    CORE_TEST_ERROR(list.add(1));
+    CORE_TEST_ERROR(list.add(4u));
+    CORE_TEST_ERROR(list.add(3u));
+    CORE_TEST_ERROR(list.add(2u));
+    CORE_TEST_ERROR(list.add(1u));
 
     list.removeFirst();
     auto iter = list.begin();
@@ -227,10 +227,10 @@ static void testRemoveFirst() {
 
 static void testRemoveLast() {
     IntList list;
-    CORE_TEST_ERROR(list.add(4));
-    CORE_TEST_ERROR(list.add(3));
-    CORE_TEST_ERROR(list.add(2));
-    CORE_TEST_ERROR(list.add(1));
+    CORE_TEST_ERROR(list.add(4u));
+    CORE_TEST_ERROR(list.add(3u));
+    CORE_TEST_ERROR(list.add(2u));
+    CORE_TEST_ERROR(list.add(1u));
 
     list.removeLast();
     auto iter = list.begin();
@@ -280,7 +280,7 @@ static void testOutOfMemory() {
     int memFails = 0;
     for(int i = 0; i < 40; i++) {
         Core::Fail::leftAllocations = i;
-        Core::Error e = list.add(1);
+        Core::Error e = list.add(1u);
         if(e == Core::ErrorCode::OUT_OF_MEMORY) {
             memFails++;
         }

+ 41 - 42
test/modules/ListTests.cpp

@@ -3,12 +3,12 @@
 #include "core/data/List.hpp"
 #include "core/math/Math.hpp"
 
-template class Core::List<int>;
-using IntList = Core::List<int>;
+template class Core::List<size_t>;
+using IntList = Core::List<size_t>;
 
 static void testAdd() {
     IntList list;
-    if(CORE_TEST_ERROR(list.add(5))) {
+    if(CORE_TEST_ERROR(list.add(5u))) {
         CORE_TEST_EQUAL(5, list[0]);
     }
     CORE_TEST_EQUAL(1, list.getLength());
@@ -16,9 +16,9 @@ static void testAdd() {
 
 static void testMultipleAdd() {
     IntList list;
-    CORE_TEST_ERROR(list.add(4));
-    CORE_TEST_ERROR(list.add(3));
-    CORE_TEST_ERROR(list.add(2));
+    CORE_TEST_ERROR(list.add(4u));
+    CORE_TEST_ERROR(list.add(3u));
+    CORE_TEST_ERROR(list.add(2u));
     CORE_TEST_EQUAL(4, list[0]);
     CORE_TEST_EQUAL(3, list[1]);
     CORE_TEST_EQUAL(2, list[2]);
@@ -27,7 +27,7 @@ static void testMultipleAdd() {
 
 static void testAddReplace() {
     IntList list;
-    if(CORE_TEST_ERROR(list.add(5))) {
+    if(CORE_TEST_ERROR(list.add(5u))) {
         list[0] = 3;
     }
     CORE_TEST_EQUAL(3, list[0]);
@@ -35,17 +35,17 @@ static void testAddReplace() {
 
 static void testClear() {
     IntList list;
-    CORE_TEST_ERROR(list.add(5));
-    CORE_TEST_ERROR(list.add(4));
+    CORE_TEST_ERROR(list.add(5u));
+    CORE_TEST_ERROR(list.add(4u));
     list.clear();
     CORE_TEST_EQUAL(0, list.getLength());
 }
 
 static void testShrink() {
     IntList list;
-    CORE_TEST_ERROR(list.add(5));
-    CORE_TEST_ERROR(list.add(4));
-    CORE_TEST_ERROR(list.add(3));
+    CORE_TEST_ERROR(list.add(5u));
+    CORE_TEST_ERROR(list.add(4u));
+    CORE_TEST_ERROR(list.add(3u));
     CORE_TEST_TRUE(list.getCapacity() >= 3);
     CORE_TEST_ERROR(list.shrink());
     CORE_TEST_TRUE(list.getLength() == 3);
@@ -56,12 +56,12 @@ static void testShrink() {
 }
 
 static void testBigAdd(bool light) {
-    int limit = light ? 10000 : 100000;
+    size_t limit = light ? 10000 : 100000;
     IntList list;
-    for(int i = 0; i < limit; i++) {
+    for(size_t i = 0; i < limit; i++) {
         CORE_TEST_ERROR(list.add(i));
     }
-    for(int i = 0; i < list.getLength(); i++) {
+    for(size_t i = 0; i < list.getLength(); i++) {
         CORE_TEST_EQUAL(i, list[i]);
     }
     CORE_TEST_EQUAL(limit, list.getLength());
@@ -69,24 +69,24 @@ static void testBigAdd(bool light) {
 
 static void testCopy() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
-    CORE_TEST_ERROR(list.add(2));
-    CORE_TEST_ERROR(list.add(3));
+    CORE_TEST_ERROR(list.add(1u));
+    CORE_TEST_ERROR(list.add(2u));
+    CORE_TEST_ERROR(list.add(3u));
 
     IntList copy;
     CORE_TEST_ERROR(copy.copyFrom(list));
     CORE_TEST_EQUAL(list.getLength(), copy.getLength());
-    i64 limit = Core::Math::min(copy.getLength(), list.getLength());
-    for(i64 i = 0; i < limit; i++) {
+    size_t limit = Core::Math::min(copy.getLength(), list.getLength());
+    for(size_t i = 0; i < limit; i++) {
         CORE_TEST_EQUAL(list[i], copy[i]);
     }
 }
 
 static void testMove() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
-    CORE_TEST_ERROR(list.add(2));
-    CORE_TEST_ERROR(list.add(3));
+    CORE_TEST_ERROR(list.add(1u));
+    CORE_TEST_ERROR(list.add(2u));
+    CORE_TEST_ERROR(list.add(3u));
 
     IntList move(Core::move(list));
     CORE_TEST_EQUAL(0, list.getLength());
@@ -98,9 +98,9 @@ static void testMove() {
 
 static void testMoveAssignment() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
-    CORE_TEST_ERROR(list.add(2));
-    CORE_TEST_ERROR(list.add(3));
+    CORE_TEST_ERROR(list.add(1u));
+    CORE_TEST_ERROR(list.add(2u));
+    CORE_TEST_ERROR(list.add(3u));
 
     IntList move;
     move = Core::move(list);
@@ -113,15 +113,15 @@ static void testMoveAssignment() {
 
 static void testToString1() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
-    CORE_TEST_ERROR(list.add(243));
-    CORE_TEST_ERROR(list.add(-423));
-    CORE_TEST_STRING("[1, 243, -423]", list);
+    CORE_TEST_ERROR(list.add(1u));
+    CORE_TEST_ERROR(list.add(243u));
+    CORE_TEST_ERROR(list.add(423u));
+    CORE_TEST_STRING("[1, 243, 423]", list);
 }
 
 static void testToString2() {
     IntList list;
-    CORE_TEST_ERROR(list.add(1));
+    CORE_TEST_ERROR(list.add(1u));
     CORE_TEST_STRING("[1]", list);
 }
 
@@ -132,10 +132,10 @@ static void testToString3() {
 
 static void testRemoveBySwap() {
     IntList list;
-    CORE_TEST_ERROR(list.add(4));
-    CORE_TEST_ERROR(list.add(3));
-    CORE_TEST_ERROR(list.add(2));
-    CORE_TEST_EQUAL(Core::ErrorCode::INVALID_INDEX, list.removeBySwap(-1));
+    CORE_TEST_ERROR(list.add(4u));
+    CORE_TEST_ERROR(list.add(3u));
+    CORE_TEST_ERROR(list.add(2u));
+    CORE_TEST_EQUAL(Core::ErrorCode::INVALID_INDEX, list.removeBySwap(534));
     CORE_TEST_ERROR(list.removeBySwap(0));
     CORE_TEST_EQUAL(Core::ErrorCode::INVALID_INDEX, list.removeBySwap(2));
     CORE_TEST_EQUAL(2, list[0]);
@@ -151,10 +151,10 @@ static void testRemoveBySwap() {
 
 static void testRemove() {
     IntList list;
-    CORE_TEST_ERROR(list.add(4));
-    CORE_TEST_ERROR(list.add(3));
-    CORE_TEST_ERROR(list.add(2));
-    CORE_TEST_EQUAL(Core::ErrorCode::INVALID_INDEX, list.remove(-1));
+    CORE_TEST_ERROR(list.add(4u));
+    CORE_TEST_ERROR(list.add(3u));
+    CORE_TEST_ERROR(list.add(2u));
+    CORE_TEST_EQUAL(Core::ErrorCode::INVALID_INDEX, list.remove(5356));
     CORE_TEST_ERROR(list.remove(0));
     CORE_TEST_EQUAL(Core::ErrorCode::INVALID_INDEX, list.remove(2));
     CORE_TEST_EQUAL(3, list[0]);
@@ -173,7 +173,7 @@ static void testResize() {
     IntList list;
     CORE_TEST_ERROR(list.resize(5, 10));
     CORE_TEST_EQUAL(5, list.getLength());
-    for(int i = 0; i < 5; i++) {
+    for(size_t i = 0; i < 5; i++) {
         CORE_TEST_EQUAL(10, list[i]);
     }
 }
@@ -182,7 +182,7 @@ static void testDefaultResize() {
     IntList list;
     CORE_TEST_ERROR(list.resize(5));
     CORE_TEST_EQUAL(5, list.getLength());
-    for(int i = 0; i < 5; i++) {
+    for(size_t i = 0; i < 5; i++) {
         CORE_TEST_EQUAL(0, list[i]);
     }
 }
@@ -190,7 +190,6 @@ static void testDefaultResize() {
 static void testInvalidReserve() {
     IntList list;
     CORE_TEST_ERROR(list.reserve(0));
-    CORE_TEST_ERROR(list.reserve(-5));
 }
 
 static void testShrinkExact() {

+ 8 - 8
test/modules/RandomTests.cpp

@@ -15,7 +15,7 @@ static void testAverage(bool light) {
 
 static void testCoin(bool light) {
     int limit = light ? 100000 : 1000000;
-    Core::Random r(553);
+    Core::Random r(5533);
     Core::Array<int, 2> c(0);
     for(int i = 0; i < limit; i++) {
         c[r.nextBool()]++;
@@ -26,15 +26,15 @@ static void testCoin(bool light) {
 }
 
 static void testDistribution(bool light) {
-    int limit = light ? 100000 : 1000000;
+    size_t limit = light ? 100000 : 1000000;
     Core::Random r(553);
     Core::Array<int, 102> c(0);
-    for(int i = 0; i < limit; i++) {
-        c[r.next(1, c.getLength() - 2)]++;
+    for(size_t i = 0; i < limit; i++) {
+        c[r.nextSize(1, c.getLength() - 2)]++;
     }
     CORE_TEST_EQUAL(0, c[0]);
     CORE_TEST_EQUAL(0, c[c.getLength() - 1]);
-    for(int i = 1; i < c.getLength() - 1; i++) {
+    for(size_t i = 1; i < c.getLength() - 1; i++) {
         CORE_TEST_FLOAT(0.01f,
                         static_cast<float>(c[i]) / static_cast<float>(limit),
                         0.001f);
@@ -54,7 +54,7 @@ static void testFloatAverage(bool light) {
 
 static void testFloatCoin(bool light) {
     int limit = light ? 100000 : 1000000;
-    Core::Random r(553);
+    Core::Random r(5534);
     Core::Array<int, 2> c(0);
     for(int i = 0; i < limit; i++) {
         c[r.nextFloat() < 0.5f]++;
@@ -69,11 +69,11 @@ static void testFloatDistribution(bool light) {
     Core::Random r(553);
     Core::Array<int, 102> c(0);
     for(int i = 0; i < limit; i++) {
-        c[static_cast<int>(r.nextFloat(1.0f, c.getLength() - 1))]++;
+        c[static_cast<size_t>(r.nextFloat(1.0f, c.getLength() - 1))]++;
     }
     CORE_TEST_EQUAL(0, c[0]);
     CORE_TEST_EQUAL(0, c[c.getLength() - 1]);
-    for(int i = 1; i < c.getLength() - 1; i++) {
+    for(size_t i = 1; i < c.getLength() - 1; i++) {
         CORE_TEST_FLOAT(0.01f,
                         static_cast<float>(c[i]) / static_cast<float>(limit),
                         0.003f);

+ 3 - 14
test/modules/UtilityTests.cpp

@@ -19,21 +19,11 @@ static void testIf() {
     CORE_TEST_TRUE((Core::IsSame<Core::If<false, int, double>, double>));
 }
 
-static void testNegativeArguments() {
-    char from[16];
-    Core::memorySet(from, 1, sizeof(from));
-    Core::memorySet(from, 0, -1);
-    char to[16];
-    Core::memorySet(to, 1, sizeof(to));
-    Core::memoryCopy(to, from, -1);
-    CORE_TEST_TRUE(Core::memoryCompare(from, to, sizeof(from)));
-}
-
-static void testNegativeRellocate() {
+static void testZeroRellocate() {
     char* buffer = nullptr;
     CORE_TEST_ERROR(Core::reallocate(buffer, 16));
     CORE_TEST_TRUE(buffer != nullptr);
-    CORE_TEST_ERROR(Core::reallocate(buffer, -1));
+    CORE_TEST_ERROR(Core::reallocate(buffer, 0));
     CORE_TEST_TRUE(buffer == nullptr);
 }
 
@@ -51,7 +41,6 @@ static void testReallocateFail() {
 void Core::testUtility() {
     testPopCount();
     testIf();
-    testNegativeArguments();
-    testNegativeRellocate();
+    testZeroRellocate();
     testReallocateFail();
 }