On this page:
keyset?
keyset
empty-keyset
keyset-contains?
keyset-index-of
keyset-ref
keyset-size
keyset->list
7.3

7 Keysets

 (require rebellion/keyset) package: rebellion

A keyset is a data structure representing an immutable sorted set of keywords. Keysets can be more efficient than generic sorted set implementations. For example, the keyset constructor is a macro that sorts the keywords at compile-time.

procedure

(keyset? v)  boolean?

  v : any/c
A predicate for keysets.

syntax

(keyset keyword ...)

Constructs a keyset containing each keyword, excluding duplicates. The keywords are sorted by keyword<? at compile-time, when the keyset form is expanded. The expanded code of a keyset form runs in linear time.

Examples:
> (keyset #:banana #:orange #:apple #:grape)

(keyset #:apple #:banana #:grape #:orange)

> (keyset #:orange #:banana #:banana)

(keyset #:banana #:orange)

value

empty-keyset : keyset? = (keyset)

The empty keyset, which contains no keywords.

procedure

(keyset-contains? keys kw)  boolean?

  keys : keyset?
  kw : keyword?
Returns #t if kw is present in keys. This is a constant-time operation.

Examples:
> (define fruits (keyset #:banana #:orange #:apple #:grape))
> (keyset-contains? fruits '#:orange)

#t

> (keyset-contains? fruits '#:walnut)

#f

procedure

(keyset-index-of keys kw)  natural?

  keys : keyset?
  kw : keyword?
Returns the position of kw in keys. This is a constant-time operation.

Examples:
> (define fruits (keyset #:banana #:orange #:apple #:grape))
> (keyset-index-of fruits '#:grape)

2

> (keyset-index-of fruits '#:banana)

1

procedure

(keyset-ref keys pos)  keyword?

  keys : keyset?
  pos : natural?
Returns the keyword at position pos in keys. This is a constant-time operation.

Examples:
> (define fruits (keyset #:banana #:orange #:apple #:grape))
> (keyset-ref fruits 0)

'#:apple

> (keyset-ref fruits 3)

'#:orange

procedure

(keyset-size keys)  natural?

  keys : keyset?
Returns the number of keywords in keys. This is a constant-time operation.

Examples:
> (define fruits (keyset #:banana #:orange #:apple #:grape))
> (keyset-size fruits)

4

procedure

(keyset->list keys)  (listof keyword?)

  keys : keyset?
Converts keys into a plain list of keywords.

Examples:
> (define greek-gods (keyset #:zeus #:hera #:hades #:athena #:poseidon))
> (keyset->list greek-gods)

'(#:athena #:hades #:hera #:poseidon #:zeus)