Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Seitosh
Seitosh
Commits
79e13340
Commit
79e13340
authored
Feb 06, 2019
by
thomas.forbriger
Browse files
croposp [WP]: provide class Pairs
parent
1d458d97
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/ts/croposp/croposp.h
View file @
79e13340
...
...
@@ -66,9 +66,18 @@ namespace croposp {
psd
::
TDseries
series
;
};
// struct NamedSeries
// a struct to hold computation results cross PSD
struct
NamedCPSD
{
std
::
string
label
;
psd
::
TDCseries
series
;
};
// struct NamedCPSD
// a vector type to hold results
typedef
std
::
vector
<
NamedSeries
>
TNamedSeriesVector
;
// a vector type to hold results
typedef
std
::
vector
<
NamedCPSD
>
TNamedCPSDVector
;
/* ====================================================================== */
/* classes
* -------
...
...
@@ -81,6 +90,14 @@ namespace croposp {
class
Pairs
{
public:
Pairs
(
const
unsigned
int
&
n
);
unsigned
int
operator
()(
const
unsigned
int
&
k
,
const
unsigned
int
&
l
)
const
;
bool
swap
(
const
unsigned
int
&
k
,
const
unsigned
int
&
l
)
const
;
unsigned
int
size
()
const
;
unsigned
int
pairs
()
const
;
private:
unsigned
int
Mn
;
};
// class Pairs
/* ---------------------------------------------------------------------- */
...
...
src/ts/croposp/pairs.cc
View file @
79e13340
...
...
@@ -34,9 +34,72 @@
"TF_PAIRS_CC V1.0"
#include "croposp.h"
#include<tfxx/error.h>
namespace
croposp
{
/*! \class croposp::Pairs
*
* Handle pairs of data.
*
* The constructor takes the size of the collection.
* Index values must be positive (zero or larger than zero) and smaller than
* the size of the collection.
*/
Pairs
::
Pairs
(
const
unsigned
int
&
n
)
:
Mn
(
n
)
{
TFXX_assert
(
this
->
Mn
>
1
,
"collection must have at least two elements to make a pair"
);
}
/* ---------------------------------------------------------------------- */
unsigned
int
Pairs
::
operator
()(
const
unsigned
int
&
k
,
const
unsigned
int
&
l
)
const
{
unsigned
int
retval
=
0
;
TFXX_assert
(
k
!=
l
,
"index values must not equal"
);
if
(
this
->
swap
(
k
,
l
))
{
TFXX_assert
(
l
<
this
->
Mn
,
"index value too large"
);
TFXX_assert
(
k
>=
0
,
"index value too small"
);
retval
=
l
*
(
l
-
1
)
/
2
+
k
;
}
else
{
TFXX_assert
(
k
<
this
->
Mn
,
"index value too large"
);
TFXX_assert
(
l
>=
0
,
"index value too small"
);
retval
=
k
*
(
k
-
1
)
/
2
+
l
;
}
return
(
retval
);
}
// unsigned int Pairs::operator(const unsigned int& k,
// const unsigned int& l) const
/* ---------------------------------------------------------------------- */
bool
Pairs
::
swap
(
const
unsigned
int
&
k
,
const
unsigned
int
&
l
)
const
{
return
(
k
<=
l
);
}
// bool Pairs::swap(const unsigned int& k,
// const unsigned int& l) const
/* ---------------------------------------------------------------------- */
unsigned
int
Pairs
::
size
()
const
{
return
(
this
->
Mn
);
}
// unsigned int Pairs::size() const
/* ---------------------------------------------------------------------- */
unsigned
int
Pairs
::
pairs
()
const
{
unsigned
int
retval
=
this
->
Mn
*
(
this
->
Mn
)
/
2
;
return
(
retval
);
}
// unsigned int Pairs::size() const
}
// namespace croposp
/* ----- END OF pairs.cc ----- */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment