Scheme 48 Manual | Contents | In Chapter: Libraries
Previous: Byte vectors | Next: Cells

## Sparse vectors

These are vectors that grow as large as they need to. That is, they can be indexed by arbitrarily large nonnegative integers. The implementation allows for arbitrarily large gaps by arranging the entries in a tree. They are in the structure `sparse-vectors`.

- `(make-sparse-vector) -> sparse-vector`
- `(sparse-vector-ref sparse-vector k) -> value`
- `(sparse-vector-set! sparse-vector k value)`
- `(sparse-vector->list sparse-vector) -> list`

`Make-sparse-vector`, `sparse-vector-ref`, and `sparse-vector-set!` are analogous to `make-vector`, `vector-ref`, and `vector-set!`, except that the indices passed to `sparse-vector-ref` and `sparse-vector-set!` can be arbitrarily large. For indices whose elements have not been set in a sparse vector, `sparse-vector-ref` returns `#f`.

`Sparse-vector->list` is for debugging: It returns a list of the consecutive elements in a sparse vector from 0 to the highest element that has been set. Note that the list will also include all the `#f` elements for the unset elements.

Previous: Byte vectors | Next: Cells