hashed.cpp
来自「Boost provides free peer-reviewed portab」· C++ 代码 · 共 79 行
CPP
79 行
/* Boost.MultiIndex example of use of hashed indices. * * Copyright 2003-2008 Joaquin M Lopez Munoz. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * See http://www.boost.org/libs/multi_index for library home page. */#if !defined(NDEBUG)#define BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING#define BOOST_MULTI_INDEX_ENABLE_SAFE_MODE#endif#include <boost/multi_index_container.hpp>#include <boost/multi_index/hashed_index.hpp>#include <boost/multi_index/member.hpp>#include <boost/multi_index/ordered_index.hpp>#include <boost/tokenizer.hpp>#include <iomanip>#include <iostream>#include <string>using boost::multi_index_container;using namespace boost::multi_index;/* word_counter keeps the ocurrences of words inserted. A hashed * index allows for fast checking of preexisting entries. */struct word_counter_entry{ std::string word; unsigned int occurrences; word_counter_entry(std::string word_):word(word_),occurrences(0){}};/* see Compiler specifics: Use of member_offset for info on * BOOST_MULTI_INDEX_MEMBER */typedef multi_index_container< word_counter_entry, indexed_by< ordered_non_unique< BOOST_MULTI_INDEX_MEMBER(word_counter_entry,unsigned int,occurrences), std::greater<unsigned int> /* sorted beginning with most frequent */ >, hashed_unique< BOOST_MULTI_INDEX_MEMBER(word_counter_entry,std::string,word) > >> word_counter;/* utilities */template<typename T>struct increment{ void operator()(T& x)const{++x;}};typedef boost::tokenizer<boost::char_separator<char> > text_tokenizer;int main(){ /* boostinspect:noascii */ std::string text= "En un lugar de la Mancha, de cuyo nombre no quiero acordarme, no ha " "mucho tiempo que viv韆 un hidalgo de los de lanza en astillero, adarga " "antigua, roc韓 flaco y galgo corredor. Una olla de algo m醩 vaca que " "carnero, salpic髇 las m醩 noches, duelos y quebrantos los s醔ados, " "lantejas los viernes, alg鷑 palomino de a馻didura los domingos, " "consum韆n las tres partes de su hacienda. El resto della conclu韆n sayo " "de velarte, calzas de velludo para las fiestas, con sus pantuflos de lo " "mesmo, y los d韆s de entresemana se honraba con su vellor
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?