Debian Codegraph @

src/permutation_index.cc

raw
1 /*
2 * This file is part of MUSIC.
3 * Copyright (C) 2008, 2009 INCF
4 *
5 * MUSIC is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * MUSIC is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "music/permutation_index.hh"
19 #include <algorithm>
20 namespace MUSIC {
21
22 PermutationIndex::PermutationIndex (GlobalIndex* indices, int size)
23 {
24 // NOTE: collapse adjacent intervals where possible?
25 for (int i = 0; i < size; ++i)
26 indices_.push_back (IndexInterval (indices[i],
27 indices[i] + 1,
28 indices[i] - i));
29 sort (indices_.begin (), indices_.end ());
30 }
31
32
33 PermutationIndex::PermutationIndex (std::vector<IndexInterval>& indices)
34 : indices_ (indices)
35 {
36 }
37
38
39 IndexMap::iterator
40 PermutationIndex::begin ()
41 {
42 return IndexMap::iterator (new iterator (&indices_.front ()));
43 }
44
45
46 const IndexMap::iterator
47 PermutationIndex::end () const
48 {
49 return IndexMap::iterator (new iterator (&indices_.back () + 1));
50 }
51
52
53 IndexMap*
54 PermutationIndex::copy ()
55 {
56 return new PermutationIndex (indices_);
57 }
58
59 }