libept
fast.h
Go to the documentation of this file.
1 #ifndef EPT_DEBTAGS_COLL_FAST_H
2 #define EPT_DEBTAGS_COLL_FAST_H
3 
8 /*
9  * Copyright (C) 2005--2015 Enrico Zini <enrico@debian.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  */
25 
26 #include <set>
27 #include <map>
28 #include <string>
29 #include <vector>
30 
31 namespace ept {
32 namespace debtags {
33 namespace coll {
34 
38 class Fast
39 {
40 protected:
41  std::map<std::string, std::set<std::string>> items;
42  std::map<std::string, std::set<std::string>> tags;
43 
44 public:
45  typedef std::map<std::string, std::set<std::string>>::const_iterator const_iterator;
46  typedef std::map<std::string, std::set<std::string>>::iterator iterator;
47  typedef std::map<std::string, std::set<std::string>>::value_type value_type;
48  typedef std::map<std::string, std::set<std::string>>::const_iterator const_tag_iterator;
49  typedef std::map<std::string, std::set<std::string>>::iterator tag_iterator;
50 
51  const_iterator begin() const { return items.begin(); }
52  const_iterator end() const { return items.end(); }
53  iterator begin() { return items.begin(); }
54  iterator end() { return items.end(); }
55 
56  const_tag_iterator tagBegin() const { return tags.begin(); }
57  const_tag_iterator tagEnd() const { return tags.end(); }
58  tag_iterator tagBegin() { return tags.begin(); }
59  tag_iterator tagEnd() { return tags.end(); }
60 
61  void insert(const std::string& item, const std::set<std::string>& tags);
62  void insert(const std::set<std::string>& items, const std::string& tag);
63  void insert(const std::set<std::string>& items, const std::set<std::string>& tags);
64 
65  void clear() { items.clear(); tags.clear(); }
66 
67  std::set<std::string> getTagsOfItem(const std::string& item) const;
68  std::set<std::string> getItemsHavingTag(const std::string& tag) const;
69 
76  std::set<std::string> getItemsHavingTags(const std::set<std::string>& tags) const;
77 
78  bool empty() const { return items.empty(); }
79 
80  bool hasItem(const std::string& item) const { return items.find(item) != items.end(); }
81  bool hasTag(const std::string& tag) const { return tags.find(tag) != tags.end(); }
82  std::set<std::string> getTaggedItems() const;
83  std::set<std::string> getAllTags() const;
84  std::vector<std::string> getAllTagsAsVector() const;
85 
86  unsigned int itemCount() const { return items.size(); }
87  unsigned int tagCount() const { return tags.size(); }
88 
89  // tag1 implies tag2 if the itemset of tag1 is a subset of the itemset of
90  // tag2
91  std::set<std::string> getTagsImplying(const std::string& tag) const;
92 
93  // Return the items which have the exact tagset 'tags'
94  std::set<std::string> getItemsExactMatch(const std::set<std::string>& tags) const;
95 
96  std::string findTagWithMaxCardinality(size_t& card) const;
97 
102  Fast getChildCollection(const std::string& tag) const;
103 
104  void removeTag(const std::string& tag);
105  void removeTagsWithCardinalityLessThan(size_t card);
106 };
107 
108 }
109 }
110 }
111 #endif
std::map< std::string, std::set< std::string > >::iterator tag_iterator
Definition: fast.h:49
std::map< std::string, std::set< std::string > >::const_iterator const_tag_iterator
Definition: fast.h:48
std::map< std::string, std::set< std::string > > tags
Definition: fast.h:42
unsigned int itemCount() const
Definition: fast.h:86
const_tag_iterator tagBegin() const
Definition: fast.h:56
iterator end()
Definition: fast.h:54
std::set< std::string > getItemsHavingTags(const std::set< std::string > &tags) const
Get the items which are tagged with at least the tags `tags&#39;.
Definition: fast.cc:91
void insert(const std::string &item, const std::set< std::string > &tags)
Definition: fast.cc:41
tag_iterator tagEnd()
Definition: fast.h:59
std::set< std::string > getItemsExactMatch(const std::set< std::string > &tags) const
Definition: fast.cc:169
std::map< std::string, std::set< std::string > >::value_type value_type
Definition: fast.h:47
String functions.
Definition: apt.cc:38
const_tag_iterator tagEnd() const
Definition: fast.h:57
std::vector< std::string > getAllTagsAsVector() const
Definition: fast.cc:133
std::set< std::string > getAllTags() const
Definition: fast.cc:124
std::set< std::string > getTagsImplying(const std::string &tag) const
Definition: fast.cc:142
bool empty() const
Definition: fast.h:78
std::map< std::string, std::set< std::string > >::iterator iterator
Definition: fast.h:46
void removeTag(const std::string &tag)
Definition: fast.cc:201
bool hasTag(const std::string &tag) const
Definition: fast.h:81
const_iterator begin() const
Definition: fast.h:51
std::map< std::string, std::set< std::string > >::const_iterator const_iterator
Definition: fast.h:45
void clear()
Definition: fast.h:65
std::set< std::string > getTagsOfItem(const std::string &item) const
Definition: fast.cc:106
bool hasItem(const std::string &item) const
Definition: fast.h:80
std::string findTagWithMaxCardinality(size_t &card) const
Definition: fast.cc:187
In-memory collection with both item->tags and tag->items mappings.
Definition: fast.h:38
std::set< std::string > getItemsHavingTag(const std::string &tag) const
Definition: fast.cc:82
std::map< std::string, std::set< std::string > > items
Definition: fast.h:41
std::set< std::string > getTaggedItems() const
Definition: fast.cc:115
void removeTagsWithCardinalityLessThan(size_t card)
Definition: fast.cc:230
const_iterator end() const
Definition: fast.h:52
iterator begin()
Definition: fast.h:53
tag_iterator tagBegin()
Definition: fast.h:58
Fast getChildCollection(const std::string &tag) const
Return the collection with only those items that have this tag, but with the given tag removed...
Definition: fast.cc:215
unsigned int tagCount() const
Definition: fast.h:87