Commit 7f1a8456 authored by Per Cederqvist's avatar Per Cederqvist

(prot_a_output_text_mapping): New function.

parent c589daf0
/*
* $Id: prot-a-output.c,v 0.31 1998/07/26 17:40:28 ceder Exp $
* $Id: prot-a-output.c,v 0.32 1998/08/05 16:13:28 ceder Exp $
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -29,7 +29,7 @@
*/
static const char *
rcsid = "$Id: prot-a-output.c,v 0.31 1998/07/26 17:40:28 ceder Exp $";
rcsid = "$Id: prot-a-output.c,v 0.32 1998/08/05 16:13:28 ceder Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -923,3 +923,76 @@ prot_a_output_l2g_iterator_as_text_list(Connection *fp,
else
mux_printf(fp, " *");
}
void
prot_a_output_text_mapping(Connection *fp,
Text_mapping *map)
{
Local_text_no lowest;
Local_text_no highest;
Local_text_no zeroes = 0;
Local_text_no nonzeroes = 0;
L2g_iterator iter;
/* Count the number of internal zeroes to determine if we should
use a dense or sparse representation. */
for (l2gi_searchsome(&iter, map->l2g, map->first, 0),
highest = (lowest = iter.lno) - 1;
!iter.search_ended && nonzeroes < map->no_of_texts;
l2gi_next(&iter))
{
zeroes += (iter.lno - highest) - 1;
nonzeroes++;
highest = iter.lno;
}
/* Emit the "later-texts-exists" flag. */
mux_printf(fp, " %d", iter.search_ended ? '0' : '1');
/* Emit the block, either a sparse or a dense one. */
if (nonzeroes == 0)
{
/* Special case: an emtpy array. Use the sparse format so
that we don't have to philosophize about what the lower
limit in the text-list should be. */
mux_printf(fp, " 0 0 *");
}
else if (zeroes >= nonzeroes)
{
/* There are at least as many zeroes as real mappings, so use
a sparse representation. */
mux_printf(fp, " 0 %lu {", (unsigned long)nonzeroes);
for (l2gi_searchsome(&iter, map->l2g, map->first, 0);
!iter.search_ended;
l2gi_next(&iter))
{
mux_printf(fp, " %lu %lu",
(unsigned long)iter.lno,
(unsigned long)iter.tno);
}
mux_printf(fp, " }");
}
else
{
/* Emit a dense block. */
mux_printf(fp, " 1 %lu %lu {",
(unsigned long)lowest,
(unsigned long)(zeroes + nonzeroes));
highest = lowest;
for (l2gi_searchsome(&iter, map->l2g, map->first, 0);
!iter.search_ended;
l2gi_next(&iter))
{
while (highest++ < iter.lno)
mux_printf(fp, " 0");
mux_printf(fp, " %lu", (unsigned long)iter.tno);
}
mux_printf(fp, " }");
}
}
/*
* $Id: prot-a-output.h,v 0.19 1998/07/26 17:39:50 ceder Exp $
* $Id: prot-a-output.h,v 0.20 1998/08/05 16:13:29 ceder Exp $
* Copyright (C) 1991, 1992, 1994, 1995, 1996 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -23,7 +23,7 @@
* Please mail bug reports to bug-lyskom@lysator.liu.se.
*/
/*
* $Id: prot-a-output.h,v 0.19 1998/07/26 17:39:50 ceder Exp $
* $Id: prot-a-output.h,v 0.20 1998/08/05 16:13:29 ceder Exp $
*
*/
extern void
......@@ -210,3 +210,7 @@ prot_a_output_dynamic_session_info_list (Connection *fp,
void
prot_a_output_l2g_iterator_as_text_list(Connection *fp,
L2g_iterator_as_text_list *list);
void
prot_a_output_text_mapping(Connection *fp,
Text_mapping *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