blob: d14e635569130dafea92f31f7c28a9b914d70a37 [file] [log] [blame]
akmhoque66e66182014-02-21 17:56:03 -06001/* -*- 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 Lehman0a7da612014-10-29 14:39:29 -050020 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
akmhoque66e66182014-02-21 17:56:03 -060021 */
22
23#ifndef SYNC_STATE_LEAF_CONTAINER
24#define SYNC_STATE_LEAF_CONTAINER
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
38namespace mi = boost::multi_index;
39
40namespace Sync {
41
42struct 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
51struct 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
60struct 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 Lehman0a7da612014-10-29 14:39:29 -050069/// @cond include_hidden
akmhoque66e66182014-02-21 17:56:03 -060070struct hashed { };
71struct ordered { };
72/// @endcond
73
74/**
75 * \ingroup sync
76 * @brief Container for SYNC leaves
77 */
78struct 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 Lehman0a7da612014-10-29 14:39:29 -050088
akmhoque66e66182014-02-21 17:56:03 -060089 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
101#endif // SYNC_STATE_LEAF_CONTAINER