setTimeout和clearTimeout的算法/渐近性能

时间:2014-01-06 05:21:30

标签: javascript algorithm big-o settimeout

在常见浏览器(Chrome,FF,IE)中实现setTimeoutclearTimeout的算法是什么?

首先想到的算法是可以在最小堆上维护超时,按运行时间排序。首先从堆中删除超时。

     1
    / \
   2   7
  / \
 5  5

(where numbers are the UTC time, or something)

这将使asympotic performance

setTimeout   - O(log n)
clearTimeout - O(n)

setTimeoutclearTimeout的效果之间是否有这样的差异,还是使用了不同的算法? (例如,使用堆,但使用“禁用”标记标记超时,而不是立即从堆中查找和删除它们。)

0 个答案:

没有答案