aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/attribute/postinglist/postinglist_test.cpp
blob: c6b627f97e2abb202bf7a62776b388d83433c5fb (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/vespalib/btree/btreenodeallocator.hpp>
#include <vespa/vespalib/btree/btreenode.hpp>
#include <vespa/vespalib/btree/btreenodestore.hpp>
#include <vespa/vespalib/btree/btreeiterator.hpp>
#include <vespa/vespalib/btree/btreeroot.hpp>
#include <vespa/vespalib/btree/btreestore.hpp>
#include <vespa/vespalib/datastore/datastore.h>
#include <vespa/vespalib/util/rand48.h>
#include <vespa/vespalib/testkit/testapp.h>
#include <set>
#include <map>
#include <cinttypes>

#include <vespa/log/log.h>
LOG_SETUP("postinglist_test");

namespace search {

using vespalib::GenerationHandler;

/*
 * TODO: Make it pass MALLOC_OPTIONS=AJ on freebsd and valgrind on Linux.
 */

class AttributePostingListTest : public vespalib::TestApp
{
private:
    /* Limited STL version for validation of full version */
    using STLPostingList = std::set<uint32_t>;
    using STLValueTree = std::map<int, STLPostingList>;

    class RandomValue
    {
    public:
        uint32_t _docId;
        int _value;
        uint32_t _order;

        RandomValue()
            : _docId(0),
              _value(0u),
              _order(0u)
        {
        }

        RandomValue(uint32_t docId, uint32_t value, uint32_t order)
            : _docId(docId),
              _value(value),
              _order(order)
        {
        }

        bool
        operator<(const RandomValue &rhs) const
        {
            return (_value < rhs._value ||
                    (_value == rhs._value &&
                     (_docId < rhs._docId ||
                      (_docId == rhs._docId &&
                       _order < rhs._order))));
        }

        bool
        operator>(const RandomValue &rhs) const
        {
            return (_value > rhs._value ||
                    (_value == rhs._value &&
                     (_docId > rhs._docId ||
                      (_docId == rhs._docId &&
                       _order > rhs._order))));
        }

        bool
        operator==(const RandomValue &rhs) const
        {
            return (_value == rhs._value &&
                    _docId == rhs._docId &&
                    _order == rhs._order);
        }
    };

    class CompareOrder
    {
    public:
        bool
        operator()(const RandomValue &a, const RandomValue &b)
        {
            return (a._order < b._order ||
                    (a._order == b._order &&
                     (a._value < b._value ||
                      (a._value == b._value &&
                       a._docId < b._docId))));
        }
    };
    std::vector<RandomValue> _randomValues;

public:
    using IntKeyStore = vespalib::datastore::DataStore<int>;
    using AttributePosting = vespalib::btree::BTreeKeyData<uint32_t, vespalib::btree::BTreeNoLeafData>;
    using PostingList = vespalib::btree::BTreeStore<uint32_t,
                              vespalib::btree::BTreeNoLeafData,
                              vespalib::btree::NoAggregated,
                              std::less<uint32_t>,
                              vespalib::btree::BTreeDefaultTraits>;
    using PostingListNodeAllocator = PostingList::NodeAllocatorType;
    using PostingIdx = vespalib::datastore::EntryRef;
    using StoreIndex = vespalib::datastore::EntryRef;

    class IntComp {
    private:
        const IntKeyStore & _store;
        int                 _value;
        int getValue(const StoreIndex & idx) const {
            if (idx.valid()) {
                return _store.getEntry(idx);
            }
            return _value;
        }
    public:
        IntComp(const IntKeyStore & store) : _store(store), _value(0) {}
        IntComp(const IntKeyStore & store, int value) : _store(store), _value(value) {}
        bool operator() (const StoreIndex & lhs, const StoreIndex & rhs) const {
            return getValue(lhs) < getValue(rhs);
        }
    };

    using IntEnumTree = vespalib::btree::BTreeRoot<StoreIndex, PostingIdx,
                             vespalib::btree::NoAggregated,
                             const IntComp &>;
    using IntEnumNodeAllocator = IntEnumTree::NodeAllocatorType;
    using Tree = IntEnumTree;
    using TreeManager = IntEnumNodeAllocator;
    using ValueHandle = IntKeyStore;
    using RandomValuesVector = std::vector<RandomValue>;
private:
    GenerationHandler _handler;
    IntKeyStore *_intKeyStore;
    IntEnumNodeAllocator *_intNodeAlloc;
    IntEnumTree *_intTree;
    PostingList *_intPostings;
    STLValueTree *_stlTree;

    vespalib::Rand48 _randomGenerator;
    uint32_t _generation;

    void
    allocTree();

    void
    freeTree(bool verbose);

    void
    fillRandomValues(unsigned int count,
                     unsigned int mvcount);

    void
    insertRandomValues(Tree &tree,
                       TreeManager &treeMgr,
                       ValueHandle &valueHandle,
                       PostingList &postings,
                       STLValueTree *stlTree,
                       RandomValuesVector &values);

    void
    removeRandomValues(Tree &tree,
                       TreeManager &treeMgr,
                       ValueHandle &valueHandle,
                       PostingList &postings,
                       STLValueTree *stlTree,
                       RandomValuesVector &values);

    void
    lookupRandomValues(Tree &tree,
                       TreeManager &treeMgr,
                       const ValueHandle &valueHandle,
                       PostingList &postings,
                       STLValueTree *stlTree,
                       RandomValuesVector &values);

    void
    sortRandomValues();

    void
    doCompactEnumStore(Tree &tree,
                       TreeManager &treeMgr,
                       ValueHandle &valueHandle);

    void
    doCompactPostingList(Tree &tree,
                         TreeManager &treeMgr,
                         PostingList &postings,
                         PostingListNodeAllocator &postingsAlloc);

    void
    bumpGeneration(Tree &tree,
                   ValueHandle &valueHandle,
                   PostingList &postings,
                   PostingListNodeAllocator &postingsAlloc);

    void
    reclaim_memory(Tree &tree,
                         ValueHandle &valueHandle,
                         PostingList &postings,
                         PostingListNodeAllocator &postingsAlloc);

    static const char *
    frozenName(bool frozen)
    {
        return frozen ? "frozen" : "thawed";
    }
public:
    AttributePostingListTest();
    ~AttributePostingListTest();

    int Main() override;
};

AttributePostingListTest::AttributePostingListTest()
    : vespalib::TestApp(),
      _randomValues(),
      _handler(),
      _intKeyStore(NULL),
      _intNodeAlloc(NULL),
      _intTree(NULL),
      _intPostings(NULL),
      _stlTree(NULL),
      _randomGenerator()
{}
AttributePostingListTest::~AttributePostingListTest() {}

void
AttributePostingListTest::allocTree()
{
    _intKeyStore = new IntKeyStore;
    _intNodeAlloc = new IntEnumNodeAllocator();
    _intTree = new IntEnumTree();
    _intPostings = new PostingList();
    _stlTree = new STLValueTree;
}


void
AttributePostingListTest::freeTree(bool verbose)
{
    (void) verbose;
    LOG(info,
        "freeTree before clear: %" PRIu64 " (%" PRIu64 " held)"
        ", %zu leaves",
        static_cast<uint64_t>(_intNodeAlloc->getMemoryUsage().allocatedBytes()),
        static_cast<uint64_t>(_intNodeAlloc->getMemoryUsage().allocatedBytesOnHold()),
        _intTree->size(*_intNodeAlloc));
    _intTree->clear(*_intNodeAlloc);
    LOG(info,
        "freeTree before unhold: %" PRIu64 " (%" PRIu64 " held)",
        static_cast<uint64_t>(_intNodeAlloc->getMemoryUsage().allocatedBytes()),
        static_cast<uint64_t>(_intNodeAlloc->getMemoryUsage().allocatedBytesOnHold()));
    _intNodeAlloc->freeze();
    _intPostings->freeze();
    _intNodeAlloc->assign_generation(_handler.getCurrentGeneration());
    _intPostings->clearBuilder();
    _intPostings->assign_generation(_handler.getCurrentGeneration());
    _handler.incGeneration();
    _intNodeAlloc->reclaim_memory(_handler.get_oldest_used_generation());
    _intPostings->reclaim_memory(_handler.get_oldest_used_generation());
    LOG(info,
        "freeTree after unhold: %" PRIu64 " (%" PRIu64 " held)",
        static_cast<uint64_t>(_intNodeAlloc->getMemoryUsage().allocatedBytes()),
        static_cast<uint64_t>(_intNodeAlloc->getMemoryUsage().allocatedBytesOnHold()));
    delete _stlTree;
    _stlTree = NULL;
    delete _intTree;
    _intTree = NULL;
    delete _intNodeAlloc;
    _intNodeAlloc = NULL;
    delete _intKeyStore;
    _intKeyStore = NULL;
    delete _intPostings;
    _intPostings = NULL;
}


void
AttributePostingListTest::
fillRandomValues(unsigned int count,
                 unsigned int mvcount)
{
    unsigned int i;
    unsigned int j;
    unsigned int mv;
    unsigned int mvmax;
    unsigned int mvcount2;
    unsigned int mvcount3;

    mvmax = 100;
    mvcount2 = mvcount * (mvmax * (mvmax - 1)) / 2;
    LOG(info,
        "Filling %u+%u random values", count, mvcount2);
    _randomValues.clear();
    _randomValues.reserve(count);
    _randomGenerator.srand48(42);
    for (i = 0; i <count; i++) {
        uint32_t docId = _randomGenerator.lrand48();
        uint32_t val = _randomGenerator.lrand48();
        uint32_t order = _randomGenerator.lrand48();
        _randomValues.push_back(RandomValue(docId, val, order));
    }
    for (mv = 1; mv < mvmax; mv++) {
        for (i = 0; i < mvcount; i++) {
            for (j = 0; j < mv; j++) {
                uint32_t docId = _randomGenerator.lrand48();
                uint32_t val = _randomGenerator.lrand48();
                uint32_t order = _randomGenerator.lrand48();
                _randomValues.push_back(RandomValue(docId, val, order));
            }
        }
    }
    mvcount3 = 0;
    for (mv = 10; mv < 4000; mv = mv * 3)
    {
        mvcount3 += mv * 2;
        for (j = 0; j < mv; j++) {
            uint32_t val = _randomGenerator.lrand48();
            uint32_t docId = _randomGenerator.lrand48();
            uint32_t order = _randomGenerator.lrand48();
            _randomValues.push_back(RandomValue(docId, val, order));
            val = _randomGenerator.lrand48();
            docId = _randomGenerator.lrand48();
            order = _randomGenerator.lrand48();
            _randomValues.push_back(RandomValue(docId, val, order));
        }
    }
    std::sort(_randomValues.begin(),
              _randomValues.end(),
              CompareOrder());

    EXPECT_TRUE(_randomValues.size() == count + mvcount2 + mvcount3);
}


void
AttributePostingListTest::
insertRandomValues(Tree &tree,
                   TreeManager &treeMgr,
                   ValueHandle &valueHandle,
                   PostingList &postings,
                   STLValueTree *stlTree,
                   RandomValuesVector &
                   values)
{
    RandomValuesVector::iterator i;
    RandomValuesVector::iterator ie;

    LOG(info, "insertRandomValues start");
    ie = values.end();
    for (i = values.begin(); i != ie; ++i) {
        Tree::Iterator itr = tree.find(StoreIndex(), treeMgr, IntComp(valueHandle, i->_value));
        if (!itr.valid()) {
#if 0
            if (valueHandle.needResize())
                doCompactEnumStore(tree, treeMgr, valueHandle);
#endif
            StoreIndex idx = valueHandle.addEntry(i->_value);
            if (tree.insert(idx, PostingIdx(), treeMgr, IntComp(valueHandle))) {
                itr = tree.find(idx, treeMgr, IntComp(valueHandle));
            }
        } else {
        }
        ASSERT_TRUE(itr.valid());
        EXPECT_EQUAL(i->_value, valueHandle.getEntry(itr.getKey()));

        /* TODO: Insert docid to postinglist */
        PostingIdx oldIdx = itr.getData();
        PostingIdx newIdx = oldIdx;
        AttributePosting newPosting(i->_docId,
                                    vespalib::btree::BTreeNoLeafData());
        std::vector<AttributePosting> additions;
        std::vector<uint32_t> removals;
        additions.push_back(newPosting);
        postings.apply(newIdx, additions.data(), additions.data() + additions.size(),
                       removals.data(), removals.data() + removals.size());
        std::atomic_thread_fence(std::memory_order_release);
        itr.writeData(newIdx);

        if (stlTree != NULL) {
            STLValueTree::iterator it;
            it = stlTree->find(i->_value);
            if (it == stlTree->end()) {
                std::pair<STLValueTree::iterator,bool> ir =
                    stlTree->insert(std::make_pair(i->_value,
                                    STLPostingList()));
                ASSERT_TRUE(ir.second && ir.first != stlTree->end() &&
                            ir.first->first == i->_value);
                it = ir.first;
            }
            ASSERT_TRUE(it != stlTree->end() && it->first == i->_value);
            it->second.insert(i->_docId);

            if (it->second.empty()) {
                stlTree->erase(it);
                ASSERT_TRUE(!itr.valid());
            } else {
                size_t postingsize;

                ASSERT_TRUE(itr.valid());
                postingsize = postings.size(newIdx);
                ASSERT_TRUE(postingsize > 0 &&
                            postingsize == it->second.size());
                STLPostingList::iterator it3;
                STLPostingList::iterator it3b;
                STLPostingList::iterator it3e;

                PostingList::Iterator it0;

                it3b = it->second.begin();
                it3e = it->second.end();
                it0 = postings.begin(newIdx);
                it3 = it3b;

                while (it3 != it3e) {
                    ASSERT_TRUE(it0.valid());
                    ASSERT_TRUE(*it3 == it0.getKey());
                    ++it3;
                    ++it0;
                }
                ASSERT_TRUE(!it0.valid());
            }
        }
    }
    ASSERT_TRUE(tree.isValid(treeMgr, IntComp(valueHandle)));
    LOG(info, "insertRandomValues done");
}


void
AttributePostingListTest::
removeRandomValues(Tree &tree,
                   TreeManager &treeMgr,
                   ValueHandle &valueHandle,
                   PostingList &postings,
                   STLValueTree *stlTree,
                   RandomValuesVector &values)
{
    RandomValuesVector::iterator i;
    RandomValuesVector::iterator ie;

    LOG(info, "removeRandomValues start");
    ie = values.end();
    for (i = values.begin(); i != ie; ++i) {
        Tree::Iterator itr = tree.find(StoreIndex(), treeMgr, IntComp(valueHandle, i->_value));
        PostingIdx newIdx;
        /*
         * TODO: Remove docid from postinglist, and only remove
         *       value from tree if postinglist is empty
         */
        if (itr.valid()) {
            PostingIdx oldIdx = itr.getData();
            newIdx = oldIdx;
            std::vector<AttributePosting> additions;
            std::vector<uint32_t> removals;
            removals.push_back(i->_docId);
            postings.apply(newIdx, additions.data(), additions.data() + additions.size(),
                           removals.data(), removals.data() + removals.size());
            if (newIdx != oldIdx) {
                std::atomic_thread_fence(std::memory_order_release);
                itr.writeData(newIdx);
            }
            if (!newIdx.valid()) {
                if (tree.remove(StoreIndex(), treeMgr, IntComp(valueHandle, i->_value))) {
                    itr = tree.find(StoreIndex(), treeMgr, IntComp(valueHandle, i->_value));
                }
            }
        }
        if (stlTree != NULL) {
            STLValueTree::iterator it;
            it = stlTree->find(i->_value);
            ASSERT_TRUE(it != stlTree->end() && it->first == i->_value);
            STLPostingList::iterator it2;
            it2 = it->second.find(i->_docId);
            ASSERT_TRUE(it2 != it->second.end() &&
                        *it2 == i->_docId);
            it->second.erase(it2);

            if (it->second.empty()) {
                stlTree->erase(it);
                ASSERT_TRUE(!itr.valid());
            } else {
                size_t postingsize;

                ASSERT_TRUE(itr.valid());
                postingsize = postings.size(newIdx);
                ASSERT_TRUE(postingsize > 0 &&
                            postingsize == it->second.size());
                STLPostingList::iterator it3;
                STLPostingList::iterator it3b;
                STLPostingList::iterator it3e;

                PostingList::Iterator it0;

                it3b = it->second.begin();
                it3e = it->second.end();
                it0 = postings.begin(newIdx);
                it3 = it3b;

                while (it3 != it3e) {
                    ASSERT_TRUE(it0.valid());
                    ASSERT_TRUE(*it3 == it0.getKey());
                    ++it3;
                    ++it0;
                }
                ASSERT_TRUE(!it0.valid());
            }
        }
    }
    ASSERT_TRUE(tree.isValid(treeMgr, IntComp(valueHandle)));
    LOG(info, "removeRandomValues done");
}


void
AttributePostingListTest::
lookupRandomValues(Tree &tree,
                   TreeManager &treeMgr,
                   const ValueHandle &valueHandle,
                   PostingList &postings,
                   STLValueTree *stlTree,
                   RandomValuesVector &values)
{
    RandomValuesVector::iterator i;
    RandomValuesVector::iterator ie;

    LOG(info, "lookupRandomValues start");
    ie = values.end();
    for (i = values.begin(); i != ie; ++i) {
        Tree::Iterator itr = tree.find(StoreIndex(), treeMgr, IntComp(valueHandle, i->_value));
        ASSERT_TRUE(itr.valid() &&
                    valueHandle.getEntry(itr.getKey()) == i->_value);
        if (stlTree != NULL) {
            STLValueTree::iterator it;
            it = stlTree->find(i->_value);
            ASSERT_TRUE(it != stlTree->end() && it->first == i->_value);

            if (it->second.empty()) {
                stlTree->erase(it);
                ASSERT_TRUE(!itr.valid());
            } else {
                size_t postingsize;

                ASSERT_TRUE(itr.valid());
                postingsize = postings.size(itr.getData());
                ASSERT_TRUE(postingsize > 0 &&
                            postingsize == it->second.size());
                STLPostingList::iterator it3;
                STLPostingList::iterator it3b;
                STLPostingList::iterator it3e;

                PostingList::Iterator it0;

                it3b = it->second.begin();
                it3e = it->second.end();
                it0 = postings.begin(itr.getData());
                it3 = it3b;

                while (it3 != it3e) {
                    ASSERT_TRUE(it0.valid());
                    ASSERT_TRUE(*it3 == it0.getKey());
                    ++it3;
                    ++it0;
                }
                ASSERT_TRUE(!it0.valid());
            }
        }
    }
    LOG(info, "lookupRandomValues done");
}


void
AttributePostingListTest::doCompactEnumStore(Tree &tree,
                                             TreeManager &treeMgr,
                                             ValueHandle &valueHandle)
{
    LOG(info,"doCompactEnumStore start");

    Tree::Iterator i = tree.begin(treeMgr);

    std::vector<uint32_t> toHold;
    valueHandle.for_each_active_buffer([&toHold](uint32_t buffer_id, const vespalib::datastore::BufferState &) {
        toHold.push_back(buffer_id);
    });

    valueHandle.switch_primary_buffer(0, 0u);

    for (; i.valid(); ++i)
    {
        StoreIndex ov = i.getKey();
        StoreIndex nv = valueHandle.addEntry(valueHandle.getEntry(ov));

        std::atomic_thread_fence(std::memory_order_release);
        i.writeKey(nv);
    }
    using generation_t = GenerationHandler::generation_t;
    for (std::vector<uint32_t>::const_iterator
             it = toHold.begin(), ite = toHold.end(); it != ite; ++it) {
        valueHandle.holdBuffer(*it);
    }
    generation_t generation = _handler.getCurrentGeneration();
    valueHandle.assign_generation(generation);
    _handler.incGeneration();
    valueHandle.reclaim_memory(_handler.get_oldest_used_generation());

    LOG(info,
        "doCompactEnumStore done");
}


void
AttributePostingListTest::
doCompactPostingList(Tree &tree,
                     TreeManager &treeMgr,
                     PostingList &postings,
                     PostingListNodeAllocator &postingsAlloc)
{
    LOG(info,
        "doCompactPostingList start");

#if 0
    Tree::Iterator i(tree.begin(treeMgr));

    postings.performCompaction(i, capacityNeeded);
#else
    (void) tree;
    (void) treeMgr;
    (void) postings;
    (void) postingsAlloc;
#endif

    LOG(info,
        "doCompactPostingList done");
}


void
AttributePostingListTest::
bumpGeneration(Tree &tree,
               ValueHandle &valueHandle,
               PostingList &postings,
               PostingListNodeAllocator &postingsAlloc)
{
    (void) tree;
    (void) valueHandle;
    postingsAlloc.freeze();
    postingsAlloc.assign_generation(_handler.getCurrentGeneration());
    postings.assign_generation(_handler.getCurrentGeneration());
    _handler.incGeneration();
}

void
AttributePostingListTest::
reclaim_memory(Tree &tree,
                     ValueHandle &valueHandle,
                     PostingList &postings,
                     PostingListNodeAllocator &postingsAlloc)
{
    (void) tree;
    (void) valueHandle;
    postingsAlloc.reclaim_memory(_handler.get_oldest_used_generation());
    postings.reclaim_memory(_handler.get_oldest_used_generation());
}

int
AttributePostingListTest::Main()
{
    TEST_INIT("postinglist_test");

    fillRandomValues(1000, 10);

    allocTree();
    insertRandomValues(*_intTree, *_intNodeAlloc, *_intKeyStore, *_intPostings,
                       _stlTree, _randomValues);
    lookupRandomValues(*_intTree, *_intNodeAlloc, *_intKeyStore, *_intPostings,
                       _stlTree, _randomValues);
    _intNodeAlloc->freeze();
    _intNodeAlloc->assign_generation(_handler.getCurrentGeneration());
    doCompactEnumStore(*_intTree, *_intNodeAlloc, *_intKeyStore);
    removeRandomValues(*_intTree, *_intNodeAlloc, *_intKeyStore, *_intPostings,
                       _stlTree, _randomValues);
    insertRandomValues(*_intTree, *_intNodeAlloc, *_intKeyStore, *_intPostings,
                       _stlTree, _randomValues);
    freeTree(true);

    TEST_DONE();
}

}

TEST_APPHOOK(search::AttributePostingListTest);