- #include <map>
- #include <string>
- class Dictionary
- {
- public:
- std::string get_perfix(long mask);
- long get_mask(const std::string perfix);
- bool is_exist(const std::string member);
- void add(const std::string word);
- Dictionary();
- virtual ~Dictionary();
- private:
- long index;
- std::map<std::string, long> store;
- };
- Dictionary::Dictionary()
- {
- index = 0;
- }
- Dictionary::~Dictionary()
- {
- }
- void Dictionary::add(const std::string word)
- {
- this->store[word] = ++index;
- }
- bool Dictionary::is_exist(const std::string member)
- {
- std::map<std::string, long>::iterator pos;
- pos = this->store.find(member);
- if (pos != store.end())
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- long Dictionary::get_mask(const std::string perfix)
- {
- if ((index==0) || (perfix==""))
- {
- return 0;
- }
- else
- {
- std::map<std::string, long>::iterator pos;
- pos = this->store.find(perfix);
- if (pos != store.end())
- {
- return pos->second;
- }
- else
- {
- return 0;
- }
- }
- }
- std::string Dictionary::get_perfix(long mask)
- {
- if (mask != 0)
- {
- std::map<std::string, long>::iterator pos;
- for (pos = this->store.begin(); pos != store.end(); pos++)
- {
- if (pos->second == mask)
- {
- return pos->first;
- }
- }
- }
- return "";
- }
lz78中字典实现
最新推荐文章于 2024-03-07 11:02:32 发布