]> git.lyx.org Git - features.git/blob - src/WordList.cpp
* compile fix
[features.git] / src / WordList.cpp
1 /**
2  * \file WordList.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Stefan Schimanski
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "WordList.h"
14
15 #include "support/convert.h"
16 #include "support/debug.h"
17 #include "support/docstring.h"
18 #include "support/weighted_btree.h"
19
20 #include <boost/assert.hpp>
21
22 namespace lyx {
23
24 ///
25 WordList theGlobalWordList;
26
27 WordList & theWordList()
28 {
29         return theGlobalWordList;
30 }
31         
32 ///
33 struct WordList::Impl {
34         ///
35         size_t c_;
36         ///
37         typedef stx::weighted_btree<docstring, size_t, int> Words;
38         ///
39         Words words_;
40 };
41
42
43 WordList::WordList()
44 {
45         d = new Impl;
46         d->c_ = 0;
47
48 #if 0
49         for (size_t i = 1000000; i > 0; --i) {
50                 d->words_.insert("a" + convert<docstring>(i), size_t(1), stx::Void());
51         }
52 #endif
53 }
54
55
56 WordList::~WordList()
57 {
58         delete d;
59 }
60
61
62 docstring const & WordList::word(size_t idx) const
63 {
64         Impl::Words::const_iterator it = d->words_.find_summed_weight(idx);
65         BOOST_ASSERT(it != d->words_.end());
66         return it->first;
67 }
68
69
70 size_t WordList::size() const
71 {
72         return d->words_.size();
73 }
74
75
76 void WordList::insert(docstring const & w)
77 {
78         Impl::Words::iterator it = d->words_.find(w);
79         if (it == d->words_.end())
80                 d->words_.insert(w, size_t(1), 1);
81         else
82                 it.data()++;
83 }
84
85
86 void WordList::remove(docstring const & w)
87 {
88         Impl::Words::iterator it = d->words_.find(w);
89         if (it != d->words_.end()) {
90                 it.data()--;
91                 if (it.data() == 0)
92                         d->words_.erase(w);
93         }
94 }
95
96 } // namespace lyx