Vaucanson  1.4.1
graphcontainer.hh
1 // graphcontainer.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2007, 2008 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 
18 #ifndef VCSN_AUTOMATA_IMPLEMENTATION_BMIG_GRAPHCONTAINER_HH_
19 # define VCSN_AUTOMATA_IMPLEMENTATION_BMIG_GRAPHCONTAINER_HH_
20 
21 # include <vaucanson/misc/hash.hh>
22 # include <vaucanson/automata/implementation/bmig/edge_value.hh>
23 # include <boost/multi_index_container.hpp>
24 # include <boost/multi_index/member.hpp>
25 # include <boost/multi_index/ordered_index.hpp>
26 # include <boost/multi_index/hashed_index.hpp>
27 # include <boost/functional/hash/hash.hpp>
28 # include <boost/multi_index/sequenced_index.hpp>
29 # include <boost/tuple/tuple.hpp>
30 # include <boost/multi_index/composite_key.hpp>
31 
32 namespace vcsn
33 {
34  namespace bmig
35  {
36  using ::boost::multi_index_container;
37  using ::boost::multi_index::hashed_non_unique;
38  using ::boost::multi_index::indexed_by;
39  using ::boost::multi_index::composite_key;
40  using ::boost::multi_index::hashed_non_unique;
41  using ::boost::multi_index::tag;
42  using ::boost::multi_index::member;
43  using ::boost::multi_index::index_iterator;
45  using ::boost::multi_index::project;
46  using ::boost::multi_index::composite_key_hash;
47 
48  /*---------------------------------------------------------\
49  | Declaring the Boost multi_index used to store the graph. |
50  `---------------------------------------------------------*/
51 
52  // Empty structure to name the different keys.
53  struct succ {};
54  struct pred {};
55  struct src {};
56  struct dst {};
57 
58  // Composite key (source, label)
59  template<typename State, typename HLabel, typename EdgeValue>
60  struct SuccessorKey : composite_key <
61  EdgeValue,
62  BOOST_MULTI_INDEX_MEMBER(EdgeValue, State, from_),
63  BOOST_MULTI_INDEX_MEMBER(EdgeValue, HLabel, label_)
64  > {};
65 
66  // Composite key (target, label)
67  template<typename State, typename HLabel, typename EdgeValue>
68  struct PredecessorKey : composite_key <
69  EdgeValue,
70  BOOST_MULTI_INDEX_MEMBER(EdgeValue, State, to_),
71  BOOST_MULTI_INDEX_MEMBER(EdgeValue, HLabel, label_)
72  > {};
73 
74  // Use composite keys in hash tables.
75  template<typename State, typename HLabel, typename EdgeValue>
76  struct SourceAndLabel : public hashed_non_unique <
77  tag<succ>,
78  SuccessorKey<State, HLabel, EdgeValue>,
79  composite_key_hash<
80  vcsn::misc::hash_state_handler,
81  vcsn::misc::hash_label<HLabel>
82  //vcsn::misc::hash_handler<HLabel>
83  >
84  > {};
85 
86  template<typename State, typename HLabel, typename EdgeValue>
87  struct DestinationAndLabel : public hashed_non_unique <
88  tag<pred>,
89  PredecessorKey<State, HLabel, EdgeValue>,
90  composite_key_hash<
91  vcsn::misc::hash_state_handler,
92  vcsn::misc::hash_label<HLabel>
93  //vcsn::misc::hash_handler<HLabel>
94  >
95  > {};
96 
97 
98  // Single key (source)
99  template<typename State, typename EdgeValue>
100  struct Source : public hashed_non_unique <
101  tag<src>,
102  BOOST_MULTI_INDEX_MEMBER(EdgeValue, State, from_),
103  vcsn::misc::hash_state_handler
104  > {};
105 
106 
107  // Single key (target)
108  template<typename State, typename EdgeValue>
109  struct Destination : public hashed_non_unique <
110  tag<dst>,
111  BOOST_MULTI_INDEX_MEMBER(EdgeValue, State, to_),
112  vcsn::misc::hash_state_handler
113  > {};
114 
115 
129  template<typename State, typename HLabel, typename EdgeValue>
131  : public multi_index_container
132  <
133  EdgeValue,
134  indexed_by
135  <
136  SourceAndLabel<State, HLabel, EdgeValue>,
137  DestinationAndLabel<State, HLabel, EdgeValue>,
138  Source<State, EdgeValue>,
139  Destination<State, EdgeValue>
140  >
141  > {};
142 
143  } // bmig
144 } // vcsn
145 
146 #endif // ! VCSN_AUTOMATA_IMPLEMENTATION_BMIG_GRAPHCONTAINER_HH_
147