merge when and whenFull
Former-commit-id: 693b209cb42ea357b3cbc4a757730fa2ac001729
This commit is contained in:
parent
d0de1741ed
commit
fa533a5b62
37
src/expire.h
37
src/expire.h
@ -61,7 +61,10 @@ class expireEntry {
|
|||||||
expireEntryFat *m_pfatentry;
|
expireEntryFat *m_pfatentry;
|
||||||
} u;
|
} u;
|
||||||
long long m_when; // LLONG_MIN means this is a fat entry and we should use the pointer
|
long long m_when; // LLONG_MIN means this is a fat entry and we should use the pointer
|
||||||
long long m_whenFull;
|
|
||||||
|
long long FFatMask() const noexcept {
|
||||||
|
return (1LL) << (sizeof(long long)*CHAR_BIT-1);
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
class iter
|
class iter
|
||||||
{
|
{
|
||||||
@ -101,8 +104,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (subkey != nullptr)
|
if (subkey != nullptr)
|
||||||
{
|
{
|
||||||
m_when = INVALID_EXPIRE;
|
m_when = FFatMask() | INVALID_EXPIRE;
|
||||||
m_whenFull = INVALID_EXPIRE;
|
|
||||||
u.m_pfatentry = new (MALLOC_LOCAL) expireEntryFat(key);
|
u.m_pfatentry = new (MALLOC_LOCAL) expireEntryFat(key);
|
||||||
u.m_pfatentry->expireSubKey(subkey, when);
|
u.m_pfatentry->expireSubKey(subkey, when);
|
||||||
}
|
}
|
||||||
@ -110,22 +112,19 @@ public:
|
|||||||
{
|
{
|
||||||
u.m_key = key;
|
u.m_key = key;
|
||||||
m_when = when;
|
m_when = when;
|
||||||
m_whenFull = when;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expireEntry(expireEntryFat *pfatentry)
|
expireEntry(expireEntryFat *pfatentry)
|
||||||
{
|
{
|
||||||
u.m_pfatentry = pfatentry;
|
u.m_pfatentry = pfatentry;
|
||||||
m_when = INVALID_EXPIRE;
|
m_when = FFatMask() | pfatentry->whenFull();
|
||||||
m_whenFull = pfatentry->whenFull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expireEntry(expireEntry &&e)
|
expireEntry(expireEntry &&e)
|
||||||
{
|
{
|
||||||
u.m_key = e.u.m_key;
|
u.m_key = e.u.m_key;
|
||||||
m_when = e.m_when;
|
m_when = e.m_when;
|
||||||
m_whenFull = e.m_whenFull;
|
|
||||||
e.u.m_key = (char*)key(); // we do this so it can still be found in the set
|
e.u.m_key = (char*)key(); // we do this so it can still be found in the set
|
||||||
e.m_when = 0;
|
e.m_when = 0;
|
||||||
}
|
}
|
||||||
@ -144,7 +143,7 @@ public:
|
|||||||
u.m_key = key;
|
u.m_key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool FFat() const noexcept { return m_when == INVALID_EXPIRE; }
|
inline bool FFat() const noexcept { return m_when & FFatMask(); }
|
||||||
expireEntryFat *pfatentry() { assert(FFat()); return u.m_pfatentry; }
|
expireEntryFat *pfatentry() { assert(FFat()); return u.m_pfatentry; }
|
||||||
|
|
||||||
|
|
||||||
@ -172,19 +171,15 @@ public:
|
|||||||
{
|
{
|
||||||
if (FFat())
|
if (FFat())
|
||||||
return u.m_pfatentry->when();
|
return u.m_pfatentry->when();
|
||||||
return m_when;
|
return whenFull();
|
||||||
}
|
}
|
||||||
long long whenFull() const noexcept
|
long long whenFull() const noexcept
|
||||||
{
|
{
|
||||||
return m_whenFull;
|
return (m_when & (~FFatMask())) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(const char *subkey, long long when)
|
void update(const char *subkey, long long when)
|
||||||
{
|
{
|
||||||
if (subkey == nullptr)
|
|
||||||
{
|
|
||||||
m_whenFull = when;
|
|
||||||
}
|
|
||||||
if (!FFat())
|
if (!FFat())
|
||||||
{
|
{
|
||||||
if (subkey == nullptr)
|
if (subkey == nullptr)
|
||||||
@ -197,12 +192,14 @@ public:
|
|||||||
// we have to upgrade to a fat entry
|
// we have to upgrade to a fat entry
|
||||||
long long whenT = m_when;
|
long long whenT = m_when;
|
||||||
sds keyPrimary = u.m_key;
|
sds keyPrimary = u.m_key;
|
||||||
m_when = INVALID_EXPIRE;
|
m_when |= FFatMask();
|
||||||
u.m_pfatentry = new (MALLOC_LOCAL) expireEntryFat(keyPrimary);
|
u.m_pfatentry = new (MALLOC_LOCAL) expireEntryFat(keyPrimary);
|
||||||
u.m_pfatentry->expireSubKey(nullptr, whenT);
|
u.m_pfatentry->expireSubKey(nullptr, whenT);
|
||||||
// at this point we're fat so fall through
|
// at this point we're fat so fall through
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (subkey == nullptr)
|
||||||
|
m_when = when | FFatMask();
|
||||||
u.m_pfatentry->expireSubKey(subkey, when);
|
u.m_pfatentry->expireSubKey(subkey, when);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,13 +222,9 @@ public:
|
|||||||
bool FGetPrimaryExpire(long long *pwhen)
|
bool FGetPrimaryExpire(long long *pwhen)
|
||||||
{
|
{
|
||||||
*pwhen = -1;
|
*pwhen = -1;
|
||||||
for (auto itr : *this)
|
if (this->whenFull() != INVALID_EXPIRE) {
|
||||||
{
|
*pwhen = this->whenFull();
|
||||||
if (itr.subkey() == nullptr)
|
return true;
|
||||||
{
|
|
||||||
*pwhen = itr.when();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user