Skip to content

Commit

Permalink
Stores the code now. Not complete. Has bugs in hash map.
Browse files Browse the repository at this point in the history
  • Loading branch information
ax-6 committed Mar 31, 2024
1 parent 063420d commit 5a5dab1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions compiler/dyn_array/dyn_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ Compiler::DynArray<ArrayType>::~DynArray() {
}

template <typename ArrayType>
void Compiler::DynArray<ArrayType>::PushBack(ArrayType data) {
void Compiler::DynArray<ArrayType>::Insert(ArrayType data) {
if (capacity_ == 0 && Resize(1) == -1) {
return;
}
if (size_ > capacity_) {
Debugger error(Debugger::Level::ERROR, "Aq::Compiler::DynArray::PushBack",
"PushBack_SizeError", "Size out of capacity occurred.",
Debugger error(Debugger::Level::ERROR, "Aq::Compiler::DynArray::Insert",
"Insert_SizeError", "Size out of capacity occurred.",
nullptr);
return;
}
if (size_ == capacity_) {
if (Resize(capacity_ * 2) != 0) {
Debugger Error(Debugger::Level::ERROR, "Aq::Compiler::DynArray::PushBack",
"PushBack_ResizeError", "Resize out of memory occurred.",
Debugger Error(Debugger::Level::ERROR, "Aq::Compiler::DynArray::Insert",
"Insert_ResizeError", "Resize out of memory occurred.",
nullptr);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/dyn_array/dyn_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Compiler::DynArray {
}

// Adds an element to the end of the container. No return value.
void PushBack(ArrayType data);
void Insert(ArrayType data);

// Increase the container capacity.
// If |new_capacity| is 0, it is increased to 2 times |capacity_|. If
Expand Down
6 changes: 3 additions & 3 deletions compiler/hash_map/hash_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ unsigned int Compiler::HashMap<ValueType>::Hash(std::string key) const {

template <typename ValueType>
int Compiler::HashMap<ValueType>::Resize() {
PairList* temp = pair_list_;
DynArray<LinkedList<Pair<std::string,std::string>>>* temp = pair_list_;
std::size_t new_capacity = capacity_ * 1.5;
pair_list_ = new PairList[new_capacity];
pair_list_ = new DynArray<LinkedList<Pair<std::string,std::string>>>[new_capacity];

// Memory allocation failed.
if (!pair_list_) {
Expand All @@ -77,7 +77,7 @@ int Compiler::HashMap<ValueType>::Resize() {

// Copy data.
for (int i = 0; i < capacity_; i++) {
temp[i].CopyDataToNewList(pair_list_, new_capacity);
// TODO: copy data from temp to pair_list_ (Use Iterator).
}

// Release the memory of the original linked list.
Expand Down

0 comments on commit 5a5dab1

Please sign in to comment.