servermgrv2/public/hpilo/js/cache.js
2023-07-17 21:09:49 +09:00

49 lines
2.7 KiB
JavaScript

function ColorCache() {
this.active = 0, this.pixcode = LATCHED, this.size = 17, this.element = new Uint16Array(this.size),
this.display = function() {
for (var i = 0; i < this.active; i++) {
this.element[i];
}
}, this.reset = function() {
this.element.fill(0, 0, this.active), this.active = 0, this.pixcode = LATCHED;
}, this.lru = function(color) {
var active = this.active, code = 0;
return color |= AMASK, -1 == (code = this.element.lastIndexOf(color, active - 1)) && (active < this.size ? (active++,
this.element.copyWithin(1, 0, active), this.element[0] = color, 2 > active ? this.pixcode = LATCHED : 2 == active ? this.pixcode = PIXLRU0 : 3 == active ? this.pixcode = PIXCODE1 : 6 > active ? this.pixcode = PIXCODE2 : 10 > active ? this.pixcode = PIXCODE3 : this.pixcode = PIXCODE4,
this.active = active) : code = active), code > 0 && (this.element.copyWithin(1, 0, active),
this.element[0] = color), !1;
}, this.find = function(code) {
var color;
return code > this.active ? 0 : (color = this.element[code] | AMASK, code > 0 && this.element.copyWithin(1, 0, code),
this.element[0] = color | AMASK, color);
}, this.prune = function(code) {
for (var active = this.active, i = 0, t = 0; active > i; ) this.element[i] & AMASK && (this.element[t++] = -2 & this.element[i]),
i++;
this.element.fill(0, active), this.active = active = t, 2 > active ? this.pixcode = LATCHED : 2 == active ? this.pixcode = PIXLRU0 : 3 == active ? this.pixcode = PIXCODE1 : 6 > active ? this.pixcode = PIXCODE2 : 10 > active ? this.pixcode = PIXCODE3 : this.pixcode = PIXCODE4,
this.display();
};
}
var _COLOR = 0, _USAGE = 1, _COUNTER = 2;
BLOCK_AGE = 1;
const AMASK = 1;
Uint16Array.prototype.fill || (Uint16Array.prototype.fill = function(value) {
for (var t = Object(this), len = t.length, start = arguments[1] >> 0, end = arguments[2] >> 0 || len, k = 0 > start ? len + end : start, n = 0 > end ? len + end : end, i = k; n > i; i++) t[i] = value;
return 0;
}), Uint16Array.prototype.lastIndexOf || (Uint16Array.prototype.lastIndexOf = function(searchElement) {
var t = Object(this), n = t.length;
arguments.length > 1 && (n = Number(arguments[1]));
for (var i = n; i >= 0 && t[i] !== searchElement; i--) ;
return i;
}), Uint16Array.prototype.copyWithin || (Uint16Array.prototype.copyWithin = function(target) {
var t = Object(this), len = t.length, start = 0;
arguments.length > 1 && (start = arguments[1], 0 > start && (start += len));
var end = len;
arguments.length > 2 && (end = arguments[2], 0 > end && (end += len));
var c = end - start;
if (target > start) for (var i = c - 1; i >= 0; i--) t[target + i] = t[start + i]; else for (var i = 0; c > i; i++) t[target + i] = t[start + i];
return t;
});