markparticle / WebServer

C++ Linux WebServer服务器
Apache License 2.0
3.49k stars 730 forks source link

时间堆del_函数 #85

Open kkndme-wx opened 1 year ago

kkndme-wx commented 1 year ago

void HeapTimer::del_(sizet index) { / 删除指定位置的结点 / assert(!heap.empty() && index >= 0 && index < heap_.size()); / 将要删除的结点换到队尾,然后调整堆 / size_t i = index; sizet n = heap.size() - 1; assert(i <= n); if(i < n) { SwapNode(i, n); if(!siftdown(i, n)) { siftup(i); } } 这里的siftdown(i,n)是否应该是siftdown(i,n-1)?

lizyzzz commented 1 year ago

这里没有错,n已经是size() - 1了

peng-yq commented 4 months ago

void HeapTimer::del_(sizet index) { /* 删除指定位置的结点 / assert(!heap.empty() && index >= 0 && index < heap.size()); /_ 将要删除的结点换到队尾,然后调整堆 */ size_t i = index; sizet n = heap.size() - 1; assert(i <= n); if(i < n) { SwapNode(i, n); if(!siftdown(i, n)) { siftup(i); } } 这里的siftdown(i,n)是否应该是siftdown(i,n-1)?

没有问题,因为n=size()-1,并且siftdown中while循环的条件为j<n