% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved.
% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk.
\newcommand{\GeneralSparseTableXmpTitle}{GeneralSparseTable}
\newcommand{\GeneralSparseTableXmpNumber}{9.32}
%
% =====================================================================
\begin{page}{GeneralSparseTableXmpPage}{9.32 GeneralSparseTable}
% =====================================================================
\beginscroll

%
%
%
%
%


%
Sometimes when working with tables there is a natural value to use
as the entry in all but a few cases.
The \spadtype{GeneralSparseTable} constructor can be used to provide any
table type with a default value for entries.
See \downlink{`Table'}{TableXmpPage}\ignore{Table} for general information about tables.
\showBlurb{GeneralSparseTable}

Suppose we launched a fund-raising campaign to raise fifty thousand dollars.
To record the contributions, we want a table with strings as keys
(for the names) and integer entries (for the amount).
In a data base of cash contributions, unless someone
has been explicitly entered, it is reasonable to assume they have made
a zero dollar contribution.
\xtc{
This creates a keyed access file with default entry \spad{0}.
}{
\spadpaste{patrons: GeneralSparseTable(String, Integer, KeyedAccessFile(Integer), 0) := table() ; \bound{patrons}}
}
\xtc{
Now \spad{patrons} can be used just as any other table.
Here we record two gifts.
}{
\spadpaste{patrons."Smith" := 10500 \free{patrons}\bound{smith}}
}
\xtc{
}{
\spadpaste{patrons."Jones" := 22000 \free{smith}\bound{jones}}
}
\xtc{
Now let us look up the size of the contributions from Jones and Stingy.
}{
\spadpaste{patrons."Jones"  \free{jones}}
}
\xtc{
}{
\spadpaste{patrons."Stingy" \free{jones}}
}
\xtc{
Have we met our seventy thousand dollar goal?
}{
\spadpaste{reduce(+, entries patrons) \free{jones}}
}
\noOutputXtc{
So the project is cancelled and we can delete the data base:
}{
\spadpaste{)system rm -r kaf*.sdata \free{patrons}}
}
\endscroll
\autobuttons
\end{page}
%
