Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [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> |
Chaoyi Bian | 3e1eb16 | 2012-04-03 16:59:32 -0700 | [diff] [blame] | 19 | * Chaoyi Bian <bcy@pku.edu.cn> |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 20 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 21 | */ |
| 22 | |
| 23 | #ifndef SYNC_DIFF_STATE_CONTAINER_H |
| 24 | #define SYNC_DIFF_STATE_CONTAINER_H |
| 25 | |
Alexander Afanasyev | 182fdc2 | 2012-03-05 18:06:52 -0800 | [diff] [blame] | 26 | #include "sync-diff-state.h" |
Alexander Afanasyev | a585803 | 2012-03-09 15:55:10 -0800 | [diff] [blame] | 27 | #include "sync-digest.h" |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 28 | |
| 29 | #include <boost/multi_index_container.hpp> |
Alexander Afanasyev | a585803 | 2012-03-09 15:55:10 -0800 | [diff] [blame] | 30 | #include <boost/multi_index/tag.hpp> |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 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/sequenced_index.hpp> |
| 35 | // #include <boost/multi_index/random_access_index.hpp> |
Alexander Afanasyev | 3a22913 | 2012-04-25 15:07:26 -0700 | [diff] [blame^] | 36 | #include <boost/multi_index/member.hpp> |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 37 | #include <boost/multi_index/mem_fun.hpp> |
| 38 | |
| 39 | namespace mi = boost::multi_index; |
| 40 | |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 41 | namespace Sync { |
| 42 | |
Alexander Afanasyev | e4e2bf7 | 2012-03-12 12:44:54 -0700 | [diff] [blame] | 43 | struct DigestPtrHash : public std::unary_function<Digest, std::size_t> |
Alexander Afanasyev | a585803 | 2012-03-09 15:55:10 -0800 | [diff] [blame] | 44 | { |
Alexander Afanasyev | a585803 | 2012-03-09 15:55:10 -0800 | [diff] [blame] | 45 | std::size_t |
| 46 | operator() (DigestConstPtr digest) const |
| 47 | { |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 48 | // std::cout << "digest->getHash: " << digest->getHash () << " (" << *digest << ")" << std::endl; |
Alexander Afanasyev | a585803 | 2012-03-09 15:55:10 -0800 | [diff] [blame] | 49 | return digest->getHash (); |
| 50 | } |
| 51 | }; |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 52 | |
Alexander Afanasyev | e4e2bf7 | 2012-03-12 12:44:54 -0700 | [diff] [blame] | 53 | struct DigestPtrEqual : public std::unary_function<Digest, std::size_t> |
| 54 | { |
| 55 | bool |
| 56 | operator() (DigestConstPtr digest1, DigestConstPtr digest2) const |
| 57 | { |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 58 | // std::cout << boost::cref(*digest1) << " == " << boost::cref(*digest2) << " : " << (*digest1 == *digest2) << std::endl; |
Alexander Afanasyev | e4e2bf7 | 2012-03-12 12:44:54 -0700 | [diff] [blame] | 59 | return *digest1 == *digest2; |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 64 | /// @cond include_hidden |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 65 | struct sequenced { }; |
Alexander Afanasyev | 3a22913 | 2012-04-25 15:07:26 -0700 | [diff] [blame^] | 66 | struct timed { }; |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 67 | /// @endcond |
| 68 | |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 69 | /** |
| 70 | * \ingroup sync |
| 71 | * @brief Container for differential states |
| 72 | */ |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 73 | struct DiffStateContainer : public mi::multi_index_container< |
Alexander Afanasyev | a585803 | 2012-03-09 15:55:10 -0800 | [diff] [blame] | 74 | DiffStatePtr, |
| 75 | mi::indexed_by< |
| 76 | // For fast access to elements using DiffState hashes |
| 77 | mi::hashed_unique< |
| 78 | mi::tag<hashed>, |
| 79 | mi::const_mem_fun<DiffState, DigestConstPtr, &DiffState::getDigest>, |
Alexander Afanasyev | e4e2bf7 | 2012-03-12 12:44:54 -0700 | [diff] [blame] | 80 | DigestPtrHash, |
| 81 | DigestPtrEqual |
Alexander Afanasyev | a585803 | 2012-03-09 15:55:10 -0800 | [diff] [blame] | 82 | > |
| 83 | , |
| 84 | // sequenced index to access older/newer element (like in list) |
| 85 | mi::sequenced<mi::tag<sequenced> > |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 86 | > |
Alexander Afanasyev | a585803 | 2012-03-09 15:55:10 -0800 | [diff] [blame] | 87 | > |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 88 | { |
| 89 | }; |
| 90 | |
Alexander Afanasyev | 3a22913 | 2012-04-25 15:07:26 -0700 | [diff] [blame^] | 91 | struct DigestTime |
| 92 | { |
| 93 | DigestTime (DigestConstPtr digest, const TimeAbsolute &time) |
| 94 | : m_digest (digest) |
| 95 | , m_time (time) |
| 96 | { |
| 97 | } |
| 98 | |
| 99 | DigestConstPtr m_digest; |
| 100 | TimeAbsolute m_time; |
| 101 | }; |
| 102 | |
| 103 | struct UnknownDigestContainer : public mi::multi_index_container< |
| 104 | DigestTime, |
| 105 | mi::indexed_by< |
| 106 | mi::hashed_unique< |
| 107 | mi::tag<hashed>, |
| 108 | mi::member<DigestTime, DigestConstPtr, &DigestTime::m_digest>, |
| 109 | DigestPtrHash, |
| 110 | DigestPtrEqual |
| 111 | > |
| 112 | , |
| 113 | mi::ordered_non_unique< |
| 114 | mi::tag<timed>, |
| 115 | mi::member<DigestTime, TimeAbsolute, &DigestTime::m_time> |
| 116 | > |
| 117 | > |
| 118 | > |
| 119 | { |
| 120 | }; |
| 121 | |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 122 | } // Sync |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 123 | |
| 124 | #endif // SYNC_DIFF_STATE_CONTAINER_H |