1106 |
19 Feb 08 |
peter |
// $Id$ |
1106 |
19 Feb 08 |
peter |
2 |
|
1106 |
19 Feb 08 |
peter |
3 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2012 Peter Johansson |
1106 |
19 Feb 08 |
peter |
6 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
1106 |
19 Feb 08 |
peter |
8 |
|
1106 |
19 Feb 08 |
peter |
The yat library is free software; you can redistribute it and/or |
1106 |
19 Feb 08 |
peter |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
1106 |
19 Feb 08 |
peter |
License, or (at your option) any later version. |
1106 |
19 Feb 08 |
peter |
13 |
|
1106 |
19 Feb 08 |
peter |
The yat library is distributed in the hope that it will be useful, |
1106 |
19 Feb 08 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1106 |
19 Feb 08 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1106 |
19 Feb 08 |
peter |
General Public License for more details. |
1106 |
19 Feb 08 |
peter |
18 |
|
1106 |
19 Feb 08 |
peter |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
1106 |
19 Feb 08 |
peter |
21 |
*/ |
1106 |
19 Feb 08 |
peter |
22 |
|
2881 |
18 Nov 12 |
peter |
23 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
24 |
|
1106 |
19 Feb 08 |
peter |
25 |
#include "Index.h" |
1106 |
19 Feb 08 |
peter |
26 |
|
1361 |
02 Jul 08 |
peter |
27 |
#include <cassert> |
1361 |
02 Jul 08 |
peter |
28 |
|
1106 |
19 Feb 08 |
peter |
29 |
namespace theplu { |
1106 |
19 Feb 08 |
peter |
30 |
namespace yat { |
4200 |
19 Aug 22 |
peter |
31 |
namespace utility { |
1106 |
19 Feb 08 |
peter |
32 |
|
1106 |
19 Feb 08 |
peter |
33 |
Index::Index(void) |
1106 |
19 Feb 08 |
peter |
34 |
: index_(SmartPtr<const std::vector<size_t> >(new std::vector<size_t>)) |
1106 |
19 Feb 08 |
peter |
35 |
{} |
1106 |
19 Feb 08 |
peter |
36 |
|
1106 |
19 Feb 08 |
peter |
37 |
|
1106 |
19 Feb 08 |
peter |
38 |
Index::Index(size_t n) |
1106 |
19 Feb 08 |
peter |
39 |
{ |
1106 |
19 Feb 08 |
peter |
40 |
std::vector<size_t>* vec = new std::vector<size_t>; |
1106 |
19 Feb 08 |
peter |
41 |
vec->reserve(n); |
1106 |
19 Feb 08 |
peter |
42 |
for (size_t i=0; i<n; ++i) |
1106 |
19 Feb 08 |
peter |
43 |
vec->push_back(i); |
1106 |
19 Feb 08 |
peter |
44 |
index_ = SmartPtr<const std::vector<size_t> >(vec); |
1106 |
19 Feb 08 |
peter |
45 |
} |
1106 |
19 Feb 08 |
peter |
46 |
|
1106 |
19 Feb 08 |
peter |
47 |
|
1106 |
19 Feb 08 |
peter |
48 |
Index::Index(const SmartPtr<const std::vector<size_t> >& sp) |
1106 |
19 Feb 08 |
peter |
49 |
: index_(sp) {} |
1106 |
19 Feb 08 |
peter |
50 |
|
1106 |
19 Feb 08 |
peter |
51 |
|
1134 |
23 Feb 08 |
peter |
52 |
Index::Index(const std::vector<size_t>& vec) |
1134 |
23 Feb 08 |
peter |
53 |
: index_(utility::SmartPtr<const std::vector<size_t> > |
4200 |
19 Aug 22 |
peter |
54 |
(new std::vector<size_t>(vec))) |
1134 |
23 Feb 08 |
peter |
55 |
{} |
1134 |
23 Feb 08 |
peter |
56 |
|
1134 |
23 Feb 08 |
peter |
57 |
|
1106 |
19 Feb 08 |
peter |
58 |
Index::Index(const Index& a, const Index& b) |
1106 |
19 Feb 08 |
peter |
59 |
{ |
1106 |
19 Feb 08 |
peter |
60 |
std::vector<size_t>* vec = new std::vector<size_t>; |
1106 |
19 Feb 08 |
peter |
61 |
vec->reserve(b.size()); |
1361 |
02 Jul 08 |
peter |
62 |
for (size_t i=0; i<b.size(); ++i) { |
1361 |
02 Jul 08 |
peter |
63 |
assert(b[i]<a.size()); |
1106 |
19 Feb 08 |
peter |
64 |
vec->push_back(a[b[i]]); |
1361 |
02 Jul 08 |
peter |
65 |
} |
1106 |
19 Feb 08 |
peter |
66 |
index_ = SmartPtr<const std::vector<size_t> >(vec); |
1106 |
19 Feb 08 |
peter |
67 |
} |
1106 |
19 Feb 08 |
peter |
68 |
|
1106 |
19 Feb 08 |
peter |
69 |
|
1528 |
24 Sep 08 |
peter |
70 |
Index::const_iterator Index::begin(void) const |
1528 |
24 Sep 08 |
peter |
71 |
{ |
1528 |
24 Sep 08 |
peter |
72 |
return index_->begin(); |
1528 |
24 Sep 08 |
peter |
73 |
} |
1528 |
24 Sep 08 |
peter |
74 |
|
1528 |
24 Sep 08 |
peter |
75 |
|
1528 |
24 Sep 08 |
peter |
76 |
Index::const_iterator Index::end(void) const |
1528 |
24 Sep 08 |
peter |
77 |
{ |
1528 |
24 Sep 08 |
peter |
78 |
return index_->end(); |
1528 |
24 Sep 08 |
peter |
79 |
} |
1528 |
24 Sep 08 |
peter |
80 |
|
1528 |
24 Sep 08 |
peter |
81 |
|
1106 |
19 Feb 08 |
peter |
82 |
size_t Index::size(void) const |
1106 |
19 Feb 08 |
peter |
83 |
{ |
1106 |
19 Feb 08 |
peter |
84 |
return index_->size(); |
1106 |
19 Feb 08 |
peter |
85 |
} |
1106 |
19 Feb 08 |
peter |
86 |
|
1106 |
19 Feb 08 |
peter |
87 |
|
1134 |
23 Feb 08 |
peter |
88 |
const std::vector<size_t>& Index::vector(void) const |
1134 |
23 Feb 08 |
peter |
89 |
{ |
1134 |
23 Feb 08 |
peter |
90 |
return *index_; |
1134 |
23 Feb 08 |
peter |
91 |
} |
1134 |
23 Feb 08 |
peter |
92 |
|
1134 |
23 Feb 08 |
peter |
93 |
|
1106 |
19 Feb 08 |
peter |
94 |
const size_t& Index::operator[](size_t i) const |
1106 |
19 Feb 08 |
peter |
95 |
{ |
1106 |
19 Feb 08 |
peter |
96 |
return (*index_)[i]; |
1106 |
19 Feb 08 |
peter |
97 |
} |
1106 |
19 Feb 08 |
peter |
98 |
|
1106 |
19 Feb 08 |
peter |
99 |
}}} // of namespace utility, yat, and theplu |