Section9.30

]>
Book Contents Previous Section 9.29 FullPartialFractionExpansion Next Section 9.31 GroebnerFactorizationPackage Book Index

## 9.30 GeneralSparseTable

Sometimes when working with tables there is a natural value to use as the entry in all but a few cases. The GeneralSparseTable constructor can be used to provide any table type with a default value for entries. See TableXmpPage for general information about tables.

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.

This creates a keyed access file with default entry 0.

patrons: GeneralSparseTable(String, Integer, KeyedAccessFile(Integer), 0) := table() ;
Type: GeneralSparseTable(String,Integer,KeyedAccessFile Integer,0)

Now patrons can be used just as any other table. Here we record two gifts.

patrons."Smith" := 10500

10500

Type: PositiveInteger
patrons."Jones" := 22000

22000

Type: PositiveInteger

Now let us look up the size of the contributions from Jones and Stingy.

patrons."Jones"

22000

Type: PositiveInteger
patrons."Stingy"

0

Type: NonNegativeInteger

Have we met our seventy thousand dollar goal?

reduce(+, entries patrons)

32500

Type: PositiveInteger

So the project is cancelled and we can delete the data base:

)system rm -r kaf*.sdata
Book Contents Previous Section 9.29 FullPartialFractionExpansion Next Section 9.31 GroebnerFactorizationPackage Book Index