akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 19 | * Chaoyi Bian <bcy@pku.edu.cn> |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 20 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 21 | */ |
| 22 | |
dmcoomes | e689dd6 | 2017-03-29 11:05:12 -0500 | [diff] [blame] | 23 | #ifndef NLSR_NSYNC_SYNC_STATE_LEAF_CONTAINER_H |
| 24 | #define NLSR_NSYNC_SYNC_STATE_LEAF_CONTAINER_H |
akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 25 | |
| 26 | #include "sync-leaf.h" |
| 27 | #include "sync-name-info.h" |
| 28 | |
| 29 | #include <boost/multi_index_container.hpp> |
| 30 | // #include <boost/multi_index/tag.hpp> |
| 31 | #include <boost/multi_index/ordered_index.hpp> |
| 32 | // #include <boost/multi_index/composite_key.hpp> |
| 33 | #include <boost/multi_index/hashed_index.hpp> |
| 34 | // #include <boost/multi_index/random_access_index.hpp> |
| 35 | // #include <boost/multi_index/member.hpp> |
| 36 | #include <boost/multi_index/mem_fun.hpp> |
| 37 | |
| 38 | namespace mi = boost::multi_index; |
| 39 | |
| 40 | namespace Sync { |
| 41 | |
| 42 | struct NameInfoHash : public std::unary_function<NameInfo, std::size_t> |
| 43 | { |
| 44 | std::size_t |
| 45 | operator() (NameInfoConstPtr prefix) const |
| 46 | { |
| 47 | return prefix->getHashId (); |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | struct NameInfoEqual : public std::unary_function<NameInfo, std::size_t> |
| 52 | { |
| 53 | bool |
| 54 | operator() (NameInfoConstPtr prefix1, NameInfoConstPtr prefix2) const |
| 55 | { |
| 56 | return *prefix1 == *prefix2; |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | struct NameInfoCompare : public std::unary_function<NameInfo, std::size_t> |
| 61 | { |
| 62 | bool |
| 63 | operator() (NameInfoConstPtr prefix1, NameInfoConstPtr prefix2) const |
| 64 | { |
| 65 | return *prefix1 < *prefix2; |
| 66 | } |
| 67 | }; |
| 68 | |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 69 | /// @cond include_hidden |
akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 70 | struct hashed { }; |
| 71 | struct ordered { }; |
| 72 | /// @endcond |
| 73 | |
| 74 | /** |
| 75 | * \ingroup sync |
| 76 | * @brief Container for SYNC leaves |
| 77 | */ |
| 78 | struct LeafContainer : public mi::multi_index_container< |
| 79 | LeafPtr, |
| 80 | mi::indexed_by< |
| 81 | // For fast access to elements using NameInfo |
| 82 | mi::hashed_unique< |
| 83 | mi::tag<hashed>, |
| 84 | mi::const_mem_fun<Leaf, NameInfoConstPtr, &Leaf::getInfo>, |
| 85 | NameInfoHash, |
| 86 | NameInfoEqual |
| 87 | >, |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 88 | |
akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 89 | mi::ordered_unique< |
| 90 | mi::tag<ordered>, |
| 91 | mi::const_mem_fun<Leaf, NameInfoConstPtr, &Leaf::getInfo>, |
| 92 | NameInfoCompare |
| 93 | > |
| 94 | > |
| 95 | > |
| 96 | { |
| 97 | }; |
| 98 | |
| 99 | } // Sync |
| 100 | |
dmcoomes | e689dd6 | 2017-03-29 11:05:12 -0500 | [diff] [blame] | 101 | #endif // NLSR_NSYNC_SYNC_STATE_LEAF_CONTAINER_H |