Yingdi Yu | 274a227 | 2014-08-26 19:25:16 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Alexander Afanasyev | e9eda8a | 2017-03-09 14:40:03 -0800 | [diff] [blame] | 3 | * Copyright (c) 2012-2017 University of California, Los Angeles |
Yingdi Yu | 274a227 | 2014-08-26 19:25:16 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ChronoSync, synchronization library for distributed realtime |
| 6 | * applications for NDN. |
| 7 | * |
| 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. |
| 11 | * |
| 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. |
| 15 | * |
| 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> |
| 22 | * @author Yingdi Yu <yingdi@cs.ucla.edu> |
| 23 | */ |
| 24 | |
| 25 | #ifndef CHRONOSYNC_LEAF_CONTAINER_HPP |
| 26 | #define CHRONOSYNC_LEAF_CONTAINER_HPP |
| 27 | |
| 28 | #include "mi-tag.hpp" |
| 29 | #include "leaf.hpp" |
| 30 | |
Yingdi Yu | 274a227 | 2014-08-26 19:25:16 -0700 | [diff] [blame] | 31 | #include <boost/multi_index_container.hpp> |
| 32 | #include <boost/multi_index/ordered_index.hpp> |
| 33 | #include <boost/multi_index/hashed_index.hpp> |
| 34 | #include <boost/multi_index/mem_fun.hpp> |
| 35 | |
Ashlesh Gawande | 687cf92 | 2017-05-30 15:04:16 -0500 | [diff] [blame] | 36 | #include <ndn-cxx/util/sha256.hpp> |
Yingdi Yu | 274a227 | 2014-08-26 19:25:16 -0700 | [diff] [blame] | 37 | |
| 38 | namespace chronosync { |
| 39 | |
| 40 | namespace mi = boost::multi_index; |
| 41 | |
| 42 | struct SessionNameHash |
| 43 | { |
| 44 | std::size_t |
| 45 | operator()(const Name& prefix) const |
| 46 | { |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 47 | ConstBufferPtr buffer = |
Ashlesh Gawande | 687cf92 | 2017-05-30 15:04:16 -0500 | [diff] [blame] | 48 | ndn::util::Sha256::computeDigest(prefix.wireEncode().wire(), prefix.wireEncode().size()); |
Yingdi Yu | 274a227 | 2014-08-26 19:25:16 -0700 | [diff] [blame] | 49 | |
| 50 | BOOST_ASSERT(buffer->size() > sizeof(std::size_t)); |
| 51 | |
Davide Pesavento | 5473abe | 2017-10-09 01:35:33 -0400 | [diff] [blame^] | 52 | return *reinterpret_cast<const std::size_t*>(buffer->data()); |
Yingdi Yu | 274a227 | 2014-08-26 19:25:16 -0700 | [diff] [blame] | 53 | } |
| 54 | }; |
| 55 | |
| 56 | struct SessionNameEqual |
| 57 | { |
| 58 | bool |
| 59 | operator()(const Name& prefix1, const Name& prefix2) const |
| 60 | { |
| 61 | return prefix1 == prefix2; |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | struct SessionNameCompare : public std::less<Name> |
| 66 | { |
| 67 | bool |
| 68 | operator()(const Name& prefix1, const Name& prefix2) const |
| 69 | { |
| 70 | return prefix1 < prefix2; |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | /** |
| 75 | * @brief Container for chronosync leaves |
| 76 | */ |
| 77 | struct LeafContainer : public mi::multi_index_container< |
| 78 | LeafPtr, |
| 79 | mi::indexed_by< |
| 80 | // For fast access to elements using SessionName |
| 81 | mi::hashed_unique< |
| 82 | mi::tag<hashed>, |
| 83 | mi::const_mem_fun<Leaf, const Name&, &Leaf::getSessionName>, |
| 84 | SessionNameHash, |
| 85 | SessionNameEqual |
| 86 | >, |
| 87 | |
| 88 | mi::ordered_unique< |
| 89 | mi::tag<ordered>, |
| 90 | mi::const_mem_fun<Leaf, const Name&, &Leaf::getSessionName>, |
| 91 | SessionNameCompare |
| 92 | > |
| 93 | > |
| 94 | > |
| 95 | { |
| 96 | }; |
| 97 | |
| 98 | } // namespace chronosync |
| 99 | |
| 100 | #endif // CHRONOSYNC_LEAF_CONTAINER_HPP |