File: Trie.h

package info (click to toggle)
opensp 1.5.2-10
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 8,856 kB
  • sloc: cpp: 65,784; ansic: 17,124; sh: 13,693; xml: 2,704; makefile: 910; perl: 561; yacc: 288; sed: 16
file content (70 lines) | stat: -rw-r--r-- 1,648 bytes parent folder | download | duplicates (22)
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
// Copyright (c) 1994 James Clark
// See the file COPYING for copying permission.

#ifndef Trie_INCLUDED
#define Trie_INCLUDED 1

#include <limits.h>
#include "types.h"
#include "Boolean.h"
#include "Vector.h"
#include "CopyOwner.h"
#include "Priority.h"

#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif

class BlankTrie;

class Trie {
public:
  Trie() : next_(0), nCodes_(0) { }
  Trie(const Trie &);
  ~Trie();
  Trie &operator=(const Trie &);
  const Trie *next(int i) const { return &next_[i]; }
  Boolean hasNext() const { return next_ != 0; }
  Token token() const { return token_; }
  int tokenLength() const { return tokenLength_; }
  const BlankTrie *blank() const;
  Boolean includeBlanks() const {
    return Priority::isBlank(priority_);
  }
  friend class TrieBuilder;
private:
  Trie *next_;
  int nCodes_;
  unsigned short token_;
  unsigned char tokenLength_;
  Priority::Type priority_;
  CopyOwner<BlankTrie> blank_;
};

class BlankTrie : public Trie {
public:
  BlankTrie() { }
  Boolean codeIsBlank(EquivCode c) const { return codeIsBlank_[c]; }
  // maximum number of blanks to scan (minimum is 0)
  size_t maxBlanksToScan() const { return maxBlanksToScan_; }
  // length to add to tokenLengths in this trie (for those > 0).
  int additionalLength() const { return additionalLength_; }
  BlankTrie *copy() const { return new BlankTrie(*this); }
private:
  unsigned char additionalLength_;
  size_t maxBlanksToScan_;
  Vector<PackedBoolean> codeIsBlank_;
  friend class TrieBuilder;
};

inline
const BlankTrie *Trie::blank() const
{
  return blank_.pointer();
}

#ifdef SP_NAMESPACE
}
#endif

#endif /* not Trie_INCLUDED */