-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmtrie.C
781 lines (677 loc) · 21.5 KB
/
mtrie.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
/****************************** -*- C++ -*- *****************************/
/* */
/* LangIdent: n-gram based language-identification */
/* by Ralf Brown / Carnegie Mellon University */
/* */
/* File: mtrie.C - bit-slice-based Word-frequency multi-trie */
/* Version: 1.30 */
/* LastEdit: 2019-07-15 */
/* */
/* (c) Copyright 2011,2012,2015,2019 Carnegie Mellon University */
/* This program is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU General Public License as */
/* published by the Free Software Foundation, version 3. */
/* */
/* This program is distributed in the hope that it will be */
/* useful, but WITHOUT ANY WARRANTY; without even the implied */
/* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR */
/* PURPOSE. See the GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public */
/* License (file COPYING) along with this program. If not, see */
/* http://www.gnu.org/licenses/ */
/* */
/************************************************************************/
#include <cassert>
#include <cstring>
#include "mtrie.h"
#include "framepac/memory.h"
#include "framepac/message.h"
#include "framepac/texttransforms.h"
using namespace std ;
using namespace Fr ;
/************************************************************************/
/* Manifest Constants */
/************************************************************************/
#define MULTITRIE_SIGNATURE "MulTrie\0"
#define MULTITRIE_FORMAT_VERSION 2
// reserve some space for future additions to the file format
#define MULTITRIE_PADBYTES_1 64
#if BITS_PER_LEVEL == 3
# define LEVEL_SIZE 9
#else
# define LEVEL_SIZE 8
#endif
/************************************************************************/
/* Types */
/************************************************************************/
/************************************************************************/
/* Global variables */
/************************************************************************/
ItemPoolFlat<MultiTrieFrequency> MultiTrieFrequency::s_freq_records(100000) ;
/************************************************************************/
/* Helper functions */
/************************************************************************/
#ifndef lengthof
# define lengthof(x) (sizeof(x)/sizeof((x)[0]))
#endif /* lengthof */
//----------------------------------------------------------------------
// defined in trie.C
uint32_t scaled_frequency(uint32_t raw_freq, uint64_t total_count) ;
/************************************************************************/
/* Methods for class MultiTrieFrequency */
/************************************************************************/
MultiTrieFrequency::~MultiTrieFrequency()
{
m_next = 0 ;
m_frequency = 0 ;
return ;
}
//----------------------------------------------------------------------
MultiTrieFrequency* MultiTrieFrequency::allocate(uint32_t freq, uint32_t lang, bool stopgram)
{
size_t recnum = s_freq_records.alloc() ;
auto freq_record = &s_freq_records[recnum] ;
new (freq_record) MultiTrieFrequency(freq,lang,stopgram) ;
return freq_record ;
}
//----------------------------------------------------------------------
uint32_t MultiTrieFrequency::frequency(uint32_t ID) const
{
if (ID == m_langID)
return frequency() ;
else if (next())
return next()->frequency(ID) ;
return 0 ;
}
//----------------------------------------------------------------------
void MultiTrieFrequency::newFrequency(uint32_t ID, uint32_t freq, bool stopgram)
{
// add a record with the new language ID and frequency
// because the allocation might reallocate the array containing
// 'this', we need to get our index and use it to re-establish
// the correct object address after the allocation
uint32_t index = (this - s_freq_records.item(0)) ;
MultiTrieFrequency *f = allocate(freq,ID,stopgram) ;
MultiTrieFrequency *prev = getAddress(index) ;
prev->setNext(f) ;
}
//----------------------------------------------------------------------
void MultiTrieFrequency::setFrequency(uint32_t ID, uint32_t freq, bool stopgram)
{
if (ID == languageID())
{
setFrequency(freq) ;
return ;
}
MultiTrieFrequency *nxt = next() ;
if (nxt)
{
nxt->setFrequency(ID,freq,stopgram) ;
}
else
{
newFrequency(ID,freq,stopgram) ;
}
return ;
}
//----------------------------------------------------------------------
void MultiTrieFrequency::incrFrequency(uint32_t ID, uint32_t incr)
{
if (ID == languageID())
{
incrFrequency(incr) ;
return ;
}
MultiTrieFrequency *nxt = next() ;
if (nxt)
{
nxt->incrFrequency(ID,incr) ;
}
else
{
// add a record with the new ID
newFrequency(ID,incr,false) ;
}
return ;
}
//----------------------------------------------------------------------
void MultiTrieFrequency::scaleFrequency(uint64_t total_count,
uint32_t id)
{
if (languageID() == id)
m_frequency = scaled_frequency(m_frequency,total_count) ;
else if (next())
next()->scaleFrequency(total_count,id) ;
return ;
}
//----------------------------------------------------------------------
bool MultiTrieFrequency::readAll(CFile& f)
{
UInt32 cnt ;
if (f && f.readValue(&cnt))
{
if (s_freq_records.load(f,cnt.load()))
return true ;
}
return false ;
}
//----------------------------------------------------------------------
bool MultiTrieFrequency::write(CFile& f) const
{
return f && f.writeValue(*this) ;
}
//----------------------------------------------------------------------
bool MultiTrieFrequency::writeAll(CFile& f)
{
UInt32 count(s_freq_records.size()) ;
return f && f.writeValue(count) && s_freq_records.save(f) ;
}
/************************************************************************/
/* Methods for class MultiTrieNode */
/************************************************************************/
MultiTrieNode::MultiTrieNode()
{
m_frequency = LangIDMultiTrie::INVALID_FREQ ;
return ;
}
//----------------------------------------------------------------------
bool MultiTrieNode::isStopgram(unsigned langID) const
{
auto freq = frequencies() ;
for ( ; freq ; freq = freq->next())
{
if (freq->languageID() == langID)
return freq->isStopgram() ;
}
return false ;
}
//----------------------------------------------------------------------
unsigned MultiTrieNode::numFrequencies() const
{
auto freq = frequencies() ;
unsigned count = 0 ;
for ( ; freq ; freq = freq->next())
count++ ;
return count ;
}
//----------------------------------------------------------------------
uint32_t MultiTrieNode::frequency(uint32_t langID) const
{
auto freq = frequencies() ;
for ( ; freq ; freq = freq->next())
{
if (freq->languageID() == langID)
return freq->frequency() ;
}
return 0 ;
}
//----------------------------------------------------------------------
void MultiTrieNode::setFrequency(uint32_t langID, uint32_t freq, bool stopgram)
{
auto f = MultiTrieFrequency::getAddress(m_frequency) ;
if (f)
f->setFrequency(langID,freq,stopgram) ;
else
{
// insert the initial frequency record
f = MultiTrieFrequency::allocate(freq,langID,stopgram) ;
m_frequency = MultiTrieFrequency::getIndex(f) ;
}
return ;
}
//----------------------------------------------------------------------
bool MultiTrieNode::setFrequencies(MultiTrieFrequency *freqs)
{
auto idx = MultiTrieFrequency::getIndex(freqs) ;
if (idx == LangIDMultiTrie::INVALID_FREQ)
return false ;
m_frequency = idx ;
return true ;
}
//----------------------------------------------------------------------
uint32_t MultiTrieNode::insertChild(unsigned int N, LangIDMultiTrie *trie)
{
if (N < lengthof(m_children))
{
if (childPresent(N))
return childIndex(N) ;
else
{
uint32_t new_index = trie->allocateNode() ;
if (new_index)
{
m_children[N] = new_index ;
return new_index ;
}
}
}
return NybbleTrie::INVALID_INDEX ;
}
//----------------------------------------------------------------------
bool MultiTrieNode::load(CFile& f)
{
return f && f.readValue(this) ;
}
//----------------------------------------------------------------------
bool MultiTrieNode::write(CFile& f) const
{
return f && f.writeValue(*this) ;
}
/************************************************************************/
/* Methods for class LangIDMultiTrie */
/************************************************************************/
LangIDMultiTrie::LangIDMultiTrie(uint32_t cap)
{
init(cap) ;
return ;
}
//----------------------------------------------------------------------
LangIDMultiTrie::LangIDMultiTrie(const char *filename, uint32_t langID, bool verbose)
{
init(1) ;
LoadFn* insfn = [](NybbleTrie* trie, const uint8_t* key, unsigned keylen, uint32_t lang, uint32_t freq) -> bool
{ return static_cast<LangIDMultiTrie*>(trie)->insert(key,keylen,lang,freq,false) ; } ;
loadWords(filename,insfn,langID,verbose) ;
return ;
}
//----------------------------------------------------------------------
void LangIDMultiTrie::init(uint32_t cap)
{
MultiTrieFrequency::allocateDummy() ;
m_maxkeylen = 0 ;
m_totaltokens = 0 ;
m_ignorewhitespace = false ;
if (cap == 0)
cap = 1 ;
m_nodes.reserve(cap) ;
auto root = m_nodes.alloc() ;
// initialize the root node
new (node(root)) MultiTrieNode ;
return ;
}
//----------------------------------------------------------------------
bool LangIDMultiTrie::insert(const uint8_t *key, unsigned keylength,
uint32_t langID, uint32_t frequency, bool stopgram)
{
auto leaf = node(insertKey(key,keylength)) ;
bool new_node = false ;
if (leaf)
{
new_node = (leaf->frequency() == 0) ;
leaf->setFrequency(langID,frequency,stopgram) ;
leaf->markAsLeaf() ;
if (frequency > 0)
{
addTokenCount() ;
}
}
return new_node ;
}
//----------------------------------------------------------------------
uint32_t LangIDMultiTrie::increment(const uint8_t *key, unsigned keylength,
uint32_t langID, uint32_t incr,
bool stopgram)
{
uint32_t cur_index = ROOT_INDEX ;
for (size_t i = 0 ; i < keylength ; i++)
{
if (!extendKey(cur_index,key[i]))
{
insert(key,keylength,langID,incr,stopgram) ;
return incr ;
}
}
auto n = node(cur_index) ;
if (n)
{
uint32_t freq = n->frequency(langID) + incr ;
n->setFrequency(langID,freq,n->isStopgram(langID)) ;
return freq ;
}
else
{
insert(key,keylength,langID,incr,stopgram) ;
return incr ;
}
}
//----------------------------------------------------------------------
bool LangIDMultiTrie::incrementExtensions(const uint8_t *key, unsigned prevlength,
unsigned keylength, uint32_t langID,
uint32_t incr)
{
uint32_t cur_index = ROOT_INDEX ;
// check whether the prevlength prefix is present in the trie
for (size_t i = 0 ; i < prevlength ; i++)
{
if (!extendKey(cur_index,key[i]))
return false ;
}
// now add on one byte at a time, incrementing the count for each
for (size_t i = prevlength ; i < keylength ; i++)
{
this->insertChild(cur_index,key[i]) ;
auto n = node(cur_index) ;
if (!n)
return false ;
uint32_t freq = n->frequency(langID) + incr ;
n->setFrequency(langID,freq,n->isStopgram(langID)) ;
}
return true ;
}
//----------------------------------------------------------------------
bool LangIDMultiTrie::enumerate(uint8_t *keybuf, unsigned maxkeylength, EnumFn *fn, void *user_data) const
{
if (keybuf && fn)
{
std::fill_n(keybuf,maxkeylength,'\0') ;
return enumerateChildren(ROOT_INDEX,keybuf,maxkeylength*8,0,fn,user_data) ;
}
return false ;
}
//----------------------------------------------------------------------
bool LangIDMultiTrie::enumerateChildren(NodeIndex nodeindex,
uint8_t *keybuf,
unsigned max_keylength_bits,
unsigned curr_keylength_bits,
LangIDMultiTrie::EnumFn *fn,
void *user_data) const
{
auto n = node(nodeindex) ;
// assert(!(!n->leaf() && n->frequencies())) ;
if (n->leaf() && !fn(this,nodeindex,keybuf,curr_keylength_bits/8,user_data))
return false ;
if (curr_keylength_bits < max_keylength_bits)
{
unsigned curr_bits = curr_keylength_bits + BITS_PER_LEVEL ;
for (size_t i = 0 ; i < (1<<BITS_PER_LEVEL) ; i++)
{
uint32_t child = n->childIndex(i) ;
if (child != LangIDMultiTrie::NULL_INDEX)
{
auto childnode = node(child) ;
if (childnode)
{
unsigned byte = curr_keylength_bits / 8 ;
unsigned shift = LEVEL_SIZE - (curr_keylength_bits%8) - BITS_PER_LEVEL ;
#if BITS_PER_LEVEL == 3
if (shift == 0) curr_bits = curr_keylength_bits + BITS_PER_LEVEL - 1 ;
#endif
unsigned mask = (((1<<BITS_PER_LEVEL)-1) << shift) ;
keybuf[byte] &= ~mask ;
keybuf[byte] |= (i << shift) ;
if (!enumerateChildren(child,keybuf,max_keylength_bits,curr_bits,fn,user_data))
return false ;
}
}
}
}
return true ;
}
//----------------------------------------------------------------------
size_t LangIDMultiTrie::countTerminalNodes(NodeIndex nodeindex, unsigned keylen_bits) const
{
size_t count = 0 ;
auto n = node(nodeindex) ;
if (!n->hasChildren())
{
return (keylen_bits % 8 == 0) ? 1 : 0 ;
}
keylen_bits += BITS_PER_LEVEL ;
#if BITS_PER_LEVEL == 3
if (keylen_bits % 8 == 1) --keylen_bits ;
#endif
for (size_t i = 0 ; i < (1<<BITS_PER_LEVEL) ; i++)
{
uint32_t child = n->childIndex(i) ;
if (child != NULL_INDEX)
count += countTerminalNodes(child,keylen_bits) ;
}
return count ;
}
//----------------------------------------------------------------------
size_t LangIDMultiTrie::countFullByteNodes(NodeIndex nodeindex, unsigned keylen_bits) const
{
size_t count = 0 ;
if (keylen_bits % 8 == 0)
count++ ;
keylen_bits = keylen_bits + BITS_PER_LEVEL ;
#if BITS_PER_LEVEL == 3
if (keylen_bits % 8 == 1) keylen_bits-- ;
#endif
auto n = node(nodeindex) ;
for (size_t i = 0 ; i < (1<<BITS_PER_LEVEL) ; i++)
{
uint32_t child = n->childIndex(i) ;
if (child != NULL_INDEX)
count += countFullByteNodes(child,keylen_bits) ;
}
return count ;
}
//----------------------------------------------------------------------
unsigned LangIDMultiTrie::numExtensions(NodeIndex nodeindex, unsigned bits) const
{
if (bits >= 8)
{
return 1 ;
}
auto n = node(nodeindex) ;
unsigned count = 0 ;
for (size_t i = 0 ; i < (1<<BITS_PER_LEVEL) ; ++i)
{
auto child = n->childIndex(i) ;
if (child != NULL_INDEX)
count += numExtensions(child,bits+BITS_PER_LEVEL) ;
}
return count ;
}
//----------------------------------------------------------------------
bool LangIDMultiTrie::allChildrenAreTerminals(NodeIndex nodeindex, unsigned bits) const
{
auto n = node(nodeindex) ;
if (bits >= 8)
{
return !n->hasChildren() ;
}
for (size_t i = 0 ; i < (1<<BITS_PER_LEVEL) ; ++i)
{
auto child = n->childIndex(i) ;
if (child != NULL_INDEX && !allChildrenAreTerminals(child,bits+BITS_PER_LEVEL))
return false ;
}
return true ;
}
//----------------------------------------------------------------------
uint32_t LangIDMultiTrie::numFullByteNodes() const
{
return countFullByteNodes(ROOT_INDEX) ;
}
//----------------------------------------------------------------------
uint32_t LangIDMultiTrie::numTerminalNodes() const
{
return countTerminalNodes(ROOT_INDEX) ;
}
//----------------------------------------------------------------------
static bool count_freq_records(const LangIDMultiTrie* trie, NybbleTrie::NodeIndex nodeindex, const uint8_t *,
unsigned, void *user_data)
{
auto node = trie->node(nodeindex) ;
auto count = reinterpret_cast<uint32_t*>(user_data) ;
(*count) += node->numFrequencies() ;
return true ;
}
//----------------------------------------------------------------------
uint32_t LangIDMultiTrie::countFreqRecords() const
{
uint32_t count = 0 ;
uint8_t keybuf[longestKey()] ;
(void)this->enumerate(keybuf,longestKey(),count_freq_records,&count) ;
return count ;
}
//----------------------------------------------------------------------
LangIDMultiTrie *LangIDMultiTrie::load(CFile& f)
{
if (!f)
return nullptr ;
int version = f.verifySignature(MULTITRIE_SIGNATURE) ;
if (version < 0)
{
if (version == -1) { /* read error */ }
if (version == -2) { /* wrong file type */ }
if (version == -3) { /* wrong byte order */ }
return nullptr ;
}
if (version != MULTITRIE_FORMAT_VERSION)
{
// error: wrong version of data file
return nullptr ;
}
unsigned char bits ;
if (!f.readValue(&bits) || bits != BITS_PER_LEVEL)
{
// error: wrong type of trie
return nullptr ;
}
UInt32 val_used, val_tokens, val_keylen ;
if (!f.readValue(&val_used) ||
!f.readValue(&val_tokens) ||
!f.readValue(&val_keylen))
{
// error reading header
return nullptr ;
}
uint32_t used = val_used.load() ;
Owned<LangIDMultiTrie> trie(used) ;
if (!trie)
return nullptr ;
trie->m_nodes.allocBatch(used) ;
trie->addTokenCount(val_tokens.load()) ;
trie->m_maxkeylen = (unsigned)val_keylen.load() ;
// skip the padding (reserved bytes)
f.seek(MULTITRIE_PADBYTES_1,SEEK_CUR) ;
// read the actual trie nodes
for (size_t i = 0 ; i < used ; i++)
{
auto node = trie->node(i) ;
if (!node->load(f))
{
return nullptr ;
}
}
// finally, read the frequency information
if (!MultiTrieFrequency::readAll(f))
{
return nullptr ;
}
return trie.move() ;
}
//----------------------------------------------------------------------
LangIDMultiTrie *LangIDMultiTrie::load(const char *filename)
{
CInputFile fp(filename) ;
return load(fp) ;
}
//----------------------------------------------------------------------
bool LangIDMultiTrie::writeHeader(CFile& f) const
{
// write the signature string
if (!f.writeSignature(MULTITRIE_SIGNATURE,MULTITRIE_FORMAT_VERSION))
return false ;
// follow with the number of bits per level of the trie
unsigned char bits = BITS_PER_LEVEL ;
if (!f.writeValue(bits))
return false ;
// write out the size of the trie
UInt32 val_used(size()), val_tokens(totalTokens()), val_keylen(longestKey()) ;
if (!f.writeValue(val_used) ||
!f.writeValue(val_tokens) ||
!f.writeValue(val_keylen))
return false ;
// pad the header with NULs for the unused reserved portion of the header
return f.putNulls(MULTITRIE_PADBYTES_1) ;
}
//----------------------------------------------------------------------
bool LangIDMultiTrie::write(CFile& f) const
{
if (!f || !writeHeader(f))
return false ;
// write the actual trie nodes
for (size_t i = 0 ; i < size() ; i++)
{
const auto n = node(i) ;
if (!n->write(f))
return false ;
}
// write the frequency information
if (!MultiTrieFrequency::writeAll(f))
return false ;
f.writeComplete() ;
return true ;
}
//----------------------------------------------------------------------
bool LangIDMultiTrie::write(const char *filename) const
{
COutputFile fp(filename,CFile::safe_rewrite) ;
return this->write(fp) ? fp.close() : false ;
}
//----------------------------------------------------------------------
static const char hexdigit[] = "0123456789ABCDEF" ;
void write_escaped_char(uint8_t c, CFile& f)
{
switch (c)
{
case '\\':
f.puts("\\\\") ;
break ;
case ' ':
f.puts("\\ ") ;
break ;
default:
if (c < ' ')
{
f.putc('\\') ;
f.putc(hexdigit[(c>>4)&0xF]) ;
f.putc(hexdigit[c&0xF]) ;
}
else
f.putc(c) ;
break ;
}
return ;
}
//----------------------------------------------------------------------
void write_escaped_key(CFile& f, const uint8_t* key, unsigned keylen)
{
for (size_t i = 0 ; i < keylen ; i++)
{
write_escaped_char(key[i],f) ;
}
return ;
}
//----------------------------------------------------------------------
static bool dump_ngram(const LangIDMultiTrie* trie, NybbleTrie::NodeIndex nodeindex, const uint8_t *key,
unsigned keylen, void *user_data)
{
auto node = trie->node(nodeindex) ;
CFile& f = *((CFile*)user_data) ;
if (f && node)
{
f.printf(" ") ;
write_escaped_key(f,key,keylen) ;
f.printf(" ::") ;
auto freq = node->frequencies() ;
for ( ; freq ; freq = freq->next())
{
f.printf(" %lu=%lu",(unsigned long)freq->languageID(), (unsigned long)freq->frequency()) ;
}
f.printf("\n") ;
}
return true ;
}
//----------------------------------------------------------------------
bool LangIDMultiTrie::dump(CFile& f) const
{
LocalAlloc<uint8_t,10000> keybuf(longestKey()) ;
return keybuf ? enumerate(keybuf,longestKey(),dump_ngram,&f) : false ;
}
// end of file mtrie.C //