-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.js
97 lines (73 loc) · 1.83 KB
/
debug.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var noop = function(){}
var console_log = console.log.bind(console)
var max = Math.max
var liberate = require('liberate')
var map = liberate(Array.prototype.map)
var filter = liberate(Array.prototype.filter)
var max = Math.max
var microtime = require('microtime')
var start = μ()
module.exports = {
dump: dumpta
, dump_nice: dumpv
, prems: prems
, ms: MS
, get_max: get_max_size
, log: console_log
, endsize: console_log.bind(null, 'end size')
, save: save
, diff: diff
}
var saves = {}
function save(name, ta){
saves[name] = new ta.constructor(ta.length)
saves[name].set(ta)
}
function compare(ta){
return function(a, i){ return a === ta[i] }
}
function diff(w, ta){
return filter(ta, compare(saves[w]))
}
var stash = []
function prems(ads, data){
var pre = get_max_size(ads, data) + '\n' + dumpta(ads)+ '\n' +dumpv(data, ads) + '\n' + dumpta(data)
stash.push(pre)
return stash.length - 1
}
function id(x){ return x }
function pair(data, x){ return [x, data[x]] }
function size(data, data_index){ return data[data_index] }
function get_max_size(ads,data){
return max.apply(map(ads, size.bind(null, data)))
}
function MS(ads, data, pre, name){
var ms = get_max_size(ads, data)
if ( ms > 30 ) {
console_log(name)
console_log(pre)
console_log(ms)
console_log(dumpta(ads))
console_log(dumpta(data))
throw new Error('FINISH It!!!!')
}
}
function dumpta(ta){
return map(ta, id).filter(below(200)).join(',') + ' :: ' + (μ() - start)
}
function dumpv(data, ta){
return map(ta, pair.bind(null, data)).join(' | ')
}
function findlast(ta){
var last = 0
for ( var i = 0; i < ta.length; i++ ) {
if ( ta[i] > 0 ) last = i
}
return last
}
//function id(x){ return x }
function below(limit){ return function(_,i){ return i < limit } }
function between(from, to){ return function(_,i){ return i >= from && i <= to } }
function μ(){
return microtime.now()
}