20#ifndef TULIP_SORTITERATOR_H
21#define TULIP_SORTITERATOR_H
26#include <tulip/Iterator.h>
27#include <tulip/StableIterator.h>
28#include <tulip/NumericProperty.h>
29#include <tulip/Graph.h>
30#include <tulip/Vector.h>
37 LessThan(
const tlp::NumericProperty *m) : metric(m) {}
38 const tlp::NumericProperty *metric;
39 bool operator()(
const node &n1,
const node &n2)
const {
42 bool operator()(
const edge &e1,
const edge &e2)
const {
47struct LessThanEdgeTargetMetric {
48 LessThanEdgeTargetMetric(
const Graph *sg,
const tlp::NumericProperty *metric)
49 : metric(metric), sg(sg) {}
50 bool operator()(
const edge &e1,
const edge &e2)
const {
56 const tlp::NumericProperty *metric;
60struct LessThanEdgeSourceMetric {
61 LessThanEdgeSourceMetric(
const Graph *sg,
const tlp::NumericProperty *metric)
62 : metric(metric), sg(sg) {}
63 bool operator()(
const edge &e1,
const edge &e2)
const {
69 const tlp::NumericProperty *metric;
73struct LessThanEdgeExtremitiesMetric {
74 LessThanEdgeExtremitiesMetric(
const Graph *sg,
const tlp::NumericProperty *metric)
75 : metric(metric), sg(sg) {}
76 bool operator()(
const edge &e1,
const edge &e2)
const {
77 std::pair<node, node> ends = sg->ends(e1);
85 const tlp::NumericProperty *metric;
96 bool ascendingOrder =
true)
101 if (!ascendingOrder) {
108 ~SortNodeIterator()
override {}
117 bool ascendingOrder =
true)
119 LessThan tmp(metric);
122 if (!ascendingOrder) {
129 ~SortEdgeIterator()
override {}
141 LessThanEdgeTargetMetric tmp(sg, metric);
144 if (!ascendingOrder) {
151 ~SortTargetEdgeIterator()
override {}
163 LessThanEdgeSourceMetric tmp(sg, metric);
166 if (!ascendingOrder) {
173 ~SortSourceEdgeIterator()
override {}
185 LessThanEdgeExtremitiesMetric tmp(sg, metric);
188 if (!ascendingOrder) {
195 ~SortExtremitiesEdgeIterator()
override {}
210template <
typename T,
typename CompareFunction>
214 sort(this->
sequenceCopy.begin(), this->sequenceCopy.end(), compFunc);
238template <
typename T,
typename CompareFunction>
259template <
typename Container,
typename CompareFunction>
260typename std::enable_if<has_const_iterator<Container>::value,
261 SortIterator<typename Container::value_type, CompareFunction>
263 CompareFunction &&compFunc) {
Interface all numerical properties. Property values are always returned as double.
virtual double getEdgeDoubleValue(const edge e) const =0
Returns the value associated with the edge e in this property.
virtual double getNodeDoubleValue(const node n) const =0
Returns the value associated with the node n in this property.
std::enable_if< has_const_iterator< Container >::value, StlIterator< typenameContainer::value_type, typenameContainer::const_iterator > * >::type stlIterator(const Container &stlContainer)
Convenient function for creating a StlIterator from a stl container.
SortIterator< T, CompareFunction > * sortIterator(Iterator< T > *it, CompareFunction &&compFunc)
Convenient function for creating a SortIterator.
Interface for Tulip iterators. Allows basic iteration operations only.
Iterator that wraps an existing one and sorts its iterated elements based on comparison function.
Stores the elements of an iterator and iterates a copy.
StableIterator(Iterator< tlp::node > *inputIterator, size_t nbElements=0, bool deleteIterator=true, bool sortCopy=false)
std::vector< tlp::node >::const_iterator copyIterator
std::vector< tlp::node > sequenceCopy