forked from jabbany/CommentCoreLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommentListOptimizer.js
More file actions
37 lines (37 loc) · 873 Bytes
/
CommentListOptimizer.js
File metadata and controls
37 lines (37 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/** Experimental New Optimizer **/
function CommentList(){
this.timeline = [];
this.threshold = 1000;//Every 1 second
this.count = 0;
this.isOptimized = false;
}
CommentList.prototype.load = function (tl){
tl.sort(function(a,b){
if(a.stime > b.stime) return 2;
else if(a.stime < b.stime) return -2;
else{
if(a.date > b.date) return 1;
else if(a.date < b.date) return -1;
else return 0;
}
});
this.timeline = tl;
this.count = tl.length;
this.isOptimized = false;
};
CommentList.prototype.optimize = function(){
if(this.isOptimized)
return true;
var pos = 0;
var time = 0;
var expr = {};
for(;pos<this.count;pos++){
if(this.timeline[pos].stime - this.time < this.threshold){
//Add to optimize stack if it does not exist in the stack
if(this.found(this.timeline[pos]))
break;
else
this.pushfind(this.timeline[pos])
}
}
};