blob: 615d639099c2794b377dda092101096d3627e444 [file] [log] [blame]
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Davide Pesavento07684bc2021-02-07 20:09:28 -05003 * Copyright (c) 2012-2021 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
Davide Pesavento07684bc2021-02-07 20:09:28 -050028#include "detail/mi-tag.hpp"
Yingdi Yu6f797782014-08-27 12:31:11 -070029#include "diff-state.hpp"
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080030
31#include <boost/multi_index_container.hpp>
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080032#include <boost/multi_index/hashed_index.hpp>
33#include <boost/multi_index/sequenced_index.hpp>
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080034#include <boost/multi_index/mem_fun.hpp>
Davide Pesavento07684bc2021-02-07 20:09:28 -050035#include <boost/multi_index/tag.hpp>
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080036
Yingdi Yu6f797782014-08-27 12:31:11 -070037namespace chronosync {
38
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080039namespace mi = boost::multi_index;
40
Yingdi Yu6f797782014-08-27 12:31:11 -070041struct DigestPtrHash
42{
43 std::size_t
Ashlesh Gawande08784d42017-09-06 23:40:21 -050044 operator()(ConstBufferPtr digest) const
Yingdi Yu6f797782014-08-27 12:31:11 -070045 {
46 BOOST_ASSERT(digest->size() > sizeof(std::size_t));
Alexander Afanasyevc1030192012-03-08 22:21:28 -080047
Davide Pesavento5473abe2017-10-09 01:35:33 -040048 return *reinterpret_cast<const std::size_t*>(digest->data());
Yingdi Yu6f797782014-08-27 12:31:11 -070049 }
50};
51
52struct DigestPtrEqual
53{
54 bool
Ashlesh Gawande08784d42017-09-06 23:40:21 -050055 operator()(ConstBufferPtr digest1, ConstBufferPtr digest2) const
Yingdi Yu6f797782014-08-27 12:31:11 -070056 {
57 return *digest1 == *digest2;
58 }
59};
Alexander Afanasyevc1030192012-03-08 22:21:28 -080060
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080061/**
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080062 * @brief Container for differential states
63 */
Alexander Afanasyevc1030192012-03-08 22:21:28 -080064struct DiffStateContainer : public mi::multi_index_container<
Alexander Afanasyeva5858032012-03-09 15:55:10 -080065 DiffStatePtr,
66 mi::indexed_by<
67 // For fast access to elements using DiffState hashes
68 mi::hashed_unique<
69 mi::tag<hashed>,
Ashlesh Gawande08784d42017-09-06 23:40:21 -050070 mi::const_mem_fun<DiffState, ConstBufferPtr, &DiffState::getRootDigest>,
Alexander Afanasyeve4e2bf72012-03-12 12:44:54 -070071 DigestPtrHash,
72 DigestPtrEqual
Yingdi Yu6f797782014-08-27 12:31:11 -070073 >,
Alexander Afanasyeva5858032012-03-09 15:55:10 -080074 // sequenced index to access older/newer element (like in list)
Davide Pesavento07684bc2021-02-07 20:09:28 -050075 mi::sequenced<mi::tag<sequenced>>
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080076 >
Alexander Afanasyeva5858032012-03-09 15:55:10 -080077 >
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080078{
79};
80
Yingdi Yu6f797782014-08-27 12:31:11 -070081} // namespace chronosync
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080082
Yingdi Yu6f797782014-08-27 12:31:11 -070083#endif // CHRONOSYNC_DIFF_STATE_CONTAINER_HPP