]>
Book Contents Previous Section 9.72 SingleInteger Next Section 9.74 SquareMatrix Book Index

## 9.73 SparseTable

The SparseTable domain provides a general purpose table type with default entries.

Here we create a table to save strings under integer keys. The value "Try again!" is returned if no other value has been stored for a key.

t: SparseTable(Integer, String, "Try again!") := table()

table()

Type: SparseTable(Integer,String,Try again!)

Entries can be stored in the table.

t.3 := "Number three"

"Numberthree"

Type: String
t.4 := "Number four"

"Numberfour"

Type: String

These values can be retrieved as usual, but if a look up fails the default entry will be returned.

t.3

"Numberthree"

Type: String
t.2

"Tryagain!"

Type: String

To see which values are explicitly stored, the keys keys SparseTable and entries entries SparseTable functions can be used.

keys t

[4,3]

Type: List Integer
entries t

["Numberfour","Numberthree"]

Type: List String

If a specific table representation is required, the GeneralSparseTable constructor should be used. The domain SparseTable(K, E, dflt) is equivalent to GeneralSparseTable(K,E,Table(K,E), dflt). For more information, see TableXmpPage and GeneralSparseTableXmpPage .

Book Contents Previous Section 9.72 SingleInteger Next Section 9.74 SquareMatrix Book Index