Browse Source

Changed types from unsigned int to size_t.

release/0.19
JustinAJ 10 years ago
parent
commit
5e3e8e1587
  1. 30
      Jupiter/ArrayList.h
  2. 20
      Jupiter/DLList.h
  3. 10
      Jupiter/List.h
  4. 2
      Jupiter/Queue.cpp
  5. 4
      Jupiter/Queue.h
  6. 24
      Jupiter/SLList.h

30
Jupiter/ArrayList.h

@ -41,7 +41,7 @@ namespace Jupiter
* @param index Index of the data to get. * @param index Index of the data to get.
* @return Data stored at the specified index. * @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. * @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. * @param n Index of the node to remove.
* @return Data removed. * @return Data removed.
*/ */
T *remove(unsigned int index); T *remove(size_t index);
/** /**
* @brief Adds data to the list at a specified 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 data Data to add to the list.
* @param index Position in the list to add the data to. * @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. * @brief Adds data to the end of the list.
@ -103,20 +103,20 @@ namespace Jupiter
/** Private members */ /** Private members */
private: private:
T **data; T **data;
unsigned int dataSize; size_t dataSize;
unsigned int expandArray(); size_t expandArray();
}; };
} }
// Implementation // Implementation
const unsigned int INIT_SIZE = 8; const size_t INIT_SIZE = 8;
template<typename T> unsigned int Jupiter::ArrayList<T>::expandArray() template<typename T> size_t Jupiter::ArrayList<T>::expandArray()
{ {
T **tmp = new T *[Jupiter::ArrayList<T>::dataSize * 2]; T **tmp = new T *[Jupiter::ArrayList<T>::dataSize * 2];
for (unsigned int i = 0; i < Jupiter::ArrayList<T>::dataSize; i++) tmp[i] = data[i]; for (size_t i = 0; i < Jupiter::ArrayList<T>::dataSize; i++) tmp[i] = data[i];
delete[] Jupiter::ArrayList<T>::data; delete[] Jupiter::ArrayList<T>::data;
Jupiter::ArrayList<T>::data = tmp; Jupiter::ArrayList<T>::data = tmp;
Jupiter::ArrayList<T>::dataSize *= 2; Jupiter::ArrayList<T>::dataSize *= 2;
@ -139,7 +139,7 @@ template<typename T> Jupiter::ArrayList<T>::ArrayList(const Jupiter::ArrayList<T
Jupiter::ArrayList<T>::dataSize = source.dataSize; Jupiter::ArrayList<T>::dataSize = source.dataSize;
Jupiter::ArrayList<T>::data = new T*[Jupiter::ArrayList<T>::dataSize]; Jupiter::ArrayList<T>::data = new T*[Jupiter::ArrayList<T>::dataSize];
Jupiter::List<T>::length = source.length; Jupiter::List<T>::length = source.length;
for (unsigned int i = 0; i < Jupiter::List<T>::length; i++) Jupiter::ArrayList<T>::data[i] = source.data[i]; for (size_t i = 0; i < Jupiter::List<T>::length; i++) Jupiter::ArrayList<T>::data[i] = source.data[i];
} }
template<typename T> Jupiter::ArrayList<T>::~ArrayList() template<typename T> Jupiter::ArrayList<T>::~ArrayList()
@ -147,24 +147,24 @@ template<typename T> Jupiter::ArrayList<T>::~ArrayList()
delete[] Jupiter::ArrayList<T>::data; delete[] Jupiter::ArrayList<T>::data;
} }
template<typename T> T *Jupiter::ArrayList<T>::get(unsigned int index) const template<typename T> T *Jupiter::ArrayList<T>::get(size_t index) const
{ {
return Jupiter::ArrayList<T>::data[index]; return Jupiter::ArrayList<T>::data[index];
} }
template<typename T> T *Jupiter::ArrayList<T>::remove(unsigned int index) template<typename T> T *Jupiter::ArrayList<T>::remove(size_t index)
{ {
T *r = Jupiter::ArrayList<T>::data[index]; T *r = Jupiter::ArrayList<T>::data[index];
Jupiter::ArrayList<T>::data[index] = nullptr; Jupiter::ArrayList<T>::data[index] = nullptr;
for (unsigned int i = index + 1; i < Jupiter::List<T>::length; i++) Jupiter::ArrayList<T>::data[i - 1] = Jupiter::ArrayList<T>::data[i]; for (size_t i = index + 1; i < Jupiter::List<T>::length; i++) Jupiter::ArrayList<T>::data[i - 1] = Jupiter::ArrayList<T>::data[i];
Jupiter::List<T>::length--; Jupiter::List<T>::length--;
return r; return r;
} }
template<typename T> void Jupiter::ArrayList<T>::add(T *ndata, unsigned int index) template<typename T> void Jupiter::ArrayList<T>::add(T *ndata, size_t index)
{ {
if (Jupiter::List<T>::length == Jupiter::ArrayList<T>::dataSize) Jupiter::ArrayList<T>::expandArray(); if (Jupiter::List<T>::length == Jupiter::ArrayList<T>::dataSize) Jupiter::ArrayList<T>::expandArray();
for (unsigned int i = Jupiter::List<T>::length; i > index; i--) Jupiter::ArrayList<T>::data[i] = Jupiter::ArrayList<T>::data[i - 1]; for (size_t i = Jupiter::List<T>::length; i > index; i--) Jupiter::ArrayList<T>::data[i] = Jupiter::ArrayList<T>::data[i - 1];
Jupiter::ArrayList<T>::data[index] = ndata; Jupiter::ArrayList<T>::data[index] = ndata;
Jupiter::List<T>::length++; Jupiter::List<T>::length++;
} }
@ -181,7 +181,7 @@ template<typename T> void Jupiter::ArrayList<T>::empty()
template<typename T> void Jupiter::ArrayList<T>::emptyAndDelete() template<typename T> void Jupiter::ArrayList<T>::emptyAndDelete()
{ {
for (unsigned int i = 0; i < Jupiter::List<T>::length; i++) delete Jupiter::ArrayList<T>::data[i]; for (size_t i = 0; i < Jupiter::List<T>::length; i++) delete Jupiter::ArrayList<T>::data[i];
Jupiter::List<T>::length = 0; Jupiter::List<T>::length = 0;
} }

