iblt.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2020, The University of Memphis
4  *
5  * This file is part of PSync.
6  * See AUTHORS.md for complete list of PSync authors and contributors.
7  *
8  * PSync is free software: you can redistribute it and/or modify it under the terms
9  * of the GNU Lesser General Public License as published by the Free Software Foundation,
10  * either version 3 of the License, or (at your option) any later version.
11  *
12  * PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  * PURPOSE. See the GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License along with
17  * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18  *
19 
20  * This file incorporates work covered by the following copyright and
21  * permission notice:
22 
23  * The MIT License (MIT)
24 
25  * Copyright (c) 2014 Gavin Andresen
26 
27  * Permission is hereby granted, free of charge, to any person obtaining a copy
28  * of this software and associated documentation files (the "Software"), to deal
29  * in the Software without restriction, including without limitation the rights
30  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31  * copies of the Software, and to permit persons to whom the Software is
32  * furnished to do so, subject to the following conditions:
33 
34  * The above copyright notice and this permission notice shall be included in all
35  * copies or substantial portions of the Software.
36 
37  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43  * SOFTWARE.
44 */
45 
46 #ifndef PSYNC_DETAIL_IBLT_HPP
47 #define PSYNC_DETAIL_IBLT_HPP
48 
49 #include "PSync/common.hpp"
50 
51 #include <ndn-cxx/name.hpp>
52 
53 #include <set>
54 #include <string>
55 
56 namespace psync {
57 namespace detail {
58 
60 {
61 public:
62  int32_t count;
63  uint32_t keySum;
64  uint32_t keyCheck;
65 
66  bool
67  isPure() const;
68 
69  bool
70  isEmpty() const;
71 };
72 
73 extern const size_t N_HASH;
74 extern const size_t N_HASHCHECK;
75 
81 class IBLT
82 {
83 public:
84  class Error : public std::runtime_error
85  {
86  public:
87  using std::runtime_error::runtime_error;
88  };
89 
96  explicit
97  IBLT(size_t expectedNumEntries, CompressionScheme scheme);
98 
105  void
106  initialize(const ndn::name::Component& ibltName);
107 
108  void
109  insert(uint32_t key);
110 
111  void
112  erase(uint32_t key);
113 
123  bool
124  listEntries(std::set<uint32_t>& positive, std::set<uint32_t>& negative) const;
125 
126  IBLT
127  operator-(const IBLT& other) const;
128 
129  const std::vector<HashTableEntry>&
130  getHashTable() const
131  {
132  return m_hashTable;
133  }
134 
144  void
145  appendToName(ndn::Name& name) const;
146 
156  std::vector<uint32_t>
157  extractValueFromName(const ndn::name::Component& ibltName) const;
158 
159 private:
160  void
161  update(int plusOrMinus, uint32_t key);
162 
163 private:
164  std::vector<HashTableEntry> m_hashTable;
165  static const int INSERT = 1;
166  static const int ERASE = -1;
167  CompressionScheme m_compressionScheme;
168 };
169 
170 bool
171 operator==(const IBLT& iblt1, const IBLT& iblt2);
172 
173 bool
174 operator!=(const IBLT& iblt1, const IBLT& iblt2);
175 
176 std::ostream&
177 operator<<(std::ostream& os, const IBLT& iblt);
178 
179 } // namespace detail
180 } // namespace psync
181 
182 #endif // PSYNC_DETAIL_IBLT_HPP
std::ostream & operator<<(std::ostream &os, const IBLT &iblt)
Definition: iblt.cpp:259
const size_t N_HASH
Invertible Bloom Lookup Table (Invertible Bloom Filter)
Definition: iblt.hpp:81
Definition: common.hpp:33
bool operator!=(const IBLT &iblt1, const IBLT &iblt2)
Definition: iblt.cpp:253
bool operator==(const IBLT &iblt1, const IBLT &iblt2)
Definition: iblt.cpp:232
CompressionScheme
Definition: common.hpp:35
const size_t N_HASHCHECK
const std::vector< HashTableEntry > & getHashTable() const
Definition: iblt.hpp:130