Commit 6b77ea96 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(prot_a_output_text_mapping_reverse): New function.

parent 76e00465
/*
* $Id: prot-a-output.c,v 0.69 2003/08/16 17:38:20 ceder Exp $
* $Id: prot-a-output.c,v 0.70 2003/08/22 06:44:57 ceder Exp $
* Copyright (C) 1991-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -1076,7 +1076,7 @@ prot_a_output_text_mapping(Connection *fp,
else
prot_a_output_ul(fp, limit);
/* Emit the "later-texts-exists" flag. */
/* Emit the "more-texts-exists" flag. */
isc_puts(iter.search_ended ? " 0" : " 1", fp->isc_session);
......@@ -1128,6 +1128,101 @@ prot_a_output_text_mapping(Connection *fp,
}
}
void
prot_a_output_text_mapping_reverse(Connection *fp,
Text_mapping_reverse *map)
{
Local_text_no lowest;
Local_text_no zeroes = 0;
Local_text_no nonzeroes = 0;
L2g_iterator iter;
L2g_reverse_iterator riter;
/* Initialize iterators to something. Otherwise some tools will flag
a read uninitialized memory in the for initializer. */
iter.l2g = NULL;
iter.binfo = NULL;
iter.arrindex = 0;
iter.beginval = 0;
iter.endval = 0;
iter.search_ended = 0;
iter.lno = 0;
iter.tno = 0;
riter.l2g = NULL;
riter.binfo = NULL;
riter.arrindex = 0;
riter.beginval = 0;
riter.endval = 0;
riter.search_ended = 0;
riter.lno = 0;
riter.tno = 0;
/* Count the number of internal zeroes to determine if we should
use a dense or sparse representation. */
for (l2gi_searchsome_reverse(&riter, map->l2g, 0, map->ceiling),
lowest = riter.search_ended ? map->ceiling : riter.lno + 1;
!riter.search_ended && nonzeroes < map->no_of_texts;
l2gi_prev(&riter))
{
zeroes += (lowest - riter.lno) - 1;
nonzeroes++;
lowest = riter.lno;
}
prot_a_output_ul(fp, lowest);
prot_a_output_ul(fp, map->ceiling);
/* Emit the "more-texts-exists" flag. */
isc_puts(riter.search_ended ? " 0" : " 1", fp->isc_session);
/* Emit the block, either a sparse or a dense one. */
if (nonzeroes == 0)
{
/* Special case: an empty array. Use the sparse format so
that we don't have to philosophize about what the lower
limit in the text-list should be. */
isc_puts(" 0 0 *", fp->isc_session);
}
else if (zeroes >= nonzeroes)
{
/* There are at least as many zeroes as real mappings, so use
a sparse representation. */
isc_puts(" 0", fp->isc_session);
prot_a_output_ul(fp, nonzeroes);
isc_puts(" {", fp->isc_session);
for (l2gi_searchsome(&iter, map->l2g, lowest, map->ceiling);
!iter.search_ended;
l2gi_next(&iter))
{
prot_a_output_ul(fp, iter.lno);
prot_a_output_ul(fp, iter.tno);
}
isc_puts(" }", fp->isc_session);
}
else
{
/* Emit a dense block. */
isc_puts(" 1", fp->isc_session);
prot_a_output_ul(fp, lowest);
prot_a_output_ul(fp, zeroes + nonzeroes);
isc_puts(" {", fp->isc_session);
for (l2gi_searchsome(&iter, map->l2g, lowest, map->ceiling);
!iter.search_ended;
l2gi_next(&iter))
{
while (lowest++ < iter.lno)
isc_puts(" 0", fp->isc_session);
prot_a_output_ul(fp, iter.tno);
}
isc_puts(" }", fp->isc_session);
}
}
void
prot_a_output_stats_description(Connection *fp,
Stats_description *result)
......
/*
* $Id: prot-a-output.h,v 0.35 2003/08/16 11:28:58 ceder Exp $
* $Id: prot-a-output.h,v 0.36 2003/08/22 06:44:57 ceder Exp $
* Copyright (C) 1991-1992, 1994-1999, 2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -23,7 +23,7 @@
* Please report bugs at http://bugzilla.lysator.liu.se/.
*/
/*
* $Id: prot-a-output.h,v 0.35 2003/08/16 11:28:58 ceder Exp $
* $Id: prot-a-output.h,v 0.36 2003/08/22 06:44:57 ceder Exp $
*
*/
extern void
......@@ -231,6 +231,10 @@ void
prot_a_output_text_mapping(Connection *fp,
Text_mapping *result);
void
prot_a_output_text_mapping_reverse(Connection *fp,
Text_mapping_reverse *map);
void
prot_a_output_stats_description(Connection *fp,
Stats_description *result);
......
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