Change entry representation to reduce number of entries
This commit is contained in:
@@ -50,16 +50,21 @@ namespace weaselab {
|
||||
|
||||
struct Entry {
|
||||
int64_t insertVersion;
|
||||
int param1Len;
|
||||
int param2Len;
|
||||
int keyLen;
|
||||
// Negative if this key is cleared
|
||||
int valLen;
|
||||
mutable int refCount;
|
||||
uint32_t priority;
|
||||
VersionedMap::MutationType mutationType;
|
||||
// True if mutations in (pred, this) are cleared. If false, (pred, this)
|
||||
// should be read through to the underlying data structure.
|
||||
bool clearTo;
|
||||
|
||||
const uint8_t *getParam1() const { return (const uint8_t *)(this + 1); }
|
||||
// There's an extra zero byte past the end of getKey, used for
|
||||
// reconstructing logical mutations without copies.
|
||||
const uint8_t *getKey() const { return (const uint8_t *)(this + 1); }
|
||||
|
||||
const uint8_t *getParam2() const {
|
||||
return (const uint8_t *)(this + 1) + param1Len;
|
||||
const uint8_t *getVal() const {
|
||||
return (const uint8_t *)(this + 1) + 1 + keyLen;
|
||||
}
|
||||
|
||||
void addref() const { ++refCount; }
|
||||
@@ -70,18 +75,18 @@ struct Entry {
|
||||
}
|
||||
}
|
||||
|
||||
static Entry *make(int64_t insertVersion, const uint8_t *param1,
|
||||
int param1Len, const uint8_t *param2, int param2Len,
|
||||
VersionedMap::MutationType mutationType) {
|
||||
auto e = (Entry *)malloc(sizeof(Entry) + param1Len + param2Len);
|
||||
static Entry *make(int64_t insertVersion, const uint8_t *key, int keyLen,
|
||||
const uint8_t *val, int valLen, bool clearTo) {
|
||||
auto e = (Entry *)malloc(sizeof(Entry) + keyLen + 1 + std::max(valLen, 0));
|
||||
e->insertVersion = insertVersion;
|
||||
e->param1Len = param1Len;
|
||||
e->param2Len = param2Len;
|
||||
e->keyLen = keyLen;
|
||||
e->valLen = valLen;
|
||||
e->refCount = 1;
|
||||
e->priority = rand(); // TODO
|
||||
e->mutationType = mutationType;
|
||||
memcpy((uint8_t *)e->getParam1(), param1, param1Len);
|
||||
memcpy((uint8_t *)e->getParam2(), param2, param2Len);
|
||||
e->clearTo = clearTo;
|
||||
memcpy((uint8_t *)e->getKey(), key, keyLen);
|
||||
((uint8_t *)e->getKey())[keyLen] = 0;
|
||||
memcpy((uint8_t *)e->getVal(), val, std::max(valLen, 0));
|
||||
return e;
|
||||
}
|
||||
};
|
||||
|
@@ -141,7 +141,7 @@ struct VersionedMap {
|
||||
|
||||
/** Map starts with no mutations, with `getOldestVersion()` == `getVersion()`
|
||||
* == `version`. */
|
||||
VersionedMap(int64_t version);
|
||||
explicit VersionedMap(int64_t version);
|
||||
|
||||
~VersionedMap();
|
||||
|
||||
|
Reference in New Issue
Block a user