blob: f03caf190f098778dcb5ad80ab07b511c7d8c2b3 [file] [log] [blame]
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Ashlesh Gawande08784d42017-09-06 23:40:21 -05003 * Copyright (c) 2012-2017 University of California, Los Angeles
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -08004 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -07005 * This file is part of ChronoSync, synchronization library for distributed realtime
6 * applications for NDN.
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -08007 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -07008 * 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 Afanasyev8f25cbb2012-03-01 23:53:40 -080011 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -070012 * 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 Afanasyev8f25cbb2012-03-01 23:53:40 -080015 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -070016 * 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 Yu6f797782014-08-27 12:31:11 -070022 * @author Yingdi Yu <yingdi@cs.ucla.edu>
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080023 */
24
Yingdi Yu6f797782014-08-27 12:31:11 -070025#ifndef CHRONOSYNC_DIFF_STATE_CONTAINER_HPP
26#define CHRONOSYNC_DIFF_STATE_CONTAINER_HPP
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080027
Yingdi Yu6f797782014-08-27 12:31:11 -070028#include "mi-tag.hpp"
29#include "diff-state.hpp"
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080030
31#include <boost/multi_index_container.hpp>
Alexander Afanasyeva5858032012-03-09 15:55:10 -080032#include <boost/multi_index/tag.hpp>
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080033#include <boost/multi_index/hashed_index.hpp>
34#include <boost/multi_index/sequenced_index.hpp>
Alexander Afanasyev3a229132012-04-25 15:07:26 -070035#include <boost/multi_index/member.hpp>
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080036#include <boost/multi_index/mem_fun.hpp>
37
Yingdi Yu6f797782014-08-27 12:31:11 -070038namespace chronosync {
39
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080040namespace mi = boost::multi_index;
41
Yingdi Yu6f797782014-08-27 12:31:11 -070042struct DigestPtrHash
43{
44 std::size_t
Ashlesh Gawande08784d42017-09-06 23:40:21 -050045 operator()(ConstBufferPtr digest) const
Yingdi Yu6f797782014-08-27 12:31:11 -070046 {
47 BOOST_ASSERT(digest->size() > sizeof(std::size_t));
Alexander Afanasyevc1030192012-03-08 22:21:28 -080048
Yingdi Yu6f797782014-08-27 12:31:11 -070049 return *reinterpret_cast<const std::size_t*>(digest->buf());
50 }
51};
52
53struct DigestPtrEqual
54{
55 bool
Ashlesh Gawande08784d42017-09-06 23:40:21 -050056 operator()(ConstBufferPtr digest1, ConstBufferPtr digest2) const
Yingdi Yu6f797782014-08-27 12:31:11 -070057 {
58 return *digest1 == *digest2;
59 }
60};
Alexander Afanasyevc1030192012-03-08 22:21:28 -080061
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080062/**
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080063 * @brief Container for differential states
64 */
Alexander Afanasyevc1030192012-03-08 22:21:28 -080065struct DiffStateContainer : public mi::multi_index_container<
Alexander Afanasyeva5858032012-03-09 15:55:10 -080066 DiffStatePtr,
67 mi::indexed_by<
68 // For fast access to elements using DiffState hashes
69 mi::hashed_unique<
70 mi::tag<hashed>,
Ashlesh Gawande08784d42017-09-06 23:40:21 -050071 mi::const_mem_fun<DiffState, ConstBufferPtr, &DiffState::getRootDigest>,
Alexander Afanasyeve4e2bf72012-03-12 12:44:54 -070072 DigestPtrHash,
73 DigestPtrEqual
Yingdi Yu6f797782014-08-27 12:31:11 -070074 >,
75
Alexander Afanasyeva5858032012-03-09 15:55:10 -080076 // sequenced index to access older/newer element (like in list)
77 mi::sequenced<mi::tag<sequenced> >
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080078 >
Alexander Afanasyeva5858032012-03-09 15:55:10 -080079 >
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080080{
81};
82
Yingdi Yu6f797782014-08-27 12:31:11 -070083} // namespace chronosync
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080084
Yingdi Yu6f797782014-08-27 12:31:11 -070085#endif // CHRONOSYNC_DIFF_STATE_CONTAINER_HPP