This commit is contained in:
邹晓航
2015-01-02 13:14:02 +08:00
parent 44c61cb0c0
commit 23d498f68a
3 changed files with 13 additions and 4 deletions

View File

@@ -72,6 +72,7 @@ namespace TinySTL{
if (ptr){ if (ptr){
deallocateAllNodes(ptr->left_); deallocateAllNodes(ptr->left_);
deallocateAllNodes(ptr->right_); deallocateAllNodes(ptr->right_);
nodeAllocator::destroy(ptr);
nodeAllocator::deallocate(ptr); nodeAllocator::deallocate(ptr);
} }
} }

View File

@@ -189,9 +189,12 @@ namespace TinySTL{
deque(const deque& x); deque(const deque& x);
~deque(){ ~deque(){
for (int i = 0; i != mapSize_; ++i) for (int i = 0; i != mapSize_; ++i){
for (auto p = map_[i] + 0; !p && p != map_[i] + getBuckSize(); ++p)
dataAllocator::destroy(p);
if (!map_[i]) if (!map_[i])
dataAllocator::deallocate(map_[i], getBuckSize()); dataAllocator::deallocate(map_[i], getBuckSize());
}
delete[] map_; delete[] map_;
} }
@@ -221,9 +224,12 @@ namespace TinySTL{
void pop_front(); void pop_front();
void swap(deque& x); void swap(deque& x);
void clear(){ void clear(){
for (int i = 0; i != mapSize_; ++i) /*for (int i = 0; i != mapSize_; ++i)
if (!map_[i]) if (!map_[i])
dataAllocator::destroy(map_[i], map_[i] + getBuckSize()); dataAllocator::destroy(map_[i], map_[i] + getBuckSize());*/
for (auto i = 0; i != mapSize_; ++i){
for (auto p = map_[i] + 0; !p && p != map_[i] + getBuckSize(); ++p)
dataAllocator::destroy(p);
mapSize_ = 0; mapSize_ = 0;
beg_.mapIndex_ = end_.mapIndex_ = mapSize_ / 2; beg_.mapIndex_ = end_.mapIndex_ = mapSize_ / 2;
beg_.cur_ = end_.cur_ = map_[mapSize_ / 2]; beg_.cur_ = end_.cur_ = map_[mapSize_ / 2];

View File

@@ -116,6 +116,8 @@ namespace TinySTL{
~list(){ ~list(){
for (; head != tail;){ for (; head != tail;){
auto temp = head++; auto temp = head++;
//bug fix
nodeAllocator::destroy(temp.p);
nodeAllocator::deallocate(temp.p); nodeAllocator::deallocate(temp.p);
} }
nodeAllocator::deallocate(tail.p); nodeAllocator::deallocate(tail.p);
@@ -185,7 +187,7 @@ namespace TinySTL{
nodePtr res = nodeAllocator::allocate(); nodePtr res = nodeAllocator::allocate();
res->container = this; res->container = this;
//res->data = val; -> bug //res->data = val; -> bug
construct(&(res->data), val);//fix nodeAllocator::construct(&(res->data), val);//fix
res->prev = nullptr; res->prev = nullptr;
res->next = nullptr; res->next = nullptr;
return res; return res;