RangeSet needs to use uint32 to hold the full range of ledger seqs.

This commit is contained in:
JoelKatz
2012-10-25 01:45:46 -07:00
parent edfcdbe46b
commit 18ba2f0b31
2 changed files with 32 additions and 30 deletions

View File

@@ -8,15 +8,15 @@
SETUP_LOG();
inline int min(int x, int y) { return (x < y) ? x : y; }
inline int max(int x, int y) { return (x > y) ? x : y; }
inline uint32 min(uint32 x, uint32 y) { return (x < y) ? x : y; }
inline uint32 max(uint32 x, uint32 y) { return (x > y) ? x : y; }
bool RangeSet::hasValue(int v) const
bool RangeSet::hasValue(uint32 v) const
{
return mRanges.find(v) != mRanges.end();
}
int RangeSet::getFirst() const
uint32 RangeSet::getFirst() const
{
const_iterator it = begin();
if (it == end())
@@ -24,7 +24,7 @@ int RangeSet::getFirst() const
return lower(it);
}
int RangeSet::getNext(int v) const
uint32 RangeSet::getNext(uint32 v) const
{
for (const_iterator it = begin(); it != end(); ++it)
{
@@ -34,7 +34,7 @@ int RangeSet::getNext(int v) const
return RangeSetAbsent;
}
int RangeSet::getLast() const
uint32 RangeSet::getLast() const
{
const_reverse_iterator it = rbegin();
if (it == rend())
@@ -42,7 +42,7 @@ int RangeSet::getLast() const
return upper(it);
}
int RangeSet::getPrev(int v) const
uint32 RangeSet::getPrev(uint32 v) const
{
for (const_reverse_iterator it = rbegin(); it != rend(); ++it)
{
@@ -52,7 +52,7 @@ int RangeSet::getPrev(int v) const
return RangeSetAbsent;
}
int RangeSet::prevMissing(int v) const
uint32 RangeSet::prevMissing(uint32 v) const
{ // largest number not in the set that is less than the given number
for (const_reverse_iterator it = rbegin(); it != rend(); ++it)
{
@@ -66,24 +66,24 @@ int RangeSet::prevMissing(int v) const
return RangeSetAbsent;
}
void RangeSet::setValue(int v)
void RangeSet::setValue(uint32 v)
{
setRange(v, v);
}
void RangeSet::setRange(int minV, int maxV)
void RangeSet::setRange(uint32 minV, uint32 maxV)
{
mRanges.add(boost::icl::discrete_interval<int>(minV, maxV + 1));
mRanges.add(boost::icl::discrete_interval<uint32>(minV, maxV + 1));
}
void RangeSet::clearValue(int v)
void RangeSet::clearValue(uint32 v)
{
clearRange(v, v);
}
void RangeSet::clearRange(int minV, int maxV)
void RangeSet::clearRange(uint32 minV, uint32 maxV)
{
mRanges.erase(boost::icl::discrete_interval<int>(minV, maxV + 1));
mRanges.erase(boost::icl::discrete_interval<uint32>(minV, maxV + 1));
}
std::string RangeSet::toString() const

View File

@@ -7,17 +7,19 @@
#include <boost/foreach.hpp>
#include <boost/icl/interval_set.hpp>
#include "types.h"
class RangeSet
{
public:
typedef boost::icl::interval_set<int> iRangeSet;
typedef boost::icl::interval_set<uint32> iRangeSet;
typedef iRangeSet::iterator iterator;
typedef iRangeSet::const_iterator const_iterator;
typedef iRangeSet::reverse_iterator reverse_iterator;
typedef iRangeSet::const_reverse_iterator const_reverse_iterator;
static const int RangeSetAbsent = -1;
static const uint32 RangeSetAbsent = static_cast<uint32>(-1);
protected:
@@ -27,18 +29,18 @@ public:
RangeSet() { ; }
bool hasValue(int) const;
int getFirst() const;
int getNext(int) const;
int getLast() const;
int getPrev(int) const;
bool hasValue(uint32) const;
uint32 getFirst() const;
uint32 getNext(uint32) const;
uint32 getLast() const;
uint32 getPrev(uint32) const;
int prevMissing(int) const; // largest number not in the set that is less than the given number
uint32 prevMissing(uint32) const; // largest number not in the set that is less than the given number
void setValue(int);
void setRange(int, int);
void clearValue(int);
void clearRange(int, int);
void setValue(uint32);
void setRange(uint32, uint32);
void clearValue(uint32);
void clearRange(uint32, uint32);
void clear() { mRanges.clear(); }
@@ -53,10 +55,10 @@ public:
const_reverse_iterator rbegin() const { return mRanges.rbegin(); }
const_reverse_iterator rend() const { return mRanges.rend(); }
static int lower(const_iterator& it) { return it->lower(); }
static int upper(const_iterator& it) { return it->upper() - 1; }
static int lower(const_reverse_iterator& it) { return it->lower(); }
static int upper(const_reverse_iterator& it) { return it->upper() - 1; }
static uint32 lower(const_iterator& it) { return it->lower(); }
static uint32 upper(const_iterator& it) { return it->upper() - 1; }
static uint32 lower(const_reverse_iterator& it) { return it->lower(); }
static uint32 upper(const_reverse_iterator& it) { return it->upper() - 1; }
bool operator!=(const RangeSet& r) const { return mRanges != r.mRanges; }