Change entry representation to reduce number of entries
This commit is contained in:
@@ -50,16 +50,21 @@ namespace weaselab {
|
|||||||
|
|
||||||
struct Entry {
|
struct Entry {
|
||||||
int64_t insertVersion;
|
int64_t insertVersion;
|
||||||
int param1Len;
|
int keyLen;
|
||||||
int param2Len;
|
// Negative if this key is cleared
|
||||||
|
int valLen;
|
||||||
mutable int refCount;
|
mutable int refCount;
|
||||||
uint32_t priority;
|
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 {
|
const uint8_t *getVal() const {
|
||||||
return (const uint8_t *)(this + 1) + param1Len;
|
return (const uint8_t *)(this + 1) + 1 + keyLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addref() const { ++refCount; }
|
void addref() const { ++refCount; }
|
||||||
@@ -70,18 +75,18 @@ struct Entry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Entry *make(int64_t insertVersion, const uint8_t *param1,
|
static Entry *make(int64_t insertVersion, const uint8_t *key, int keyLen,
|
||||||
int param1Len, const uint8_t *param2, int param2Len,
|
const uint8_t *val, int valLen, bool clearTo) {
|
||||||
VersionedMap::MutationType mutationType) {
|
auto e = (Entry *)malloc(sizeof(Entry) + keyLen + 1 + std::max(valLen, 0));
|
||||||
auto e = (Entry *)malloc(sizeof(Entry) + param1Len + param2Len);
|
|
||||||
e->insertVersion = insertVersion;
|
e->insertVersion = insertVersion;
|
||||||
e->param1Len = param1Len;
|
e->keyLen = keyLen;
|
||||||
e->param2Len = param2Len;
|
e->valLen = valLen;
|
||||||
e->refCount = 1;
|
e->refCount = 1;
|
||||||
e->priority = rand(); // TODO
|
e->priority = rand(); // TODO
|
||||||
e->mutationType = mutationType;
|
e->clearTo = clearTo;
|
||||||
memcpy((uint8_t *)e->getParam1(), param1, param1Len);
|
memcpy((uint8_t *)e->getKey(), key, keyLen);
|
||||||
memcpy((uint8_t *)e->getParam2(), param2, param2Len);
|
((uint8_t *)e->getKey())[keyLen] = 0;
|
||||||
|
memcpy((uint8_t *)e->getVal(), val, std::max(valLen, 0));
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -141,7 +141,7 @@ struct VersionedMap {
|
|||||||
|
|
||||||
/** Map starts with no mutations, with `getOldestVersion()` == `getVersion()`
|
/** Map starts with no mutations, with `getOldestVersion()` == `getVersion()`
|
||||||
* == `version`. */
|
* == `version`. */
|
||||||
VersionedMap(int64_t version);
|
explicit VersionedMap(int64_t version);
|
||||||
|
|
||||||
~VersionedMap();
|
~VersionedMap();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user