blitz Version 1.0.2
Loading...
Searching...
No Matches
traversal.h
Go to the documentation of this file.
1// -*- C++ -*-
2/***************************************************************************
3 * blitz/traversal.h Declaration of the TraversalOrder classes
4 *
5 * $Id$
6 *
7 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
8 *
9 * This file is a part of Blitz.
10 *
11 * Blitz is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation, either version 3
14 * of the License, or (at your option) any later version.
15 *
16 * Blitz is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
23 *
24 * Suggestions: blitz-devel@lists.sourceforge.net
25 * Bugs: blitz-support@lists.sourceforge.net
26 *
27 * For more information, please see the Blitz++ Home Page:
28 * https://sourceforge.net/projects/blitz/
29 *
30 ***************************************************************************/
31
32// Fast traversal orders require the ISO/ANSI C++ standard library
33// (particularly set).
34#ifdef BZ_HAVE_STD
35
36#ifndef BZ_TRAVERSAL_H
37#define BZ_TRAVERSAL_H
38
39#include <blitz/vector2.h>
40
41#include <set>
42
43namespace blitz {
44
45template<int N_dimensions>
46class TraversalOrder {
47
48public:
51
53 {
54 size_ = 0;
55 }
56
58 : size_(size), order_(order)
59 { }
60
61 TraversalOrder(const T_coord& size)
62 : size_(size)
63 { }
64
65 T_coord operator[](int i) const
66 { return order_[i]; }
67
68 T_coord& operator[](int i)
69 { return order_[i]; }
70
71 int length() const
72 { return order_.length(); }
73
75 {
76 for (int i=0; i < N_dimensions; ++i)
77 {
78 if (size_[i] < x.size_[i])
79 return true;
80 else if (size_[i] > x.size_[i])
81 return false;
82 }
83 return false;
84 }
85
87 {
88 for (int i=0; i < N_dimensions; ++i)
89 {
90 if (size_[i] != x.size_[i])
91 return false;
92 }
93
94 return true;
95 }
96
97protected:
100};
101
102/*
103 * This specialization is provided to avoid problems with zero-length
104 * vectors.
105 */
106template<>
107class TraversalOrder<0> {
108public:
109 TraversalOrder () {} // AJS
110};
111
112template<int N_dimensions>
113class TraversalOrderCollection {
114public:
116 typedef _bz_typename T_traversal::T_coord T_coord;
117 typedef set<T_traversal> T_set;
118 typedef _bz_typename set<T_traversal>::const_iterator T_iterator;
119
120 const T_traversal* find(const T_coord& size)
121 {
122 T_iterator iter = traversals_.find(T_traversal(size));
123 if (iter != traversals_.end())
124 return &(*iter);
125 return 0;
126 }
127
128 void insert(T_traversal x)
129 {
130 traversals_.insert(x);
131 }
132
133protected:
134 static T_set traversals_;
135};
136
137template<int N_dimensions>
138_bz_typename TraversalOrderCollection<N_dimensions>::T_set
139 TraversalOrderCollection<N_dimensions>::traversals_;
140
141/*
142 * This specialization is provided to avoid problems with zero-length
143 * vectors.
144 */
145
146template<>
147class TraversalOrderCollection<0> {
148public:
149 typedef int T_traversal;
150 typedef int T_coord;
151 typedef int T_set;
152 typedef int T_iterator;
153
154 const T_traversal* find(const T_coord& size)
155 { return 0; }
156};
157
158}
159
160#include <blitz/traversal.cc>
161
162#endif // BZ_TRAVERSAL_H
163
164#endif // BZ_HAVE_STD
165
MemoryBlockReference()
Definition memblock.h:367
#define _bz_typename
Definition compiler.h:80
_bz_global blitz::IndexPlaceholder< 0 > i
Definition indexexpr.h:256
Definition array-impl.h:66
void find(Array< TinyVector< int, N_rank >, 1 > &, const Array< P_numtype, N_rank > &)
Definition array-impl.h:2537