mvaganov

don't retype all this...

May 14th, 2017
83
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma once
  2.  
  3. #include "managedarray.h"
  4.  
  5. template <typename T>
  6. class FastList : public ManagedArray<T> {
  7. private:
  8.     int count; // how many elements are actually used
  9. public:
  10.     inline FastList() : ManagedArray<T>(),count(0){}
  11.     inline ~FastList(){}
  12.  
  13.     inline int size() { return count; }
  14.     // re-allocates data to be 1 larger, and adds the given value to the end
  15.     void addToEnd(const T value) {
  16.         if (count >= ManagedArray<T>::size()) {
  17.             if(size() == 0) {
  18.                 ManagedArray<T>::setSize(2);
  19.             } else {
  20.                 ManagedArray<T>::setSize(size() + 10); // TODO talk about why *2 is bad
  21.             }
  22.         }
  23.         ManagedArray<T>::set(count++, value); // add 1 to count AFTER the function call is done.
  24.     }
  25.     // inserts a value into the given index by reallocating to a bigger array and
  26.     // copying every value value into the new array with the new value in its index
  27.     void insert(const int index, const T value) {
  28.         addToEnd(value);
  29.         for(int i = count-1; i > index; --i) {
  30.             ManagedArray<T>::set(i, ManagedArray<T>::get(i-1));
  31.         }
  32.         ManagedArray<T>::set(index, value);
  33.     }
  34.     // removes the value at the given index by reallocating to a smaller array
  35.     // and copying every value *except* the removed value into the new array
  36.     void removeAt(const int index) {
  37.         for(int i = index; i < count; ++i) {
  38.             ManagedArray<T>::set(i, ManagedArray<T>::get(i+1));
  39.         }
  40.         count--;   
  41.     }
  42. };
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×