source: Sophya/trunk/SophyaExt/Blitz/blitz/traversal.h@ 3007

Last change on this file since 3007 was 221, checked in by ansari, 26 years ago

Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99

File size: 3.9 KB
Line 
1/***************************************************************************
2 * blitz/traversal.h Declaration of the TraversalOrder classes
3 *
4 * $Id: traversal.h,v 1.1.1.1 1999-04-09 17:59:02 ansari Exp $
5 *
6 * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * Suggestions: blitz-suggest@cybervision.com
19 * Bugs: blitz-bugs@cybervision.com
20 *
21 * For more information, please see the Blitz++ Home Page:
22 * http://seurat.uwaterloo.ca/blitz/
23 *
24 ***************************************************************************
25 * $Log: not supported by cvs2svn $
26 * Revision 1.2 1998/03/14 00:04:47 tveldhui
27 * 0.2-alpha-05
28 *
29 * Revision 1.1 1997/07/16 14:51:20 tveldhui
30 * Update: Alpha release 0.2 (Arrays)
31 *
32 */
33
34// Fast traversal orders require the ISO/ANSI C++ standard library
35// (particularly set).
36#ifdef BZ_HAVE_STD
37
38#ifndef BZ_TRAVERSAL_H
39#define BZ_TRAVERSAL_H
40
41#ifndef BZ_TINYVEC_H
42 #include <blitz/tinyvec.h>
43#endif
44
45#ifndef BZ_VECTOR_H
46 #include <blitz/vector.h>
47#endif
48
49#include <set>
50
51BZ_NAMESPACE(blitz)
52
53template<int N_dimensions>
54class TraversalOrder {
55
56public:
57 typedef TinyVector<int, N_dimensions> T_coord;
58 typedef Vector<T_coord> T_traversal;
59
60 TraversalOrder()
61 {
62 size_ = 0;
63 }
64
65 TraversalOrder(const T_coord& size, T_traversal& order)
66 : size_(size), order_(order)
67 { }
68
69 TraversalOrder(const T_coord& size)
70 : size_(size)
71 { }
72
73 T_coord operator[](int i) const
74 { return order_[i]; }
75
76 T_coord& operator[](int i)
77 { return order_[i]; }
78
79 int length() const
80 { return order_.length(); }
81
82 bool operator<(const TraversalOrder<N_dimensions>& x) const
83 {
84 for (int i=0; i < N_dimensions; ++i)
85 {
86 if (size_[i] < x.size_[i])
87 return true;
88 else if (size_[i] > x.size_[i])
89 return false;
90 }
91 return false;
92 }
93
94 bool operator==(const TraversalOrder<N_dimensions>& x) const
95 {
96 for (int i=0; i < N_dimensions; ++i)
97 {
98 if (size_[i] != x.size_[i])
99 return false;
100 }
101
102 return true;
103 }
104
105protected:
106 T_traversal order_;
107 T_coord size_;
108};
109
110/*
111 * This specialization is provided to avoid problems with zero-length
112 * vectors.
113 */
114template<>
115class TraversalOrder<0> {
116};
117
118template<int N_dimensions>
119class TraversalOrderCollection {
120public:
121 typedef TraversalOrder<N_dimensions> T_traversal;
122 typedef _bz_typename T_traversal::T_coord T_coord;
123 typedef set<T_traversal> T_set;
124 typedef _bz_typename set<T_traversal>::const_iterator T_iterator;
125
126 const T_traversal* find(const T_coord& size)
127 {
128 T_iterator iter = traversals_.find(T_traversal(size));
129 if (iter != traversals_.end())
130 return &(*iter);
131 return 0;
132 }
133
134 void insert(T_traversal x)
135 {
136 traversals_.insert(x);
137 }
138
139protected:
140 static T_set traversals_;
141};
142
143/*
144 * This specialization is provided to avoid problems with zero-length
145 * vectors.
146 */
147
148template<>
149class TraversalOrderCollection<0> {
150public:
151 typedef int T_traversal;
152 typedef int T_coord;
153 typedef int T_set;
154 typedef int T_iterator;
155
156 const T_traversal* find(const T_coord& size)
157 { return 0; }
158};
159
160BZ_NAMESPACE_END
161
162#include <blitz/traversal.cc>
163
164#endif // BZ_TRAVERSAL_H
165
166#endif // BZ_HAVE_STD
167
Note: See TracBrowser for help on using the repository browser.