20
Jupiter/DLList.h

@ -51,7 +51,7 @@ namespace Jupiter
* @param n Index of the node to return. * @param n Index of the node to return.
* @return n'th Node in the list. * @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. * @brief Gets the data at a specified index.
@ -59,7 +59,7 @@ namespace Jupiter
* @param index Index of the data to get. * @param index Index of the data to get.
* @return Data stored at the specified index. * @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. * @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. * @param n Index of the node to remove.
* @return Contents of the node removed. * @return Contents of the node removed.
*/ */
T *remove(unsigned int n); T *remove(size_t n);
/** /**
* @brief Removes a node from the list. * @brief Removes a node from the list.
@ -83,7 +83,7 @@ namespace Jupiter
* @param data Data to add to the list. * @param data Data to add to the list.
* @param index Position in the list to add the data to. * @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. * @brief Adds data to the end of the list.
@ -176,26 +176,26 @@ template<typename T> Jupiter::DLList<T>::~DLList()
} }
} }
template<typename T> typename Jupiter::DLList<T>::Node *Jupiter::DLList<T>::getNode(unsigned int index) const template<typename T> typename Jupiter::DLList<T>::Node *Jupiter::DLList<T>::getNode(size_t index) const
{ {
Jupiter::DLList<T>::Node *r; Jupiter::DLList<T>::Node *r;
if (index * 2 < Jupiter::List<T>::length) if (index * 2 < Jupiter::List<T>::length)
{ {
r = Jupiter::DLList<T>::head; r = Jupiter::DLList<T>::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; return r;
} }
r = Jupiter::DLList<T>::end; r = Jupiter::DLList<T>::end;
for (unsigned int i = Jupiter::List<T>::length - 1; i > index; i--) r = r->previous; for (size_t i = Jupiter::List<T>::length - 1; i > index; i--) r = r->previous;
return r; return r;
} }
template<typename T> T *Jupiter::DLList<T>::get(unsigned int index) const template<typename T> T *Jupiter::DLList<T>::get(size_t index) const
{ {
return Jupiter::DLList<T>::getNode(index)->data; return Jupiter::DLList<T>::getNode(index)->data;
} }
template<typename T> T *Jupiter::DLList<T>::remove(unsigned int index) template<typename T> T *Jupiter::DLList<T>::remove(size_t index)
{ {
return Jupiter::DLList<T>::remove(Jupiter::DLList<T>::getNode(index)); return Jupiter::DLList<T>::remove(Jupiter::DLList<T>::getNode(index));
} }
@ -224,7 +224,7 @@ template<typename T> T *Jupiter::DLList<T>::remove(Node *data)
return r; return r;
} }
template<typename T> void Jupiter::DLList<T>::add(T *data, unsigned int index) template<typename T> void Jupiter::DLList<T>::add(T *data, size_t index)
{ {
Jupiter::DLList<T>::Node *node = new Jupiter::DLList<T>::Node(); Jupiter::DLList<T>::Node *node = new Jupiter::DLList<T>::Node();
node->data = data; node->data = data;

10
Jupiter/List.h

@ -37,7 +37,7 @@ namespace Jupiter
* @param index Index of the data to get. * @param index Index of the data to get.
* @return Data stored at the specified index. * @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. * @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. * @param n Index of the node to remove.
* @return Contents of the node removed. * @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. * @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 data Data to add to the list.
* @param index Position in the list to add the data to. * @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. * @brief Adds data to the list in an efficient manner.
@ -67,10 +67,10 @@ namespace Jupiter
* *
* @return Number of nodes in the list. * @return Number of nodes in the list.
*/ */
unsigned int size() const { return Jupiter::List<T>::length; }; size_t size() const { return Jupiter::List<T>::length; };
protected: 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. */
}; };
} }

