Commit bbc40c2d authored by Per Cederqvist's avatar Per Cederqvist

(l2g_expensive_set): New function, not yet completely implemented.

parent 9f307ce6
......@@ -708,6 +708,117 @@ l2g_append(Local_to_global *l2g,
binfo->zeroes--;
}
#if 0 /* Not yet completely implemented. */
void
l2g_expensive_set(Local_to_global *l2g,
Local_text_no lno,
Text_no tno)
{
struct l2g_block_info * binfo;
Local_text_no_iter ix;
if (lno >= l2g->first_unused)
{
l2g_append(l2g, lno, tno);
return;
}
if (tno == 0)
{
l2g_delete(l2g, lno);
return;
}
binfo = find_block(l2g, lno);
if (binfo == NULL)
{
/* Append a new block. */
FIXME;
}
else if (lno < binfo->start)
{
assert(binfo == l2g->blocks);
/* Prepend a new block. */
FIXME;
}
else if (is_dense(binfo))
{
assert(binfo->start <= lno);
if (lno < binfo->start + L2G_BLOCKSIZE)
{
while (binfo->start + binfo->first_free <= lno)
binfo->value_block[binfo->first_free++] = 0;
assert(lno < binfo->start + binfo->first_free);
assert(binfo->first_free < L2G_BLOCKSIZE);
if (binfo->value_block[lno - binfo->start] == 0)
binfo->zeroes--;
binfo->value_block[lno - binfo->start] = tno;
}
else
{
/* There is no room within this block. Insert a new block
after binfo. */
FIXME;
}
}
else
{
ix = sparse_locate_value(binfo, lno);
if (ix < binfo->first_free && binfo->key_block[ix] == lno)
{
assert(binfo->value_block[ix] != 0);
binfo->value_block[ix] = tno;
}
else
{
if (binfo->zeroes == 0)
{
/* Split the block to make room. */
FIXME; /* IF lno > [the greatest value in the
block] THEN create a new empty
block and let binfo point to it
ELSE move the final lno into the
new block and let binfo point to
the old block, that now contains an
empty slot ENDIF. The ordo for
this is not good when we do many
worst-case insertions, but that is
alright, since this function is
only used for disaster recovery. */
assert(binfo->zeroes == 1 || binfo->first_free == 0);
}
else
sparse_compact(binfo);
/* There is room for a new mapping in this block. */
for (ix = binfo->first_free; ix > 0; --ix)
{
assert(binfo->key_block[ix-1] != lno);
if (binfo->key_block[ix-1] > lno)
{
binfo->key_block[ix] = binfo->key_block[ix-1];
binfo->value_block[ix] = binfo->value_block[ix-1];
}
else
break;
}
assert(ix == 0 || binfo->key_block[ix-1] < lno);
assert(ix == binfo->first_free || binfo->key_block[ix+1] > lno);
binfo->key_block[ix] = lno;
binfo->value_block[ix] = tno;
binfo->first_free++;
binfo->zeroes--;
}
}
}
#endif
/*
* Delete the local text LNO from the structure L2G.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment