3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Stefan Schimanski
8 * Full author contact details are available in file CREDITS.
15 #include "support/convert.h"
16 #include "support/debug.h"
17 #include "support/docstring.h"
18 #include "support/weighted_btree.h"
20 #include <boost/assert.hpp>
25 WordList theGlobalWordList;
27 WordList & theWordList()
29 return theGlobalWordList;
33 struct WordList::Impl {
37 typedef stx::weighted_btree<docstring, size_t, int> Words;
49 for (size_t i = 1000000; i > 0; --i) {
50 d->words_.insert("a" + convert<docstring>(i), size_t(1), stx::Void());
62 docstring const & WordList::word(size_t idx) const
64 Impl::Words::const_iterator it = d->words_.find_summed_weight(idx);
65 BOOST_ASSERT(it != d->words_.end());
70 size_t WordList::size() const
72 return d->words_.summed_weight();
76 void WordList::insert(docstring const & w)
78 Impl::Words::iterator it = d->words_.find(w);
79 if (it == d->words_.end())
80 d->words_.insert(w, size_t(1), 1);
83 d->words_.change_weight(it, 1);
88 void WordList::remove(docstring const & w)
90 Impl::Words::iterator it = d->words_.find(w);
91 if (it != d->words_.end()) {
93 d->words_.change_weight(it, 0);
94 // We will not erase here, but instead we just leave it
95 // in the btree with weight 0. This avoid too much
96 // reorganisation of the tree all the time.
98 // d->words_.erase(w);