1#ifndef __JTOOLS__JCOLLECTION__
2#define __JTOOLS__JCOLLECTION__
72 template<
class JElement_t,
class JDistance_t = JDistance<
typename JElement_t::abscissa_type> >
76 typename JElement_t::ordinate_type>,
78 public JMath< JCollection<JElement_t, JDistance_t> >
93 typedef typename container_type::iterator
iterator;
114 const JElement_t& second)
const
116 return this->
getDistance(first.getX(), second.getX()) > 0.0;
152 container_type::clear();
166 if (i == this->end() || this->
getDistance(x, i->getX()) > distance_type::precision) {
184 if (i == this->end() || this->
getDistance(x, i->getX()) > distance_type::precision) {
199 return (
int) this->size();
211 return this->at(index).getX();
222 return this->begin()->getX();
233 return this->rbegin()->getX();
246 return this->at(index).getY();
258 return this->at(index).getY();
269 for (
iterator i = this->begin(); i != this->end(); ++i) {
270 *i = transformer(*i);
282 std::sort(this->begin(), this->end(),
compare);
294 return std::lower_bound(this->begin(), this->end(), x,
compare);
306 return std::lower_bound(this->begin(), this->end(), x,
compare);
320 if (i == this->end() || this->
getDistance(element.getX(), i->getX()) > 0.0)
321 return pair_type(container_type::insert(i, element),
true);
349 for (
iterator i = this->begin(); i != this->end(); ++i) {
364 template<
class JFunction1D_t>
366 const JFunction1D_t& function)
368 using namespace JLANG;
372 for (
int i = 0; i != bounds.
getSize(); ++i) {
376 out->
put(x, function(x));
379 if (is_identical(*
this, function)) {
396 if (this->empty() || collection.empty()) {
407 if (
getDistance(p->getX(), q->getX()) > precision) {
411 }
while (p != this->end() &&
getDistance(p->getX(), q->getX()) > precision);
413 }
else if (
getDistance(q->getX(), p->getX()) > precision) {
417 }
while (q != collection.end() && getDistance(q->getX(), p->getX()) > precision);
420 for ( ; p != this->end() && q != collection.end(); ++p, ++q) {
421 if (fabs(
getDistance(p->getX(), q->getX())) > precision) {
454 for (
iterator i = this->begin(); i != this->end(); ++i) {
455 i->getY() = -i->getY();
470 if (!collection.empty()) {
474 for (
const_iterator i = collection.begin(); i != collection.end(); ++i) {
475 this->
put(i->getX(), +i->getY());
485 if (
getDistance(p->getX(), q->getX()) > precision) {
489 }
while (p != this->end() &&
getDistance(p->getX(), q->getX()) > precision);
491 }
else if (
getDistance(q->getX(), p->getX()) > precision) {
495 }
while (q != collection.end() && getDistance(q->getX(), p->getX()) > precision);
500 for ( ; p != this->end() && i != collection.end(); ++p, ++i) {
501 p->getY() += i->getY();
504 for ( ; i != collection.end(); ++i) {
505 this->
put(i->getX(), +i->getY());
508 for (i = collection.begin(); i != q; ++i) {
509 this->
put(i->getX(), +i->getY());
530 if (!collection.empty()) {
534 for (
const_iterator i = collection.begin(); i != collection.end(); ++i) {
535 this->
put(i->getX(), -i->getY());
545 if (
getDistance(p->getX(), q->getX()) > precision) {
549 }
while (p != this->end() &&
getDistance(p->getX(), q->getX()) > precision);
551 }
else if (
getDistance(q->getX(), p->getX()) > precision) {
555 }
while (q != collection.end() && getDistance(q->getX(), p->getX()) > precision);
560 for ( ; p != this->end() && i != collection.end(); ++p, ++i) {
561 p->getY() -= i->getY();
564 for ( ; i != collection.end(); ++i) {
565 this->
put(i->getX(), -i->getY());
568 for (i = collection.begin(); i != q; ++i) {
569 this->
put(i->getX(), -i->getY());
590 for (
iterator i = this->begin(); i != this->end(); ++i) {
606 for (
iterator i = this->begin(); i != this->end(); ++i) {
622 for (
iterator i = this->begin(); i != this->end(); ++i) {
638 for (
iterator i = this->begin(); i != this->end(); ++i) {
652 template<
class JFunction1D_t>
655 for (
iterator i = this->begin(); i != this->end(); ++i) {
656 i->getY() += function(i->getX());
669 template<
class JFunction1D_t>
672 for (
iterator i = this->begin(); i != this->end(); ++i) {
673 i->getY() -= function(i->getX());
689 return collection.add(value);
702 return collection.sub(value);
713 template<
class JFunction1D_t>
716 return collection.add(function);
727 template<
class JFunction1D_t>
730 return collection.sub(function);
747 collection.resize(
n);
767 const int n = collection.size();
808 void resize(
typename container_type::size_type size)
810 container_type::resize(size);
829 template<
class JElement_t,
831 inline typename JElement_t::ordinate_type
834 typedef typename JElement_t::ordinate_type ordinate_type;
839 if (input.getSize() > 1) {
841 output.
put(input.begin()->getX(), V);
843 for (const_iterator
j = input.begin(), i =
j++;
j != input.end(); ++i, ++
j) {
845 V += 0.5 * input.getDistance(i->getX(),
j->getX()) * (i->getY() +
j->getY());
847 output.
put(
j->getX(), V);
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Base class for data structures with artithmetic capabilities.
Definition of zero value for any class.
Interface for binary input.
Interface for binary output.
Exception for accessing a value in a collection that is outside of its range.
Auxiliary classes and methods for language specific functionality.
T getZero()
Get zero value for a given data type.
static const JZero zero
Function object to assign zero value.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Template for generic class types.
JArgument< T >::argument_type argument_type
Auxiliary base class for aritmetic operations of derived class types.