js-cfb/bits/43_rbtree.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

/* [MS-CFB] 2.6.4 Red-Black Tree */
function build_full_paths(FI/*:CFBFileIndex*/, FP/*:Array<string>*/, Paths/*:Array<string>*/)/*:void*/ {
var i = 0, L = 0, R = 0, C = 0, j = 0, pl = Paths.length;
var dad/*:Array<number>*/ = [], q/*:Array<number>*/ = [];
for(; i < pl; ++i) { dad[i]=q[i]=i; FP[i]=Paths[i]; }
for(; j < q.length; ++j) {
i = q[j];
L = FI[i].L; R = FI[i].R; C = FI[i].C;
if(dad[i] === i) {
if(L !== -1 /*NOSTREAM*/ && dad[L] !== L) dad[i] = dad[L];
if(R !== -1 && dad[R] !== R) dad[i] = dad[R];
}
if(C !== -1 /*NOSTREAM*/) dad[C] = i;
if(L !== -1 && i != dad[i]) { dad[L] = dad[i]; if(q.lastIndexOf(L) < j) q.push(L); }
if(R !== -1 && i != dad[i]) { dad[R] = dad[i]; if(q.lastIndexOf(R) < j) q.push(R); }
}
for(i=1; i < pl; ++i) if(dad[i] === i) {
if(R !== -1 /*NOSTREAM*/ && dad[R] !== R) dad[i] = dad[R];
else if(L !== -1 && dad[L] !== L) dad[i] = dad[L];
}
for(i=1; i < pl; ++i) {
if(FI[i].type === 0 /* unknown */) continue;
2018-12-12 18:50:04 +00:00
j = i;
if(j != dad[j]) do {
j = dad[j];
2018-12-12 18:50:04 +00:00
FP[i] = FP[j] + "/" + FP[i];
} while (j !== 0 && -1 !== dad[j] && j != dad[j]);
2018-12-12 18:50:04 +00:00
dad[i] = -1;
}
FP[0] += "/";
for(i=1; i < pl; ++i) {
if(FI[i].type !== 2 /* stream */) FP[i] += "/";
}
}