OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FixedIntegerIndex.h
Go to the documentation of this file.
1 /*
2  * opencog/atomspace/FixedIntegerIndex.h
3  *
4  * Copyright (C) 2008 Linas Vepstas <linasvepstas@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License v3 as
8  * published by the Free Software Foundation and including the exceptions
9  * at http://opencog.org/wiki/Licenses
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program; if not, write to:
18  * Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #ifndef _OPENCOG_FIXEDINTEGERINDEX_H
23 #define _OPENCOG_FIXEDINTEGERINDEX_H
24 
25 #include <cstddef>
26 #include <vector>
27 
28 #include <opencog/atomspace/Atom.h>
30 
31 namespace opencog
32 {
37 typedef std::unordered_set<Atom*> UnorderedAtomSet;
38 
44 {
45  protected:
46  std::vector<UnorderedAtomSet> idx;
47  void resize(size_t sz)
48  {
49  idx.resize(sz);
50  }
51 
52  public:
54  void insert(size_t i, Atom* a)
55  {
56  UnorderedAtomSet &s(idx.at(i));
57  s.insert(a);
58  }
59 
60  void remove(size_t i, Atom* a)
61  {
62  UnorderedAtomSet &s = idx.at(i);
63  s.erase(a);
64  }
65 
66  size_t size(size_t i) const
67  {
68  const UnorderedAtomSet &s(idx.at(i));
69  return s.size();
70  }
71 
72  size_t size(void) const;
73 };
74 
76 } //namespace opencog
77 
78 #endif // _OPENCOG_FIXEDINTEGERINDEX_H
size_t size(size_t i) const
std::vector< UnorderedAtomSet > idx
std::unordered_set< Atom * > UnorderedAtomSet
void insert(size_t i, Atom *a)