Implemented mtree uninlining and splitting
This is the first step towards a working mtree, though raises more questions than it resolves.
This commit is contained in:
+18
-17
@@ -2245,7 +2245,7 @@ code = '''
|
||||
&alphas[0 % 26], 1) => 0;
|
||||
lfs_size_t n = 1;
|
||||
for (lfs_size_t i = 1; i < N; i++) {
|
||||
int err = lfsr_btree_split(&lfs, &btree, i-1, NULL, 0,
|
||||
int err = lfsr_btree_split(&lfs, &btree, i-1, LFSR_DATA_NULL,
|
||||
LFSR_TAG_INLINED, 1, &alphas[(i-1) % 26], 1,
|
||||
LFSR_TAG_INLINED, 1, &alphas[(i-0) % 26], 1);
|
||||
// ignore space issues
|
||||
@@ -2330,7 +2330,7 @@ code = '''
|
||||
lfs_size_t id = TEST_PRNG(&prng) % sim_size;
|
||||
|
||||
// split btree
|
||||
int err = lfsr_btree_split(&lfs, &btree, id, NULL, 0,
|
||||
int err = lfsr_btree_split(&lfs, &btree, id, LFSR_DATA_NULL,
|
||||
LFSR_TAG_INLINED, 1, &alphas[i % 26], 1,
|
||||
LFSR_TAG_INLINED, 1, &uppers[i % 26], 1);
|
||||
// ignore space issues
|
||||
@@ -2409,7 +2409,7 @@ code = '''
|
||||
&alphas[0 % 26], 1) => 0;
|
||||
lfs_size_t n = 1;
|
||||
for (lfs_size_t i = 1; i < N; i++) {
|
||||
int err = lfsr_btree_split(&lfs, &btree, (i-1)*W+W-1, NULL, 0,
|
||||
int err = lfsr_btree_split(&lfs, &btree, (i-1)*W+W-1, LFSR_DATA_NULL,
|
||||
LFSR_TAG_INLINED, W, &alphas[(i-1) % 26], 1,
|
||||
LFSR_TAG_INLINED, W, &alphas[(i-0) % 26], 1);
|
||||
// ignore space issues
|
||||
@@ -2508,7 +2508,7 @@ code = '''
|
||||
|
||||
// split btree
|
||||
int err = lfsr_btree_split(&lfs, &btree,
|
||||
weighted_id+sim_weights[id]-1, NULL, 0,
|
||||
weighted_id+sim_weights[id]-1, LFSR_DATA_NULL,
|
||||
LFSR_TAG_INLINED, weight1, &alphas[i % 26], 1,
|
||||
LFSR_TAG_INLINED, weight2, &uppers[i % 26], 1);
|
||||
// ignore space issues
|
||||
@@ -3027,7 +3027,7 @@ code = '''
|
||||
// create a two-entry tree
|
||||
lfsr_btree_t btree = LFSR_BTREE_NULL;
|
||||
lfsr_btree_push(&lfs, &btree, 0, LFSR_TAG_INLINED, 1, "0", 1) => 0;
|
||||
lfsr_btree_split(&lfs, &btree, 0, "aab", 3,
|
||||
lfsr_btree_split(&lfs, &btree, 0, LFSR_DATA_BUF("aab", 3),
|
||||
LFSR_TAG_INLINED, 1, "0", 1,
|
||||
LFSR_TAG_INLINED, 1, "1", 1) => 0;
|
||||
printf("btree: w%d 0x%x.%x\n",
|
||||
@@ -3084,10 +3084,10 @@ code = '''
|
||||
// create a two-entry tree
|
||||
lfsr_btree_t btree = LFSR_BTREE_NULL;
|
||||
lfsr_btree_push(&lfs, &btree, 0, LFSR_TAG_INLINED, 1, "0", 1) => 0;
|
||||
lfsr_btree_split(&lfs, &btree, 0, "aab", 3,
|
||||
lfsr_btree_split(&lfs, &btree, 0, LFSR_DATA_BUF("aab", 3),
|
||||
LFSR_TAG_INLINED, 1, "0", 1,
|
||||
LFSR_TAG_INLINED, 1, "1", 1) => 0;
|
||||
lfsr_btree_split(&lfs, &btree, 1, "aac", 3,
|
||||
lfsr_btree_split(&lfs, &btree, 1, LFSR_DATA_BUF("aac", 3),
|
||||
LFSR_TAG_INLINED, 1, "1", 1,
|
||||
LFSR_TAG_INLINED, 1, "2", 1) => 0;
|
||||
printf("btree: w%d 0x%x.%x\n",
|
||||
@@ -3152,10 +3152,10 @@ code = '''
|
||||
// create a two-entry tree
|
||||
lfsr_btree_t btree = LFSR_BTREE_NULL;
|
||||
lfsr_btree_push(&lfs, &btree, 0, LFSR_TAG_INLINED, 1, "0", 1) => 0;
|
||||
lfsr_btree_split(&lfs, &btree, 0, "aac", 3,
|
||||
lfsr_btree_split(&lfs, &btree, 0, LFSR_DATA_BUF("aac", 3),
|
||||
LFSR_TAG_INLINED, 1, "1", 1,
|
||||
LFSR_TAG_INLINED, 1, "2", 1) => 0;
|
||||
lfsr_btree_split(&lfs, &btree, 0, "aab", 3,
|
||||
lfsr_btree_split(&lfs, &btree, 0, LFSR_DATA_BUF("aab", 3),
|
||||
LFSR_TAG_INLINED, 1, "0", 1,
|
||||
LFSR_TAG_INLINED, 1, "1", 1) => 0;
|
||||
printf("btree: w%d 0x%x.%x\n",
|
||||
@@ -3229,7 +3229,7 @@ code = '''
|
||||
char name[3] = {
|
||||
alphas[(i/26/26) % 26], alphas[(i/26) % 26], alphas[i % 26]
|
||||
};
|
||||
int err = lfsr_btree_split(&lfs, &btree, i-1, name, 3,
|
||||
int err = lfsr_btree_split(&lfs, &btree, i-1, LFSR_DATA_BUF(name, 3),
|
||||
LFSR_TAG_INLINED, 1, &nums[(i-1) % 10], 1,
|
||||
LFSR_TAG_INLINED, 1, &nums[(i-0) % 10], 1);
|
||||
// ignore space issues
|
||||
@@ -3331,7 +3331,7 @@ code = '''
|
||||
}
|
||||
|
||||
// split btree
|
||||
int err = lfsr_btree_split(&lfs, &btree, id, name, 3,
|
||||
int err = lfsr_btree_split(&lfs, &btree, id, LFSR_DATA_BUF(name, 3),
|
||||
LFSR_TAG_INLINED, 1, &nums[i % 10], 1,
|
||||
LFSR_TAG_INLINED, 1, &nums[i % 10], 1);
|
||||
// ignore space issues
|
||||
@@ -3414,7 +3414,8 @@ code = '''
|
||||
char name[3] = {
|
||||
alphas[(i/26/26) % 26], alphas[(i/26) % 26], alphas[i % 26]
|
||||
};
|
||||
int err = lfsr_btree_split(&lfs, &btree, (i-1)*W+W-1, name, 3,
|
||||
int err = lfsr_btree_split(&lfs, &btree,
|
||||
(i-1)*W+W-1, LFSR_DATA_BUF(name, 3),
|
||||
LFSR_TAG_INLINED, W, &nums[(i-1) % 10], 1,
|
||||
LFSR_TAG_INLINED, W, &nums[(i-0) % 10], 1);
|
||||
// ignore space issues
|
||||
@@ -3530,7 +3531,7 @@ code = '''
|
||||
|
||||
// split btree
|
||||
int err = lfsr_btree_split(&lfs, &btree,
|
||||
weighted_id+sim_weights[id]-1, name, 3,
|
||||
weighted_id+sim_weights[id]-1, LFSR_DATA_BUF(name, 3),
|
||||
LFSR_TAG_INLINED, weight1, &nums[i % 10], 1,
|
||||
LFSR_TAG_INLINED, weight2, &nums[i % 10], 1);
|
||||
// ignore space issues
|
||||
@@ -3693,7 +3694,7 @@ code = '''
|
||||
lfsr_data_read(&lfs, split_data, 0, split_buf, 4) => 1;
|
||||
if (split_id > id) {
|
||||
int err = lfsr_btree_split(&lfs, &btree,
|
||||
split_id, sim_names[id+1], 3,
|
||||
split_id, LFSR_DATA_BUF(sim_names[id+1], 3),
|
||||
LFSR_TAG_INLINED, 1, &nums[i % 10], 1,
|
||||
LFSR_TAG_INLINED, 1, split_buf, 1);
|
||||
// ignore space issues
|
||||
@@ -3703,7 +3704,7 @@ code = '''
|
||||
assert(err == 0);
|
||||
} else {
|
||||
int err = lfsr_btree_split(&lfs, &btree,
|
||||
split_id, name, 3,
|
||||
split_id, LFSR_DATA_BUF(name, 3),
|
||||
LFSR_TAG_INLINED, 1, split_buf, 1,
|
||||
LFSR_TAG_INLINED, 1, &nums[i % 10], 1);
|
||||
// ignore space issues
|
||||
@@ -3893,7 +3894,7 @@ code = '''
|
||||
lfsr_data_read(&lfs, split_data, 0, split_buf, 4) => 1;
|
||||
if (split_id > weighted_id+sim_weights[id]-1) {
|
||||
int err = lfsr_btree_split(&lfs, &btree,
|
||||
split_id, sim_names[id+1], 3,
|
||||
split_id, LFSR_DATA_BUF(sim_names[id+1], 3),
|
||||
LFSR_TAG_INLINED, weight, &nums[i % 10], 1,
|
||||
LFSR_TAG_INLINED, split_weight, split_buf, 1);
|
||||
// ignore space issues
|
||||
@@ -3903,7 +3904,7 @@ code = '''
|
||||
assert(err == 0);
|
||||
} else {
|
||||
int err = lfsr_btree_split(&lfs, &btree,
|
||||
split_id, name, 3,
|
||||
split_id, LFSR_DATA_BUF(name, 3),
|
||||
LFSR_TAG_INLINED, split_weight, split_buf, 1,
|
||||
LFSR_TAG_INLINED, weight, &nums[i % 10], 1);
|
||||
// ignore space issues
|
||||
|
||||
+43
-34
@@ -17,7 +17,8 @@ code = '''
|
||||
|
||||
for (lfs_size_t i = 0; i < N; i++) {
|
||||
lfsr_mount(&lfs, cfg) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.supermdir, NULL, 0) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.supermdir, &(lfs_ssize_t){-1},
|
||||
NULL, 0) => 0;
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
}
|
||||
|
||||
@@ -37,42 +38,50 @@ code = '''
|
||||
const char *alphas = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
lfsr_mount(&lfs, cfg) => 0;
|
||||
lfsr_mdir_t mdir = lfs.supermdir;
|
||||
lfs_ssize_t rid = -1;
|
||||
for (lfs_size_t i = 0; i < N; i++) {
|
||||
lfsr_mdir_commit(&lfs, &lfs.supermdir, LFSR_ATTRS(
|
||||
LFSR_ATTR(i, MKREG, +1, &alphas[i % 26], 1))) => 0;
|
||||
rid += 1;
|
||||
lfsr_mdir_commit(&lfs, &mdir, &rid, LFSR_ATTRS(
|
||||
LFSR_ATTR(rid, MKREG, +1, &alphas[i % 26], 1))) => 0;
|
||||
}
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
lfsr_mount(&lfs, cfg) => 0;
|
||||
for (lfs_size_t i = 0; i < N; i++) {
|
||||
uint8_t buffer[4];
|
||||
lfsr_mdir_get(&lfs, &lfs.supermdir, i, LFSR_TAG_REG, buffer, 4) => 1;
|
||||
assert(memcmp(buffer, &alphas[i % 26], 1) == 0);
|
||||
}
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
// TODO
|
||||
// lfsr_mount(&lfs, cfg) => 0;
|
||||
// for (lfs_size_t i = 0; i < N; i++) {
|
||||
// uint8_t buffer[4];
|
||||
// lfsr_mdir_get(&lfs, &lfs.supermdir, i, LFSR_TAG_REG, buffer, 4) => 1;
|
||||
// assert(memcmp(buffer, &alphas[i % 26], 1) == 0);
|
||||
// }
|
||||
// lfsr_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
## try creating many entries, this should trigger a split
|
||||
#[cases.test_mtree_split]
|
||||
#defines.N = 5000
|
||||
#in = 'lfs.c'
|
||||
#code = '''
|
||||
# lfs_t lfs;
|
||||
# lfsr_format(&lfs, cfg) => 0;
|
||||
# const char *alphas = "abcdefghijklmnopqrstuvwxyz";
|
||||
#
|
||||
# lfsr_mount(&lfs, cfg) => 0;
|
||||
# for (lfs_size_t i = 0; i < N; i++) {
|
||||
# lfsr_mdir_commit(&lfs, &lfs.supermdir, LFSR_ATTRS(
|
||||
# LFSR_ATTR(i, MKREG, +1, &alphas[i % 26], 1))) => 0;
|
||||
# }
|
||||
# lfsr_unmount(&lfs) => 0;
|
||||
#
|
||||
# lfsr_mount(&lfs, cfg) => 0;
|
||||
# for (lfs_size_t i = 0; i < N; i++) {
|
||||
# uint8_t buffer[4];
|
||||
# lfsr_mdir_get(&lfs, &lfs.supermdir, i, LFSR_TAG_REG, buffer, 4) => 1;
|
||||
# assert(memcmp(buffer, &alphas[i % 26], 1) == 0);
|
||||
# }
|
||||
# lfsr_unmount(&lfs) => 0;
|
||||
#'''
|
||||
# try creating many entries, this should trigger a split
|
||||
[cases.test_mtree_split]
|
||||
defines.N = 500
|
||||
in = 'lfs.c'
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
lfsr_format(&lfs, cfg) => 0;
|
||||
const char *alphas = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
lfsr_mount(&lfs, cfg) => 0;
|
||||
lfsr_mdir_t mdir = lfs.supermdir;
|
||||
lfs_ssize_t rid = -1;
|
||||
for (lfs_size_t i = 0; i < N; i++) {
|
||||
rid += 1;
|
||||
lfsr_mdir_commit(&lfs, &mdir, &rid, LFSR_ATTRS(
|
||||
LFSR_ATTR(rid, MKREG, +1, &alphas[i % 26], 1))) => 0;
|
||||
}
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// TODO
|
||||
// lfsr_mount(&lfs, cfg) => 0;
|
||||
// for (lfs_size_t i = 0; i < N; i++) {
|
||||
// uint8_t buffer[4];
|
||||
// lfsr_mdir_get(&lfs, &lfs.supermdir, i, LFSR_TAG_REG, buffer, 4) => 1;
|
||||
// assert(memcmp(buffer, &alphas[i % 26], 1) == 0);
|
||||
// }
|
||||
// lfsr_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
@@ -46,7 +46,7 @@ code = '''
|
||||
lfs_ssize_t d = lfsr_mpair_todisk(&lfs,
|
||||
lfsr_mdir_mpair(&lfs.supermdir), buf);
|
||||
assert(d >= 0);
|
||||
lfsr_mdir_commit(&lfs, &lfs.supermdir, LFSR_ATTRS(
|
||||
lfsr_mdir_commit(&lfs, &lfs.supermdir, &(lfs_ssize_t){-1}, LFSR_ATTRS(
|
||||
LFSR_ATTR(-1, SUPERMDIR, 0, buf, d))) => 0;
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user