added destructors
This commit is contained in:
@@ -13,6 +13,13 @@ struct Array_List {
|
|||||||
length = initial_capacity;
|
length = initial_capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~Array_List() {
|
||||||
|
if (data) {
|
||||||
|
free(data);
|
||||||
|
data = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type* begin() {
|
type* begin() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-9
@@ -48,10 +48,18 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~Bucket_Allocator() {
|
~Bucket_Allocator() {
|
||||||
for (int i = 0; i < bucket_count; ++i) {
|
for (int i = 0; i < latest_bucket-1; ++i) {
|
||||||
free(buckets[i]);
|
for (int j = 0; j < bucket_size; ++j) {
|
||||||
|
::delete (buckets[i]+j);
|
||||||
}
|
}
|
||||||
::free(buckets);
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < next_index_in_latest_bucket; ++i) {
|
||||||
|
::delete (buckets[latest_bucket]+i);
|
||||||
|
}
|
||||||
|
|
||||||
|
::delete[] buckets;
|
||||||
|
free_list.~Array_List();
|
||||||
}
|
}
|
||||||
|
|
||||||
type* allocate(unsigned int amount = 1) {
|
type* allocate(unsigned int amount = 1) {
|
||||||
@@ -84,13 +92,9 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void free(type* obj) {
|
void free_object(type* obj) {
|
||||||
|
delete obj;
|
||||||
free_list.append(obj);
|
free_list.append(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset() {
|
|
||||||
latest_bucket = 0;
|
|
||||||
next_index_in_latest_bucket = 0;
|
|
||||||
next_bucket_index = 0;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ cl^
|
|||||||
../test.cpp^
|
../test.cpp^
|
||||||
/Fe%exeName% /MP /openmp /W3 /std:c++latest^
|
/Fe%exeName% /MP /openmp /W3 /std:c++latest^
|
||||||
/nologo /EHsc /Z7^
|
/nologo /EHsc /Z7^
|
||||||
/link /incremental /debug:fastlink
|
/link /incremental
|
||||||
|
|
||||||
if %errorlevel% == 0 (
|
if %errorlevel% == 0 (
|
||||||
echo.
|
echo.
|
||||||
|
|||||||
@@ -30,6 +30,13 @@ struct Hash_Map {
|
|||||||
data = (HM_Cell*)calloc(initial_capacity, sizeof(HM_Cell));
|
data = (HM_Cell*)calloc(initial_capacity, sizeof(HM_Cell));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~Hash_Map() {
|
||||||
|
if (data) {
|
||||||
|
free(data);
|
||||||
|
data = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int get_index_of_living_cell_if_it_exists(key_type key, u64 hash_val) {
|
int get_index_of_living_cell_if_it_exists(key_type key, u64 hash_val) {
|
||||||
// int index = hash_val & (current_capacity - 1);
|
// int index = hash_val & (current_capacity - 1);
|
||||||
int index = hash_val % current_capacity;
|
int index = hash_val % current_capacity;
|
||||||
|
|||||||
Reference in New Issue
Block a user