Advertisement
Guest User

IndexedSet.cpp

a guest
Nov 10th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include "IndexedSet.h"
  2.  
  3. IndexedSet::IndexedSet() {}
  4.  
  5. IndexedSet::IndexedSet(const IndexedSet& other)
  6. {
  7.     this->valuesSet = other.valuesSet;
  8.     this->valuesArray = new Value[other.valuesSet.size()];
  9.     int i = 0;
  10.     for (Value val : other.valuesSet)
  11.     {
  12.         valuesArray[i] = val;
  13.         i++;
  14.     }
  15. }
  16.  
  17. void IndexedSet::add(const Value& v)
  18. {
  19.     this->valuesSet.insert(v);
  20.     delete[] this->valuesArray;
  21.     this->valuesArray = nullptr;
  22. }
  23.  
  24. size_t IndexedSet::size() const
  25. {
  26.     return this->valuesSet.size();
  27. }
  28.  
  29. const Value& IndexedSet::operator[](size_t index)
  30. {
  31.     if(this->valuesArray == nullptr)
  32.     {
  33.         this->valuesArray = new Value[this->valuesSet.size()];
  34.         int i = 0;
  35.         for (Value v : valuesSet)
  36.         {
  37.             this->valuesArray[i] = v;
  38.             i++;
  39.         }
  40.     }
  41.  
  42.     return this->valuesArray[index];
  43. }
  44.  
  45. IndexedSet& IndexedSet::operator=(const IndexedSet& other)
  46. {
  47.     if(this != &other)
  48.     {
  49.         this->valuesSet = other.valuesSet;
  50.         this->valuesArray = new Value[other.valuesSet.size()];
  51.  
  52.         int i = 0;
  53.         for (Value v : valuesSet)
  54.         {
  55.             this->valuesArray[i] = v;
  56.             i++;
  57.         }
  58.     }
  59.  
  60.     return *this;
  61. }
  62.  
  63. void IndexedSet::buildIndex()
  64. {
  65.    
  66. }
  67.  
  68. void IndexedSet::clearIndex()
  69. {
  70.    
  71. }
  72.  
  73.  
  74. IndexedSet::~IndexedSet()
  75. {
  76.     delete[] this->valuesArray;
  77.     this->valuesArray = nullptr;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement