public virtual object Clone() { CharVector cv = new CharVector((char[])array.Clone(), blockSize); cv.n = this.n; return(cv); }
private void Compact(CharVector kx, TernaryTree map, char p) { int k; if (p == 0) { return; } if (m_sc[p] == 0xFFFF) { k = map.Find(m_kv.Array, m_lo[p]); if (k < 0) { k = kx.Alloc(StrLen(m_kv.Array, m_lo[p]) + 1); StrCpy(kx.Array, k, m_kv.Array, m_lo[p]); map.Insert(kx.Array, k, (char)k); } m_lo[p] = (char)k; } else { Compact(kx, map, m_lo[p]); if (m_sc[p] != 0) { Compact(kx, map, m_eq[p]); } Compact(kx, map, m_hi[p]); } }
protected virtual void Init() { m_root = (char)0; m_freenode = (char)1; m_length = 0; m_lo = new char[BLOCK_SIZE]; m_hi = new char[BLOCK_SIZE]; m_eq = new char[BLOCK_SIZE]; m_sc = new char[BLOCK_SIZE]; m_kv = new CharVector(); }
/// <summary> /// 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!). /// /// </summary> public virtual void TrimToSize() { // first balance the tree for best performance Balance(); // redimension the node arrays RedimNodeArrays(m_freenode); // ok, compact kv array CharVector kx = new CharVector(); kx.Alloc(1); TernaryTree map = new TernaryTree(); Compact(kx, map, m_root); m_kv = kx; m_kv.TrimToSize(); }