Skip to content

Commit

Permalink
Pass a reference to insert so it can grow
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Feb 13, 2024
1 parent 98c4deb commit 73d1eb4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 3 additions & 5 deletions dependencies/lmdb/libraries/liblmdb/mdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2884,13 +2884,11 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp)
/* Merge in descending sorted order */
fprintf(stderr, "merge\n");
for (unsigned i = i; i < idl[0]; i++) {
if (mdb_midl_insert(mop, idl[i]) == -3) {
if ((rc = mdb_midl_need(&env->me_pghead, idl[0])) != 0)
goto fail;
mop = env->me_pghead;
}
if ((rc = mdb_midl_insert(&mop, idl[i])) != 0)
goto fail;
//mdb_midl_xmerge(mop, idl);
}
if (mop != env->me_pghead) env->me_pghead = mop;
mop_len = mop[0];
}
if (best_fit_start > 0) {
Expand Down
9 changes: 6 additions & 3 deletions dependencies/lmdb/libraries/liblmdb/midl.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ unsigned mdb_midl_search( MDB_IDL ids, MDB_ID id )
}

/* superseded by append/sort */
int mdb_midl_insert( MDB_IDL ids, MDB_ID id )
int mdb_midl_insert( MDB_IDL* ids_ref, MDB_ID id )
{
MDB_IDL ids = *ids_ref;
unsigned x, i;

x = mdb_midl_search( ids, id );
Expand Down Expand Up @@ -130,8 +131,10 @@ int mdb_midl_insert( MDB_IDL ids, MDB_ID id )
last_id = next_id;
} while(next_id);
if (x == ids[0] || // if it is full
x - i > ids[0] >> 3) // or too many moves. TODO: This threshold should actually be more like the square root of the length
return -3; // request to grow
x - i > ids[0] >> 3) { // or too many moves. TODO: This threshold should actually be more like the square root of the length
// grow the ids (this will replace the reference too)
mdb_midl_need(ids_ref, 1);
}
}

return 0;
Expand Down

0 comments on commit 73d1eb4

Please sign in to comment.