Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Object-oriented Programming
diff options
context:
space:
mode:
Commit9402e84eca44ce75350cd1e495dc0c7c8e2f2159 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-04-15 09:47:18 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-04-15 09:47:18 +0300
Files289f0c5dfa6e16509dfb0d792d09807841ef2846 /Year 1/Object-oriented Programming
uni-projects-9402e84eca44ce75350cd1e495dc0c7c8e2f2159.tar
uni-projects-9402e84eca44ce75350cd1e495dc0c7c8e2f2159.tar.gz
uni-projects-9402e84eca44ce75350cd1e495dc0c7c8e2f2159.zip
Parent1e4762258f3e2d7db1045f3034e870f84cea7977 (diff)
Renamed some WordCollection properties
diff --git a/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/WordCollection.cpp b/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/WordCollection.cpp
index ff0b48b..b0cd465 100644
--- a/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/WordCollection.cpp
+++ b/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/WordCollection.cpp
@@ -6,19 +6,19 @@
void WordCollection::free() {
delete[] words;
- delete[] sortMap;
+ delete[] sortedPos;
}
void WordCollection::copyFrom(const WordCollection& other) {
- sortMapCount = other.sortMapCount;
- wordsCount = other.wordsCount;
+ count = other.count;
+ storedWordsCount = other.storedWordsCount;
length = other.length;
words = new DynStr[length];
- sortMap = new int[length];
+ sortedPos = new int[length];
for (int i = 0; i < length; i++) { // Must be < length, since we can have valid items outside the count range in words
words[i] = other.words[i];
- sortMap[i] = other.sortMap[i];
+ sortedPos[i] = other.sortedPos[i];
}
}
@@ -33,29 +33,29 @@ void WordCollection::resize() {
for (int i = 0; i < oldLength; i++) {
newWords[i] = words[i];
- newSortMap[i] = sortMap[i];
+ newSortMap[i] = sortedPos[i];
}
delete[] words;
- delete[] sortMap;
+ delete[] sortedPos;
words = newWords;
- sortMap = newSortMap;
+ sortedPos = newSortMap;
}
void WordCollection::insertSortMapIndex(int position, int value) {
if (position == -1)
- position = sortMapCount;
+ position = count;
- for (int i = sortMapCount; i > position; i--)
- sortMap[i] = sortMap[i - 1];
- sortMap[position] = value;
+ for (int i = count; i > position; i--)
+ sortedPos[i] = sortedPos[i - 1];
+ sortedPos[position] = value;
}
void WordCollection::removeSortMapIndex(int position) {
- for (int i = position; i <= sortMapCount - 2; i++)
- sortMap[i] = sortMap[i + 1];
- sortMap[sortMapCount - 1] = 0;
+ for (int i = position; i <= count - 2; i++)
+ sortedPos[i] = sortedPos[i + 1];
+ sortedPos[count - 1] = 0;
}
int WordCollection::findSortMapIndexWhen(int condition, const char* str) {
@@ -63,8 +63,8 @@ int WordCollection::findSortMapIndexWhen(int condition, const char* str) {
else if (condition > 1) condition = 1;
// TODO: replace with binary search
- for (int i = 0; i < sortMapCount; i++) {
- if (words[sortMap[i]].compare(str) == condition)
+ for (int i = 0; i < count; i++) {
+ if (words[sortedPos[i]].compare(str) == condition)
return i;
}
return -1;
@@ -74,8 +74,8 @@ int WordCollection::findSortMapIndexWhen(int condition, const char* str) {
WordCollection::WordCollection() {
words = nullptr;
- sortMap = nullptr;
- sortMapCount = wordsCount = length = 0;
+ sortedPos = nullptr;
+ count = storedWordsCount = length = 0;
}
WordCollection::WordCollection(const WordCollection& other) {
@@ -95,16 +95,16 @@ WordCollection::~WordCollection() {
}
WordCollection& WordCollection::operator+=(const WordCollection& other) {
- for (int i = 0; i < other.sortMapCount; i++) {
- (*this) *= other.words[other.sortMap[i]].get_str();
+ for (int i = 0; i < other.count; i++) {
+ (*this) *= other.words[other.sortedPos[i]].get_str();
}
return *this;
}
WordCollection& WordCollection::operator-=(const WordCollection& other) {
if (this != &other) {
- for (int i = 0; i < other.sortMapCount; i++) {
- (*this) /= other.words[other.sortMap[i]].get_str();
+ for (int i = 0; i < other.count; i++) {
+ (*this) /= other.words[other.sortedPos[i]].get_str();
}
}
else {
@@ -115,12 +115,12 @@ WordCollection& WordCollection::operator-=(const WordCollection& other) {
WordCollection& WordCollection::operator*=(const char* str) {
if (!(*this)[str]) {
- if (sortMapCount == length || wordsCount == length) resize();
+ if (count == length || storedWordsCount == length) resize();
- words[wordsCount] = DynStr(str);
- insertSortMapIndex(findSortMapIndexWhen(1, str), wordsCount);
- sortMapCount++;
- wordsCount++;
+ words[storedWordsCount] = DynStr(str);
+ insertSortMapIndex(findSortMapIndexWhen(1, str), storedWordsCount);
+ count++;
+ storedWordsCount++;
}
return *this;
}
@@ -128,19 +128,19 @@ WordCollection& WordCollection::operator*=(const char* str) {
WordCollection& WordCollection::operator/=(const char* str) {
int ind = findSortMapIndexWhen(0, str);
if (ind > -1) {
- words[sortMap[ind]] = DynStr();
+ words[sortedPos[ind]] = DynStr();
removeSortMapIndex(ind);
- sortMapCount--;
+ count--;
}
return *this;
}
std::ostream& operator<<(std::ostream& ostrm, const WordCollection& collection) {
ostrm << "{";
- if (collection.sortMapCount > 0) {
- for (int i = 0; i <= collection.sortMapCount - 2; i++)
- ostrm << collection.words[collection.sortMap[i]].get_str() << ", ";
- ostrm << collection.words[collection.sortMap[collection.sortMapCount - 1]].get_str();
+ if (collection.count > 0) {
+ for (int i = 0; i <= collection.count - 2; i++)
+ ostrm << collection.words[collection.sortedPos[i]].get_str() << ", ";
+ ostrm << collection.words[collection.sortedPos[collection.count - 1]].get_str();
}
ostrm << "}";
return ostrm;
diff --git a/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/WordCollection.h b/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/WordCollection.h
index fdd3363..18e1b1c 100644
--- a/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/WordCollection.h
+++ b/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/WordCollection.h
@@ -4,9 +4,9 @@
class WordCollection {
DynStr* words;
- int* sortMap;
- int sortMapCount;
- int wordsCount;
+ int* sortedPos;
+ int count;
+ int storedWordsCount;
int length;
void free();