| 341 | |
| 342 | template <class TRecord, class TPacker> |
| 343 | static int VerifyFile(const TOptions& o, const TPacker& packer) { |
| 344 | TMappedFile filemap(o.Triefile); |
| 345 | typedef typename TRecord::TKeyChar TKeyChar; |
| 346 | typedef typename TRecord::TValue TValue; |
| 347 | TCompactTrie<TKeyChar, TValue, TPacker> trie((const char*)filemap.getData(), filemap.getSize(), packer); |
| 348 | |
| 349 | TFileInput in(o.Infile); |
| 350 | size_t entrycount = 0; |
| 351 | int retcode = 0; |
| 352 | TRecord r; |
| 353 | while (r.Load(in, o.AllowEmptyKey, o.NoValues)) { |
| 354 | entrycount++; |
| 355 | TValue trievalue; |
| 356 | |
| 357 | if (!trie.Find(r.Key.data(), r.Key.size(), &trievalue)) { |
| 358 | Cerr << "Trie check failed on key #" << entrycount << "\"" << r.Key << "\": no key present" << Endl; |
| 359 | retcode = 1; |
| 360 | } else if (!o.NoValues && trievalue != r.Value) { |
| 361 | Cerr << "Trie check failed on key #" << entrycount << "\"" << r.Key << "\": value mismatch" << Endl; |
| 362 | retcode = 1; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | for (typename TCompactTrie<TKeyChar, TValue, TPacker>::TConstIterator iter = trie.Begin(); iter != trie.End(); ++iter) { |
| 367 | entrycount--; |
| 368 | } |
| 369 | |
| 370 | if (entrycount) { |
| 371 | Cerr << "Broken iteration: entry count mismatch" << Endl; |
| 372 | retcode = 1; |
| 373 | } |
| 374 | |
| 375 | if ((o.Flags & CTBF_VERBOSE) && !retcode) { |
| 376 | Cerr << "Trie check successful" << Endl; |
| 377 | } |
| 378 | return retcode; |
| 379 | } |
| 380 | |
| 381 | template <class TRecord, class TPacker> |
| 382 | static int SelectInput(const TOptions& o, const TPacker& packer) { |