diff --git a/Jupiter/ArrayList.h b/Jupiter/ArrayList.h index 8f0c9c9..5f5baf0 100644 --- a/Jupiter/ArrayList.h +++ b/Jupiter/ArrayList.h @@ -41,7 +41,7 @@ namespace Jupiter * @param index Index of the data to get. * @return Data stored at the specified index. */ - T *get(unsigned int index) const; + T *get(size_t index) const; /** * @brief Removes the data at a specified index from the list, and returns the removed data. @@ -49,7 +49,7 @@ namespace Jupiter * @param n Index of the node to remove. * @return Data removed. */ - T *remove(unsigned int index); + T *remove(size_t index); /** * @brief Adds data to the list at a specified index. @@ -57,7 +57,7 @@ namespace Jupiter * @param data Data to add to the list. * @param index Position in the list to add the data to. */ - void add(T *data, unsigned int index); + void add(T *data, size_t index); /** * @brief Adds data to the end of the list. @@ -103,20 +103,20 @@ namespace Jupiter /** Private members */ private: T **data; - unsigned int dataSize; - unsigned int expandArray(); + size_t dataSize; + size_t expandArray(); }; } // Implementation -const unsigned int INIT_SIZE = 8; +const size_t INIT_SIZE = 8; -template unsigned int Jupiter::ArrayList::expandArray() +template size_t Jupiter::ArrayList::expandArray() { T **tmp = new T *[Jupiter::ArrayList::dataSize * 2]; - for (unsigned int i = 0; i < Jupiter::ArrayList::dataSize; i++) tmp[i] = data[i]; + for (size_t i = 0; i < Jupiter::ArrayList::dataSize; i++) tmp[i] = data[i]; delete[] Jupiter::ArrayList::data; Jupiter::ArrayList::data = tmp; Jupiter::ArrayList::dataSize *= 2; @@ -139,7 +139,7 @@ template Jupiter::ArrayList::ArrayList(const Jupiter::ArrayList::dataSize = source.dataSize; Jupiter::ArrayList::data = new T*[Jupiter::ArrayList::dataSize]; Jupiter::List::length = source.length; - for (unsigned int i = 0; i < Jupiter::List::length; i++) Jupiter::ArrayList::data[i] = source.data[i]; + for (size_t i = 0; i < Jupiter::List::length; i++) Jupiter::ArrayList::data[i] = source.data[i]; } template Jupiter::ArrayList::~ArrayList() @@ -147,24 +147,24 @@ template Jupiter::ArrayList::~ArrayList() delete[] Jupiter::ArrayList::data; } -template T *Jupiter::ArrayList::get(unsigned int index) const +template T *Jupiter::ArrayList::get(size_t index) const { return Jupiter::ArrayList::data[index]; } -template T *Jupiter::ArrayList::remove(unsigned int index) +template T *Jupiter::ArrayList::remove(size_t index) { T *r = Jupiter::ArrayList::data[index]; Jupiter::ArrayList::data[index] = nullptr; - for (unsigned int i = index + 1; i < Jupiter::List::length; i++) Jupiter::ArrayList::data[i - 1] = Jupiter::ArrayList::data[i]; + for (size_t i = index + 1; i < Jupiter::List::length; i++) Jupiter::ArrayList::data[i - 1] = Jupiter::ArrayList::data[i]; Jupiter::List::length--; return r; } -template void Jupiter::ArrayList::add(T *ndata, unsigned int index) +template void Jupiter::ArrayList::add(T *ndata, size_t index) { if (Jupiter::List::length == Jupiter::ArrayList::dataSize) Jupiter::ArrayList::expandArray(); - for (unsigned int i = Jupiter::List::length; i > index; i--) Jupiter::ArrayList::data[i] = Jupiter::ArrayList::data[i - 1]; + for (size_t i = Jupiter::List::length; i > index; i--) Jupiter::ArrayList::data[i] = Jupiter::ArrayList::data[i - 1]; Jupiter::ArrayList::data[index] = ndata; Jupiter::List::length++; } @@ -181,7 +181,7 @@ template void Jupiter::ArrayList::empty() template void Jupiter::ArrayList::emptyAndDelete() { - for (unsigned int i = 0; i < Jupiter::List::length; i++) delete Jupiter::ArrayList::data[i]; + for (size_t i = 0; i < Jupiter::List::length; i++) delete Jupiter::ArrayList::data[i]; Jupiter::List::length = 0; } diff --git a/Jupiter/DLList.h b/Jupiter/DLList.h index cba6744..d35d84d 100644 --- a/Jupiter/DLList.h +++ b/Jupiter/DLList.h @@ -51,7 +51,7 @@ namespace Jupiter * @param n Index of the node to return. * @return n'th Node in the list. */ - Node *getNode(unsigned int n) const; + Node *getNode(size_t n) const; /** * @brief Gets the data at a specified index. @@ -59,7 +59,7 @@ namespace Jupiter * @param index Index of the data to get. * @return Data stored at the specified index. */ - T *get(unsigned int index) const; + T *get(size_t index) const; /** * @brief Removes the n'th Node in the list, and returns its contents. @@ -67,7 +67,7 @@ namespace Jupiter * @param n Index of the node to remove. * @return Contents of the node removed. */ - T *remove(unsigned int n); + T *remove(size_t n); /** * @brief Removes a node from the list. @@ -83,7 +83,7 @@ namespace Jupiter * @param data Data to add to the list. * @param index Position in the list to add the data to. */ - void add(T *data, unsigned int index); + void add(T *data, size_t index); /** * @brief Adds data to the end of the list. @@ -176,26 +176,26 @@ template Jupiter::DLList::~DLList() } } -template typename Jupiter::DLList::Node *Jupiter::DLList::getNode(unsigned int index) const +template typename Jupiter::DLList::Node *Jupiter::DLList::getNode(size_t index) const { Jupiter::DLList::Node *r; if (index * 2 < Jupiter::List::length) { r = Jupiter::DLList::head; - for (unsigned int i = 0; i < index; i++) r = r->next; + for (size_t i = 0; i < index; i++) r = r->next; return r; } r = Jupiter::DLList::end; - for (unsigned int i = Jupiter::List::length - 1; i > index; i--) r = r->previous; + for (size_t i = Jupiter::List::length - 1; i > index; i--) r = r->previous; return r; } -template T *Jupiter::DLList::get(unsigned int index) const +template T *Jupiter::DLList::get(size_t index) const { return Jupiter::DLList::getNode(index)->data; } -template T *Jupiter::DLList::remove(unsigned int index) +template T *Jupiter::DLList::remove(size_t index) { return Jupiter::DLList::remove(Jupiter::DLList::getNode(index)); } @@ -224,7 +224,7 @@ template T *Jupiter::DLList::remove(Node *data) return r; } -template void Jupiter::DLList::add(T *data, unsigned int index) +template void Jupiter::DLList::add(T *data, size_t index) { Jupiter::DLList::Node *node = new Jupiter::DLList::Node(); node->data = data; diff --git a/Jupiter/List.h b/Jupiter/List.h index a833208..972c737 100644 --- a/Jupiter/List.h +++ b/Jupiter/List.h @@ -37,7 +37,7 @@ namespace Jupiter * @param index Index of the data to get. * @return Data stored at the specified index. */ - virtual T *get(unsigned int index) const = 0; + virtual T *get(size_t index) const = 0; /** * @brief Removes the n'th Node in the list, and returns its contents. @@ -45,7 +45,7 @@ namespace Jupiter * @param n Index of the node to remove. * @return Contents of the node removed. */ - virtual T *remove(unsigned int n) = 0; + virtual T *remove(size_t n) = 0; /** * @brief Adds data to the list at a specified index. @@ -53,7 +53,7 @@ namespace Jupiter * @param data Data to add to the list. * @param index Position in the list to add the data to. */ - virtual void add(T *data, unsigned int index) = 0; + virtual void add(T *data, size_t index) = 0; /** * @brief Adds data to the list in an efficient manner. @@ -67,10 +67,10 @@ namespace Jupiter * * @return Number of nodes in the list. */ - unsigned int size() const { return Jupiter::List::length; }; + size_t size() const { return Jupiter::List::length; }; protected: - unsigned int length = 0; /** Length (size) of the list. Returned by size(). Must be managed by extending classes. */ + size_t length = 0; /** Length (size) of the list. Returned by size(). Must be managed by extending classes. */ }; } diff --git a/Jupiter/Queue.cpp b/Jupiter/Queue.cpp index eb0138a..a7f314a 100644 --- a/Jupiter/Queue.cpp +++ b/Jupiter/Queue.cpp @@ -53,7 +53,7 @@ void *Jupiter::Queue::dequeue() return nullptr; } -unsigned int Jupiter::Queue::size() const +size_t Jupiter::Queue::size() const { return Jupiter::Queue::length; } \ No newline at end of file diff --git a/Jupiter/Queue.h b/Jupiter/Queue.h index 7d2da6f..7a9f29e 100644 --- a/Jupiter/Queue.h +++ b/Jupiter/Queue.h @@ -53,7 +53,7 @@ namespace Jupiter * * @return Number of elements in the Queue. */ - unsigned int size() const; + size_t size() const; /** * @brief Default constructor for the Queue class. @@ -71,7 +71,7 @@ namespace Jupiter struct Data; Data *head; Data *end; - unsigned int length; + size_t length; }; } diff --git a/Jupiter/SLList.h b/Jupiter/SLList.h index da6f173..95190db 100644 --- a/Jupiter/SLList.h +++ b/Jupiter/SLList.h @@ -50,7 +50,7 @@ namespace Jupiter * @param n Index of the node to return. * @return n'th Node in the list. */ - Node *getNode(unsigned int n) const; + Node *getNode(size_t n) const; /** * @brief Gets the data at a specified index. @@ -58,7 +58,7 @@ namespace Jupiter * @param index Index of the data to get. * @return Data stored at the specified index. */ - T *get(unsigned int index) const; + T *get(size_t index) const; /** * @brief Removes the n'th Node in the list, and returns its contents. @@ -66,7 +66,7 @@ namespace Jupiter * @param n Index of the node to remove. * @return Contents of the node removed. */ - T *remove(unsigned int n); + T *remove(size_t n); /** * @brief Removes the next node in the list. @@ -82,7 +82,7 @@ namespace Jupiter * @param data Data to add to the list. * @param index Position in the list to add the data to. */ - void add(T *data, unsigned int index); + void add(T *data, size_t index); /** * @brief Adds data to the front of the list. @@ -154,27 +154,27 @@ template Jupiter::SLList::~SLList() } while (c != nullptr); } -template typename Jupiter::SLList::Node *Jupiter::SLList::getNode(unsigned int index) const +template typename Jupiter::SLList::Node *Jupiter::SLList::getNode(size_t index) const { Jupiter::SLList::Node *t = head->next; - for (unsigned int i = 0; i != index; i++) t = t->next; + for (size_t i = 0; i != index; i++) t = t->next; return t; } -template T *Jupiter::SLList::get(unsigned int index) +template T *Jupiter::SLList::get(size_t index) { return Jupiter::SLList::getNode(index)->data; } -template const T *Jupiter::SLList::get(unsigned int index) const +template const T *Jupiter::SLList::get(size_t index) const { return Jupiter::SLList::getNode(index)->data; } -template T *Jupiter::SLList::remove(unsigned int index) +template T *Jupiter::SLList::remove(size_t index) { Jupiter::SLList::Node *t = head; - for (unsigned int i = 0; i != index; i++) t = t->next; + for (size_t i = 0; i != index; i++) t = t->next; Jupiter::SLList::Node *t2 = t->next; T *r = t2->data; delete t2; @@ -193,12 +193,12 @@ template T *Jupiter::SLList::removeNext(Jupiter::SLList::Node return r; } -template void Jupiter::SLList::add(T *data, unsigned int index) +template void Jupiter::SLList::add(T *data, size_t index) { Jupiter::SLList::Node *n = new Jupiter::SLList::Node(); n->data = data; Jupiter::SLList::Node *t = Jupiter::SLList::head; - for (unsigned int i = 0; i < index; i++) t = t->next; + for (size_t i = 0; i < index; i++) t = t->next; n->next = t->next; t->next = n; Jupiter::List::length++;