aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/test/bucketdocuments.h
blob: 3788f6a6897f9ed1185f2108ea9eaf0ad66fd5cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "document.h"
#include <cassert>
#include <algorithm>

namespace proton::test {

/**
 * Collection of documents contained in the same bucket.
 */
class BucketDocuments
{
private:
    DocumentVector _docs;
public:
    BucketDocuments()
        : _docs()
    {
    }
    document::BucketId getBucket() const {
        if (!_docs.empty()) {
            return _docs.back().getBucket();
        }
        return document::BucketId();
    }
    const DocumentVector &getDocs() const { return _docs; }
    DocumentVector getGidOrderDocs() const {
        DocumentVector retval = _docs;
        std::sort(retval.begin(), retval.end(), DocumentGidOrderCmp());
        return retval;
    }
    void addDoc(const Document &doc) {
        if (!_docs.empty()) {
            assert(_docs.back().getBucket() == doc.getBucket());
        }
        _docs.push_back(doc);
    }
};

}