Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
multi-index.h
Go to the documentation of this file.
1
/*
2
* A multi-index is an ordered sequence of unsigned int
3
*
4
* Authors:
5
* Marco Cecchetti <mrcekets at gmail.com>
6
*
7
* Copyright 2008 authors
8
*
9
* This library is free software; you can redistribute it and/or
10
* modify it either under the terms of the GNU Lesser General Public
11
* License version 2.1 as published by the Free Software Foundation
12
* (the "LGPL") or, at your option, under the terms of the Mozilla
13
* Public License Version 1.1 (the "MPL"). If you do not alter this
14
* notice, a recipient may use your version of this file under either
15
* the MPL or the LGPL.
16
*
17
* You should have received a copy of the LGPL along with this library
18
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
* You should have received a copy of the MPL along with this library
21
* in the file COPYING-MPL-1.1
22
*
23
* The contents of this file are subject to the Mozilla Public License
24
* Version 1.1 (the "License"); you may not use this file except in
25
* compliance with the License. You may obtain a copy of the License at
26
* http://www.mozilla.org/MPL/
27
*
28
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
29
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
30
* the specific language governing rights and limitations.
31
*/
32
33
#ifndef _GEOM_SL_MULTI_INDEX_H_
34
#define _GEOM_SL_MULTI_INDEX_H_
35
36
37
#include <
2geom/exception.h
>
38
39
#include <valarray>
40
41
#include <boost/preprocessor/cat.hpp>
42
#include <boost/preprocessor/repetition/enum_params.hpp>
43
#include <boost/preprocessor/repetition/repeat.hpp>
44
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
45
46
47
48
49
/*
50
* an helper macro for generating function with declaration:
51
* multi_index_type make_multi_index (size_t i0, ..., size_t iN)
52
* that is a facility to make up a multi-index from a list of values
53
*/
54
55
#define GEOM_SL_MAX_RANK 10
56
57
#define GEOM_SL_ASSIGN_INDEX(z, k, unused) I[k] = BOOST_PP_CAT(i, k);
58
59
#define GEOM_SL_MAKE_MULTI_INDEX(z, N, unused) \
60
inline \
61
multi_index_type make_multi_index (BOOST_PP_ENUM_PARAMS(N, size_t i)) \
62
{ \
63
multi_index_type I(N); \
64
BOOST_PP_REPEAT(N, GEOM_SL_ASSIGN_INDEX, unused) \
65
return I; \
66
}
67
// end macro GEOM_SL_MAKE_MULTI_INDEX
68
69
70
71
72
namespace
Geom
{
namespace
SL {
73
74
/*
75
* A multi-index is an ordered sequence of unsigned int;
76
* it's useful for representing exponent, degree and coefficient index
77
* of a multi-variate polynomial;
78
* example: given a monomial x_(0)^i_(0)*x_(1)^i_(1)*...*x_(N-1)^i_(N-1)
79
* we can write it in the simpler form X^I where X=(x_(0), .., x_(N-1))
80
* and I=(i_(0), .., i_(N-1)) is a multi-index
81
* A multi-index is represented as a valarray this let us make simple
82
* arithmetic operations on a multi-index
83
*/
84
85
typedef
std::valarray<size_t>
multi_index_type
;
86
87
88
// make up a multi-index of size N and fill it with zeroes
89
inline
90
multi_index_type
multi_index_zero
(
size_t
N
)
91
{
92
return
multi_index_type
(
N
);
93
}
94
95
// helper functions for generating a multi-index from a list of values
96
// we create an amount of GEOM_SL_MAX_RANK of suzh functions
97
BOOST_PP_REPEAT_FROM_TO
(0, GEOM_SL_MAX_RANK, GEOM_SL_MAKE_MULTI_INDEX,
unused
)
98
99
100
// helper function for generating a multi-index of size N
101
// from a single index v that is placed at position i with i in [0,N[
102
template
<
size_t
N>
103
inline
104
multi_index_type
make_multi_index(
size_t
i,
size_t
v
)
105
{
106
if
(!(i <
N
))
107
THROW_RANGEERROR (
"make_multi_index<N> from a single index: "
108
"out of range position"
);
109
multi_index_type
I
(
N
);
110
I
[i] =
v
;
111
return
I
;
112
}
113
114
// transform a N size multi-index in (N-1)-size multi-index
115
// by removing the first index: (i1, i2,...,iN) -> (i2,..,iN)
116
inline
117
multi_index_type
shift
(
multi_index_type
const
&
I
,
size_t
i = 1)
118
{
119
size_t
N
=
I
.size() - i;
120
multi_index_type
J =
I
[std::slice(i,
N
, 1)];
121
return
J;
122
}
123
124
// valarray operator== returns a valarray of bool
125
inline
126
bool
is_equal
(
multi_index_type
const
&
I
,
multi_index_type
const
& J)
127
{
128
if
(
I
.size() != J.size())
return
false
;
129
for
(
size_t
i = 0; i <
I
.size(); ++i)
130
if
(
I
[i] != J[i])
return
false
;
131
return
true
;
132
}
133
134
// extended operator<< for printing a multi-index
135
template
<
typename
char
T>
136
inline
137
std::basic_ostream<charT> &
138
operator<< (std::basic_ostream<charT> & os,
139
const
Geom::SL::multi_index_type
&
I
)
140
{
141
if
(
I
.size() == 0 )
return
os;
142
os <<
"["
<<
I
[0];
143
for
(
unsigned
int
i = 1; i <
I
.size(); ++i)
144
{
145
os <<
", "
<<
I
[i];
146
}
147
os <<
"]"
;
148
return
os;
149
}
150
151
}
/*end namespace Geom*/
}
/*end namespace SL*/
152
153
// argument dependent name lookup doesn't work with typedef
154
using
Geom::SL::operator<<;
155
156
157
#endif
// _GEOM_SL_MULTI_INDEX_
158
159
160
/*
161
Local Variables:
162
mode:c++
163
c-file-style:"stroustrup"
164
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
165
indent-tabs-mode:nil
166
fill-column:99
167
End:
168
*/
169
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
exception.h
Defines the different types of exceptions that 2geom can throw.
Geom::SL::multi_index_type
std::valarray< size_t > multi_index_type
Definition
multi-index.h:85
Geom::SL::shift
multi_index_type shift(multi_index_type const &I, size_t i=1)
Definition
multi-index.h:117
Geom::SL::BOOST_PP_REPEAT_FROM_TO
BOOST_PP_REPEAT_FROM_TO(0, GEOM_SL_MAX_RANK, GEOM_SL_MAKE_MULTI_INDEX, unused) template< size_t N > inline multi_index_type make_multi_index(size_t i
Geom::SL::v
size_t v
Definition
multi-index.h:105
Geom::SL::is_equal
bool is_equal(multi_index_type const &I, multi_index_type const &J)
Definition
multi-index.h:126
Geom::SL::multi_index_zero
multi_index_type multi_index_zero(size_t N)
Definition
multi-index.h:90
Geom::SL::I
I[i]
Definition
multi-index.h:110
Geom
Various utility functions.
Definition
affine.h:22
N
size_t N
Definition
solve-bezier-one-d.cpp:23
unused
std::vector< Texture > unused
Definition
texturecache.cpp:29
src
3rdparty
2geom
include
2geom
symbolic
multi-index.h
Generated on Sun Jul 20 2025 04:01:54 for Inkscape by
1.9.8