| 292 | |
| 293 | template <class TRecord, class TPacker> |
| 294 | static int ProcessFile(IInputStream& in, const TOptions& o, const TPacker& packer) { |
| 295 | TFixedBufferFileOutput out(o.Triefile); |
| 296 | typedef typename TRecord::TKeyChar TKeyChar; |
| 297 | typedef typename TRecord::TValue TValue; |
| 298 | |
| 299 | THolder< TCompactTrieBuilder<TKeyChar, TValue, TPacker> > builder(new TCompactTrieBuilder<TKeyChar, TValue, TPacker>(o.Flags, packer)); |
| 300 | |
| 301 | TRecord r; |
| 302 | while (r.Load(in, o.AllowEmptyKey, o.NoValues)) { |
| 303 | builder->Add(r.Key.data(), r.Key.size(), r.Value); |
| 304 | } |
| 305 | |
| 306 | if (o.Flags & CTBF_VERBOSE) { |
| 307 | Cerr << Endl; |
| 308 | Cerr << "Entries: " << builder->GetEntryCount() << Endl; |
| 309 | Cerr << "Tree nodes: " << builder->GetNodeCount() << Endl; |
| 310 | } |
| 311 | TBufferOutput inputForFastLayout; |
| 312 | IOutputStream* currentOutput = &out; |
| 313 | if (o.FastLayout) { |
| 314 | currentOutput = &inputForFastLayout; |
| 315 | } |
| 316 | if (o.Minimized) { |
| 317 | TBufferOutput raw; |
| 318 | size_t datalength = builder->Save(raw); |
| 319 | if (o.Flags & CTBF_VERBOSE) |
| 320 | Cerr << "Data length (before compression): " << datalength << Endl; |
| 321 | builder.Destroy(); |
| 322 | |
| 323 | datalength = CompactTrieMinimize(*currentOutput, raw.Buffer().Data(), raw.Buffer().Size(), o.Flags & CTBF_VERBOSE, packer); |
| 324 | if (o.Flags & CTBF_VERBOSE) |
| 325 | Cerr << "Data length (minimized): " << datalength << Endl; |
| 326 | } else { |
| 327 | size_t datalength = builder->Save(*currentOutput); |
| 328 | if (o.Flags & CTBF_VERBOSE) |
| 329 | Cerr << "Data length: " << datalength << Endl; |
| 330 | } |
| 331 | if (o.FastLayout) { |
| 332 | builder.Destroy(); |
| 333 | size_t datalength = CompactTrieMakeFastLayout(out, inputForFastLayout.Buffer().Data(), |
| 334 | inputForFastLayout.Buffer().Size(), o.Flags & CTBF_VERBOSE, packer); |
| 335 | if (o.Flags & CTBF_VERBOSE) |
| 336 | Cerr << "Data length (fast layout): " << datalength << Endl; |
| 337 | } |
| 338 | |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | template <class TRecord, class TPacker> |
| 343 | static int VerifyFile(const TOptions& o, const TPacker& packer) { |
nothing calls this directly
no test coverage detected