private void Compact(CharVector kx, iText.Layout.Hyphenation.TernaryTree map, char p) { int k; if (p == 0) { return; } if (sc[p] == 0xFFFF) { k = map.Find(kv.GetArray(), lo[p]); if (k < 0) { k = kx.Alloc(Strlen(kv.GetArray(), lo[p]) + 1); Strcpy(kx.GetArray(), k, kv.GetArray(), lo[p]); map.Insert(kx.GetArray(), k, (char)k); } lo[p] = (char)k; } else { Compact(kx, map, lo[p]); if (sc[p] != 0) { Compact(kx, map, eq[p]); } Compact(kx, map, hi[p]); } }
internal TernaryTree(iText.Layout.Hyphenation.TernaryTree tt) { this.root = tt.root; this.freenode = tt.freenode; this.length = tt.length; this.lo = (char[])tt.lo.Clone(); this.hi = (char[])tt.hi.Clone(); this.eq = (char[])tt.eq.Clone(); this.sc = (char[])tt.sc.Clone(); this.kv = new CharVector(tt.kv); }
// With uniform letter distribution sc[root] should be around 'm' // System.out.print("After root splitchar = "); System.out.println(sc[root]); /// <summary> /// Each node stores a character (splitchar) which is part of /// some key(s). /// </summary> /// <remarks> /// Each node stores a character (splitchar) which is part of /// some key(s). In a compressed branch (one that only contain /// a single string key) the trailer of the key which is not /// already in nodes is stored externally in the kv array. /// As items are inserted, key substrings decrease. /// Some substrings may completely disappear when the whole /// branch is totally decompressed. /// The tree is traversed to find the key substrings actually /// used. In addition, duplicate substrings are removed using /// a map (implemented with a TernaryTree!). /// </remarks> public virtual void TrimToSize() { // first balance the tree for best performance Balance(); // redimension the node arrays RedimNodeArrays(freenode); // ok, compact kv array CharVector kx = new CharVector(); kx.Alloc(1); iText.Layout.Hyphenation.TernaryTree map = new iText.Layout.Hyphenation.TernaryTree(); Compact(kx, map, root); kv = kx; kv.TrimToSize(); }