2
Jupiter/Queue.cpp

@ -53,7 +53,7 @@ void *Jupiter::Queue::dequeue()
return nullptr; return nullptr;
} }
unsigned int Jupiter::Queue::size() const size_t Jupiter::Queue::size() const
{ {
return Jupiter::Queue::length; return Jupiter::Queue::length;
} }

4
Jupiter/Queue.h

@ -53,7 +53,7 @@ namespace Jupiter
* *
* @return Number of elements in the Queue. * @return Number of elements in the Queue.
*/ */
unsigned int size() const; size_t size() const;
/** /**
* @brief Default constructor for the Queue class. * @brief Default constructor for the Queue class.
@ -71,7 +71,7 @@ namespace Jupiter
struct Data; struct Data;
Data *head; Data *head;
Data *end; Data *end;
unsigned int length; size_t length;
}; };
} }

24
Jupiter/SLList.h

@ -50,7 +50,7 @@ namespace Jupiter
* @param n Index of the node to return. * @param n Index of the node to return.
* @return n'th Node in the list. * @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. * @brief Gets the data at a specified index.
@ -58,7 +58,7 @@ namespace Jupiter
* @param index Index of the data to get. * @param index Index of the data to get.
* @return Data stored at the specified index. * @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. * @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. * @param n Index of the node to remove.
* @return Contents of the node removed. * @return Contents of the node removed.
*/ */
T *remove(unsigned int n); T *remove(size_t n);
/** /**
* @brief Removes the next node in the list. * @brief Removes the next node in the list.
@ -82,7 +82,7 @@ namespace Jupiter
* @param data Data to add to the list. * @param data Data to add to the list.
* @param index Position in the list to add the data to. * @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. * @brief Adds data to the front of the list.
@ -154,27 +154,27 @@ template<typename T> Jupiter::SLList<T>::~SLList()
} while (c != nullptr); } while (c != nullptr);
} }
template<typename T> typename Jupiter::SLList<T>::Node *Jupiter::SLList<T>::getNode(unsigned int index) const template<typename T> typename Jupiter::SLList<T>::Node *Jupiter::SLList<T>::getNode(size_t index) const
{ {
Jupiter::SLList<T>::Node *t = head->next; Jupiter::SLList<T>::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; return t;
} }
template<typename T> T *Jupiter::SLList<T>::get(unsigned int index) template<typename T> T *Jupiter::SLList<T>::get(size_t index)
{ {
return Jupiter::SLList<T>::getNode(index)->data; return Jupiter::SLList<T>::getNode(index)->data;
} }
template<typename T> const T *Jupiter::SLList<T>::get(unsigned int index) const template<typename T> const T *Jupiter::SLList<T>::get(size_t index) const
{ {
return Jupiter::SLList<T>::getNode(index)->data; return Jupiter::SLList<T>::getNode(index)->data;
} }
template<typename T> T *Jupiter::SLList<T>::remove(unsigned int index) template<typename T> T *Jupiter::SLList<T>::remove(size_t index)
{ {
Jupiter::SLList<T>::Node *t = head; Jupiter::SLList<T>::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<T>::Node *t2 = t->next; Jupiter::SLList<T>::Node *t2 = t->next;
T *r = t2->data; T *r = t2->data;
delete t2; delete t2;
@ -193,12 +193,12 @@ template<typename T> T *Jupiter::SLList<T>::removeNext(Jupiter::SLList<T>::Node
return r; return r;
} }
template<typename T> void Jupiter::SLList<T>::add(T *data, unsigned int index) template<typename T> void Jupiter::SLList<T>::add(T *data, size_t index)
{ {
Jupiter::SLList<T>::Node *n = new Jupiter::SLList<T>::Node(); Jupiter::SLList<T>::Node *n = new Jupiter::SLList<T>::Node();
n->data = data; n->data = data;
Jupiter::SLList<T>::Node *t = Jupiter::SLList<T>::head; Jupiter::SLList<T>::Node *t = Jupiter::SLList<T>::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; n->next = t->next;
t->next = n; t->next = n;
Jupiter::List<T>::length++; Jupiter::List<T>::length++;

Loading…
Cancel
Save