Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Davide Pesavento | 07684bc | 2021-02-07 20:09:28 -0500 | [diff] [blame] | 3 | * Copyright (c) 2012-2021 University of California, Los Angeles |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame] | 5 | * This file is part of ChronoSync, synchronization library for distributed realtime |
| 6 | * applications for NDN. |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame] | 8 | * ChronoSync is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 10 | * version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame] | 12 | * ChronoSync 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 General Public License for more details. |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/> |
| 20 | * @author Chaoyi Bian <bcy@pku.edu.cn> |
| 21 | * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html> |
Yingdi Yu | 6f79778 | 2014-08-27 12:31:11 -0700 | [diff] [blame] | 22 | * @author Yingdi Yu <yingdi@cs.ucla.edu> |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 23 | */ |
| 24 | |
Yingdi Yu | 6f79778 | 2014-08-27 12:31:11 -0700 | [diff] [blame] | 25 | #ifndef CHRONOSYNC_DIFF_STATE_CONTAINER_HPP |
| 26 | #define CHRONOSYNC_DIFF_STATE_CONTAINER_HPP |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 27 | |
Davide Pesavento | 07684bc | 2021-02-07 20:09:28 -0500 | [diff] [blame] | 28 | #include "detail/mi-tag.hpp" |
Yingdi Yu | 6f79778 | 2014-08-27 12:31:11 -0700 | [diff] [blame] | 29 | #include "diff-state.hpp" |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 30 | |
| 31 | #include <boost/multi_index_container.hpp> |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 32 | #include <boost/multi_index/hashed_index.hpp> |
| 33 | #include <boost/multi_index/sequenced_index.hpp> |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 34 | #include <boost/multi_index/mem_fun.hpp> |
Davide Pesavento | 07684bc | 2021-02-07 20:09:28 -0500 | [diff] [blame] | 35 | #include <boost/multi_index/tag.hpp> |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 36 | |
Yingdi Yu | 6f79778 | 2014-08-27 12:31:11 -0700 | [diff] [blame] | 37 | namespace chronosync { |
| 38 | |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 39 | namespace mi = boost::multi_index; |
| 40 | |
Yingdi Yu | 6f79778 | 2014-08-27 12:31:11 -0700 | [diff] [blame] | 41 | struct DigestPtrHash |
| 42 | { |
| 43 | std::size_t |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 44 | operator()(ConstBufferPtr digest) const |
Yingdi Yu | 6f79778 | 2014-08-27 12:31:11 -0700 | [diff] [blame] | 45 | { |
| 46 | BOOST_ASSERT(digest->size() > sizeof(std::size_t)); |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 47 | |
Davide Pesavento | 5473abe | 2017-10-09 01:35:33 -0400 | [diff] [blame] | 48 | return *reinterpret_cast<const std::size_t*>(digest->data()); |
Yingdi Yu | 6f79778 | 2014-08-27 12:31:11 -0700 | [diff] [blame] | 49 | } |
| 50 | }; |
| 51 | |
| 52 | struct DigestPtrEqual |
| 53 | { |
| 54 | bool |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 55 | operator()(ConstBufferPtr digest1, ConstBufferPtr digest2) const |
Yingdi Yu | 6f79778 | 2014-08-27 12:31:11 -0700 | [diff] [blame] | 56 | { |
| 57 | return *digest1 == *digest2; |
| 58 | } |
| 59 | }; |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 60 | |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 61 | /** |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 62 | * @brief Container for differential states |
| 63 | */ |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 64 | struct DiffStateContainer : public mi::multi_index_container< |
Alexander Afanasyev | a585803 | 2012-03-09 15:55:10 -0800 | [diff] [blame] | 65 | DiffStatePtr, |
| 66 | mi::indexed_by< |
| 67 | // For fast access to elements using DiffState hashes |
| 68 | mi::hashed_unique< |
| 69 | mi::tag<hashed>, |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 70 | mi::const_mem_fun<DiffState, ConstBufferPtr, &DiffState::getRootDigest>, |
Alexander Afanasyev | e4e2bf7 | 2012-03-12 12:44:54 -0700 | [diff] [blame] | 71 | DigestPtrHash, |
| 72 | DigestPtrEqual |
Yingdi Yu | 6f79778 | 2014-08-27 12:31:11 -0700 | [diff] [blame] | 73 | >, |
Alexander Afanasyev | a585803 | 2012-03-09 15:55:10 -0800 | [diff] [blame] | 74 | // sequenced index to access older/newer element (like in list) |
Davide Pesavento | 07684bc | 2021-02-07 20:09:28 -0500 | [diff] [blame] | 75 | mi::sequenced<mi::tag<sequenced>> |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 76 | > |
Alexander Afanasyev | a585803 | 2012-03-09 15:55:10 -0800 | [diff] [blame] | 77 | > |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 78 | { |
| 79 | }; |
| 80 | |
Yingdi Yu | 6f79778 | 2014-08-27 12:31:11 -0700 | [diff] [blame] | 81 | } // namespace chronosync |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 82 | |
Yingdi Yu | 6f79778 | 2014-08-27 12:31:11 -0700 | [diff] [blame] | 83 | #endif // CHRONOSYNC_DIFF_STATE_CONTAINER_HPP |