Repository: dogecoin/dogecoin
File: src/qt/trafficgraphwidget.h (C/C++)

Code before:

class TrafficGraphWidget : public QWidget
{
    Q_OBJECT

public:
    explicit TrafficGraphWidget(QWidget *parent = 0);
    void setClientModel(ClientModel *model);
    int getGraphRangeMins() const;

protected:
    void paintEvent(QPaintEvent *);

public Q_SLOTS:
    void updateTimespanRates();
    void updateBaseRates();
    void setGraphRangeMins(int mins);
    void clear();

private:
    void paintPath(QPainterPath &path, const QVector<float> &samples, int samplesHead);
    float resampleSamples(const QVector<float> &source, QVector<float> &dest) const;

    float fMax;
    int nMins;

    QVector<float> vTimespanSamplesIn;
    QVector<float> vTimespanSamplesOut;
    quint64 nTimespanLastBytesIn;
    quint64 nTimespanLastBytesOut;
    int64_t nTimespanLastSampleTimeMs;
    int nTimespanHeadIndex;
    QTimer *timespanTimer;

    QVector<float> vBaseSamplesIn;
    QVector<float> vBaseSamplesOut;
    quint64 nBaseLastBytesIn;
    quint64 nBaseLastBytesOut;
    int64_t nBaseLastSampleTimeMs;
    int nBaseSamplesHeadIndex;
    QTimer *baseTimer;

    ClientModel *clientModel;
};

#endif // BITCOIN_QT_TRAFFICGRAPHWIDGET_H

Review comment (suggestion):
This feels like the appropriate spot to add a comment about these vectors. Something like:

```
/*
 * We use these vectors as circle buffers so that we always have a maximum of BASE_SAMPLES_BUF_SIZE entries.
 * The HeadIndex variables keep track of the current position in the circle buffer.
 * When we increment these variables, we check for wraparound so we can continue filling the circle buffers,
 * continually replacing the oldest values.
 */
```

I know when I come back to read this code later, I'll appreciate the explanation here.

Code after:

class TrafficGraphWidget : public QWidget
{
    Q_OBJECT

public:
    explicit TrafficGraphWidget(QWidget *parent = 0);
    void setClientModel(ClientModel *model);
    int getGraphRangeMins() const;

protected:
    void paintEvent(QPaintEvent *);

public Q_SLOTS:
    void updateTimespanRates();
    void updateBaseRates();
    void setGraphRangeMins(int mins);
    void clear();

private:
    void paintPath(QPainterPath &path, const QVector<float> &samples, int samplesHead);
    float resampleSamples(const QVector<float> &source, QVector<float> &dest) const;

    float fMax;
    int nMins;

    /*
    *These QVector<float>s are implemented as circular buffers so that we always have a maximum of 
    *BASE_SAMPLES_BUF_SIZE (defined in trafficgraphwidget.cpp, default of 24 hours * 60 minutes * 60 seconds, 
    *or 86400 samples per day at a samplerate of 1sps) to work with. A second circular "display buffer" is 
    *implemented with a maximum of NUM_DISPLAYED_SAMPLES (defined in trafficgraphwidget.cpp, default of 800) 
    *which are the 'visual samples' which can represent different amounts of time according to the slider. 
    *
    *The "base samples" for a given timespan are resampled into the "displayed samples" (in this case 800) to 
    *redraw and show a history of the selected timespan. When these variables are incremented, we check limits 
    *to see if we need to wrap around and begin overwriting the oldest values in the circular buffers.
    */
    
    QVector<float> vTimespanSamplesIn;
    QVector<float> vTimespanSamplesOut;
    quint64 nTimespanLastBytesIn;
    quint64 nTimespanLastBytesOut;
    int64_t nTimespanLastSampleTimeMs;
    int nTimespanHeadIndex;
    QTimer *timespanTimer;

    QVector<float> vBaseSamplesIn;
    QVector<float> vBaseSamplesOut;
    quint64 nBaseLastBytesIn;
    quint64 nBaseLastBytesOut;
    int64_t nBaseLastSampleTimeMs;