// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "bucketvector.h" #include #include #include namespace BucketVector{ typedef document::BucketId::Type BidType; std::vector v; uint64_t countBitsMask = 0x03FFFFFFFFFFFFFF; void reserve(size_t n) { v.reserve(n); } void clear() { v.clear(); } void addBucket(uint64_t bucket) { BidType b = document::BucketId::bucketIdToKey(bucket & countBitsMask); v.push_back(b); } inline uint32_t getMax(uint32_t a, uint32_t b, uint32_t c){ if(a > b){ return (a>c)?a:c; } return (b>c)?b:c; } inline uint64_t getCountBitsMask(uint32_t countBits) { uint64_t shift = 8 * sizeof(BidType) - countBits; uint64_t mask = std::numeric_limits::max() << shift; mask = mask >> shift; return mask; } inline uint32_t getLSBdiff(BidType a, BidType b) { uint64_t mask = 0x0000000000000001; uint32_t c = 1; while((a&mask) == (b&mask)){ c++; mask <<= 1; } return c; } void getBuckets(uint32_t distributionBits, std::vector& buckets){ if(v.size() == 0){ return; } std::sort(v.begin(), v.end()); uint32_t prevMSB = 1; //number of common MSB bits between current and previous bucket uint32_t nextMSB; //number of common MSB bits between current and next bucket size_t i=0; for(; i