tera/Source/dapp/rest_tables.js
progr76@gmail.com 5af6a818a0 0.922
2019-03-16 19:08:05 +03:00

52 lines
1.4 KiB
JavaScript

/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://web.telegram.org/#/im?p=@terafoundation
*/
function DoRest(r,e,t)
{
var o = r.Arr[0], u = Math.floor(t / REST_BLOCK_SCALE);
if(u !== Math.floor((o.BlockNum - 1) / REST_BLOCK_SCALE))
{
for(var l = GetRestArr(u), a = [], f = l.length - 2; 0 <= f; f--)
a.push(l[f] * REST_BLOCK_SCALE);
RestPush(r, a, t, 1);
}
r.Arr[0] = {BlockNum:t, Value:e.Value};
};
function RestPush(r,e,t,o)
{
var u = r.Arr[o - 1], l = r.Arr[o];
if(1 < o)
{
var a = e[o - 2];
if(u.BlockNum > a)
return ;
}
if(l.BlockNum && l.BlockNum >= t || u.BlockNum >= t)
return l.BlockNum = 0, void (l.Value = {});
l.BlockNum && o < r.Arr.length - 1 && RestPush(r, e, t, o + 1), r.Arr[o] = u;
};
function GetRestArr(r)
{
for(var e = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], t = e.length, o = 0; o <= r; o++)
for(var u = 0, l = o, a = t - 1; 0 <= a; a--)
{
var f = e[a];
if(e[a] = l, l = f, 0 == ((u = u << 4 | 15) & o))
break;
if(0 != (u & l))
break;
}
return e;
};
global.DoRest = DoRest, global.GetRestArr = GetRestArr;