Home | History | Annotate | Download | only in compact_lang_det
      1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef ENCODINGS_COMPACT_LANG_DET_TOTE_H_
      6 #define ENCODINGS_COMPACT_LANG_DET_TOTE_H_
      7 
      8 #include <stdio.h>
      9 #include "encodings/compact_lang_det/win/cld_basictypes.h"
     10 
     11 // Take a set of <key, value> pairs and tote them up.
     12 // After explicitly sorting, retrieve top key, value pairs
     13 class Tote {
     14  public:
     15   Tote();
     16   ~Tote();
     17   void Reinit();
     18   void AddGram();
     19   void Add(uint8 ikey, int idelta);
     20   void AddBytes(int ibytes) {byte_count_ += ibytes;}
     21   int CurrentTopKey();
     22   void Sort(int n);
     23   void Dump(FILE* f);
     24   uint16 GetGramCount() const {return gram_count_;}
     25   uint16 GetIncrCount() const {return incr_count_;}
     26   int GetByteCount() const {return byte_count_;}
     27   int MaxSize() const {return kMaxSize_;}
     28   uint8 Key(int i) const {return key_[i];}
     29   int Value(int i) const {return value_[i];}
     30   void SetGramCount(uint16 v) {gram_count_ = v;}
     31   void SetIncrCount(uint16 v) {incr_count_ = v;}
     32   void SetKey(int i, int v) {key_[i] = v;}
     33   void SetValue(int i, int v) {value_[i] = v;}
     34 
     35  private:
     36   static const int kMaxSize_ = 24;
     37   uint16 gram_count_;       // Number of quadgrams/etc. scored
     38   uint16 incr_count_;       // Number of Add calls (1-3 per gram)
     39   int byte_count_;          // Bytes of text scored
     40   // Align at multiple of 8 bytes
     41   uint8 key_[kMaxSize_];    // Lang unassigned = 0, valid = 1..255
     42   int value_[kMaxSize_];    // Probability score sum
     43 };
     44 
     45 
     46 // Take a set of <key, value, reliability> triples and tote them up.
     47 // After explicitly sorting, retrieve top key, value, reliability triples
     48 class ToteWithReliability {
     49  public:
     50   ToteWithReliability();
     51   ~ToteWithReliability();
     52   void Reinit();
     53   void Add(uint8 ikey, int ibytes, int score, int ireliability);
     54   int Find(uint8 ikey);
     55   void AddClosePair(int subscr, int val) {closepair_[subscr] += val;}
     56   int CurrentTopKey();
     57   void Sort(int n);
     58   void Dump(FILE* f);
     59 
     60   ////void AddSeq(uint8 ikey) {ss_.Add(ikey);}
     61   ////void ExtractSeq(int n, uint8* dst) {ss_.Extract(n, dst);}
     62 
     63   int GetIncrCount() const {return incr_count_;}
     64   int GetClosePair(int subscr) const {return closepair_[subscr];}
     65   int MaxSize() const {return kMaxSize_;}
     66   uint8 Key(int i) const {return key_[i];}
     67   int Value(int i) const {return value_[i];}
     68   int Score(int i) const {return score_[i];}
     69   int Reliability(int i) const {return reliability_[i];}
     70   void SetKey(int i, int v) {key_[i] = v;}
     71   void SetValue(int i, int v) {value_[i] = v;}
     72   void SetScore(int i, int v) {score_[i] = v;}
     73   void SetReliability(int i, int v) {reliability_[i] = v;}
     74 
     75  private:
     76   static const int kMaxSize_ = 24;
     77   static const int kMaxClosePairSize_ = 8;
     78   int incr_count_;         // Number of Add calls
     79   int sorted_;             // Contents have been sorted, cannot Add
     80   // Align at multiple of 8 bytes
     81   int closepair_[kMaxClosePairSize_];
     82   uint8 key_[kMaxSize_];    // Lang unassigned = 0, valid = 1..255
     83   int value_[kMaxSize_];    // Bytecount this lang
     84   int score_[kMaxSize_];    // Probability score sum
     85   int reliability_[kMaxSize_];  // Percentage 0..100
     86   ////SubsetSequence ss_;
     87 };
     88 
     89 #endif  // ENCODINGS_COMPACT_LANG_DET_TOTE_H_
     90