From 5a5dab1633cbd966e44c5be70bc31009e6dec355 Mon Sep 17 00:00:00 2001 From: ax-6 Date: Sun, 31 Mar 2024 22:27:58 +0800 Subject: [PATCH] Stores the code now. Not complete. Has bugs in hash map. --- compiler/dyn_array/dyn_array.cc | 10 +++++----- compiler/dyn_array/dyn_array.h | 2 +- compiler/hash_map/hash_map.cc | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/dyn_array/dyn_array.cc b/compiler/dyn_array/dyn_array.cc index 0a74c8e..357174e 100644 --- a/compiler/dyn_array/dyn_array.cc +++ b/compiler/dyn_array/dyn_array.cc @@ -29,20 +29,20 @@ Compiler::DynArray::~DynArray() { } template -void Compiler::DynArray::PushBack(ArrayType data) { +void Compiler::DynArray::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; } diff --git a/compiler/dyn_array/dyn_array.h b/compiler/dyn_array/dyn_array.h index 8f0626e..29ab277 100644 --- a/compiler/dyn_array/dyn_array.h +++ b/compiler/dyn_array/dyn_array.h @@ -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 diff --git a/compiler/hash_map/hash_map.cc b/compiler/hash_map/hash_map.cc index cdc1bfd..cc6037e 100644 --- a/compiler/hash_map/hash_map.cc +++ b/compiler/hash_map/hash_map.cc @@ -63,9 +63,9 @@ unsigned int Compiler::HashMap::Hash(std::string key) const { template int Compiler::HashMap::Resize() { - PairList* temp = pair_list_; + DynArray>>* temp = pair_list_; std::size_t new_capacity = capacity_ * 1.5; - pair_list_ = new PairList[new_capacity]; + pair_list_ = new DynArray>>[new_capacity]; // Memory allocation failed. if (!pair_list_) { @@ -77,7 +77,7 @@ int Compiler::HashMap::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.