softcount: tolerate zero ngrams
[vspell.git] / libvspell / stridtree.h
blobdfd1c93bf734eb8db6193156ba03b4ec3b9c483a
1 #ifndef __DICTIONARY_H__
2 #include "dictionary.h"
3 #endif
4 #ifndef __VECTOR__
5 #include <vector>
6 #endif
8 #ifndef __MAP__
9 #include <map>
10 #endif
12 #ifndef BOOST_SHARED_PTR_HPP_INCLUDED
13 #include <boost/shared_ptr.hpp>
14 #endif
16 class NNode;
17 class BranchNNode;
18 class LeafNNode;
19 typedef boost::shared_ptr<NNode> NNodeRef;
21 class NNode
23 public:
24 virtual bool is_leaf() const = 0;
25 virtual ~NNode() = 0;
28 class BranchNNode:public NNode
30 protected:
31 typedef std::multimap<strid,NNodeRef> node_map;
32 typedef std::pair<node_map::const_iterator,node_map::const_iterator> const_np_range;
33 typedef std::pair<node_map::iterator,node_map::iterator> np_range;
34 node_map nodes;
35 public:
36 virtual ~BranchNNode() {}
37 bool is_leaf() const { return false; }
38 void get_leaves(strid,std::vector<LeafNNode*> &nodes) const;
39 void get_branches(strid,std::vector<BranchNNode*> &nodes) const;
40 BranchNNode* get_branch(strid) const;
41 const node_map& get_nodes() const { return nodes; }
43 BranchNNode* add_path(std::vector<strid> toks);
44 void add(strid,NNodeRef);
47 class LeafNNode:public NNode
49 protected:
50 strid id; // word id
51 public:
52 virtual ~LeafNNode() {}
53 bool is_leaf() const { return true; }
54 strid get_id() const { return id; }
55 void set_id(strid _id) { id = _id; }
57 uint get_syllable_count() const;
58 void get_syllables(std::vector<strid> &syllables) const;
62 struct DNNode {
63 NNode* node;
64 int distance;
65 DNNode(NNode* _node = NULL):node(_node),distance(0) {}
66 int operator == (const DNNode &dn1) const {
67 return dn1.node == node;
69 int operator < (const DNNode &dn1) const {
70 return (int)node+distance < (int)dn1.node+dn1.distance;
72 NNode& operator* () const { return *node; }
73 NNode* operator-> () const { return node; }