- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- Class List
- Class Hierarchy
- Class Members

Public Member Functions

# Median< T > Class Template Reference

Search for all occurrences

## Detailed Description

### template<typename T>
class QtConcurrent::Median< T >

Definition at line 62 of file qtconcurrentmedian.h.

`#include <qtconcurrentmedian.h>`

List of all members.

## Public Member Functions
| Median (int _bufferSize)
void | reset ()
void | addValue (T value)
bool | isMedianValid () const
T | median ()

## Constructor & Destructor Documentation

Median | ( | int | _bufferSize | ) | `[inline]`

Definition at line 65 of file qtconcurrentmedian.h.

            : currentMedian(), bufferSize(_bufferSize), currentIndex(0), valid(false), dirty(true)
        {
            values.resize(bufferSize);
        }

## Member Function Documentation

void reset | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 71 of file qtconcurrentmedian.h.

        {
            values.fill(0);
            currentIndex = 0;
            valid = false;
            dirty = true;
        }

void addValue | ( | T | value | ) | `[inline]`

Search for all occurrences

Definition at line 79 of file qtconcurrentmedian.h.

        {
            currentIndex = ((currentIndex + 1) % bufferSize);
            if (valid == false && currentIndex % bufferSize == 0)
                valid = true;

            // Only update the cached median value when we have to, that
            // is when the new value is on then other side of the median
            // compared to the current value at the index.
            const T currentIndexValue = values[currentIndex];
            if ((currentIndexValue > currentMedian && currentMedian > value)
                || (currentMedian > currentIndexValue && value > currentMedian)) {
                dirty = true;
            }

            values[currentIndex] = value;
        }

bool isMedianValid | ( |  | ) | const `[inline]`

Search for all occurrences

Definition at line 97 of file qtconcurrentmedian.h.

        {
            return valid;
        }

T median | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 102 of file qtconcurrentmedian.h.

        {
            if (dirty) {
                dirty = false;
                QVector<T> sorted = values;
                qSort(sorted);
                currentMedian = sorted.at(bufferSize / 2 + 1);
            }
            return currentMedian;
        }

The documentation for this class was generated from the following file:

- QtCore/qtconcurrentmedian.h