stencil-vector-utils
1 Stencil Vector contracts and predicates
stencil-vector-slot?
stencil-vector-bitmask?
stencil-vector-slot-has-slot?
stencil-vector-empty?
2 Stencil Vector Operations
make-stencil-vector
build-stencil-vector
stencil-vector-copy
stencil-vector-insert
stencil-vector-remove
stencil-vector-slot->index
stencil-vector-index->slot
stencil-vector-slot-ref
stencil-vector->list
stencil-vector->vector
3 Stencil Vector Iteration
in-stencil-vector
stencil-vector-for-each
stencil-vector-map!
stencil-vector-map
stencil-vector-fold
8.12

stencil-vector-utils🔗ℹ

 (require stencil-vector-utils)
  package: stencil-vector-utils

Functions to make it more convenient to use the stencil vectors added in Racket 8.6.

Some terminology: index refers to the virtual index used by "stencil-vector-ref" etc. 0 corresponds to the first set bit, 1 to the second, etc. no matter where in the bitmask they are. slot refers to the element associated wtih a given bit position. 0 corresponds to the first bit #b1, 1 to the second bit #b10, and so on, regardless of how many bits are set before it in the mask.

1 Stencil Vector contracts and predicates🔗ℹ

value

stencil-vector-slot? : contract?

 = (integer-in 0 (sub1 (stencil-vector-mask-width)))
Verifies that a value is a valid slot number.

value

stencil-vector-bitmask? : contract?

 = (integer-in 0 (sub1 (expt 2 (stencil-vector-mask-width))))
Verifies that a number is a valid bitmask value.

procedure

(stencil-vector-slot-has-slot? sv slot)  boolean?

  sv : stencil-vector?
  slot : stencil-vector-slot?
Returns #t if a value is associated with the given slot, #f if not.

procedure

(stencil-vector-empty? sv)  boolean?

  sv : stencil-vector?
Returns #t if the stencil vector has a length of 0.

2 Stencil Vector Operations🔗ℹ

procedure

(make-stencil-vector bitmask v)  stencil-vector?

  bitmask : stencil-vector-bitmask?
  v : any/c
Create a new stencil vector using the given bitmask, with every element populated with v.

procedure

(build-stencil-vector bitmask proc)  stencil-vector?

  bitmask : stencil-vector-bitmask?
  proc : (-> exact-nonnegative-integer? any/c)
Create a new stencil vector using the given bitmask, populated by the results of calling proc on each index in turn.

procedure

(stencil-vector-copy sv 
  #:bitmask stencil-vector-bitmask?) 
  stencil-vector?
  sv : stencil-vector?
  stencil-vector-bitmask? : (stencil-vector-mask sv)
Returns a newly allocated copy of the stencil vector. Normally the new one has the same bitmask, but you can specify a new one with the #:bitmask keyword. It is an error if the new bitmask has a different arity than the original.

procedure

(stencil-vector-insert sv slot val)  stencil-vector?

  sv : stencil-vector?
  slot : stencil-vector-slot?
  val : any/c
Returns a new stencil vector with val added at the given slot. If there’s already a value associated with that slot, it’s replaced.

procedure

(stencil-vector-remove sv slot)  stencil-vector?

  sv : stencil-vector?
  slot : stencil-vector-slot?
Returns a new stencil vector with the element at the given slot, if any, removed.

procedure

(stencil-vector-slot->index sv slot)

  (or/c exact-nonnegative-integer? #f)
  sv : stencil-vector?
  slot : stencil-vector-slot?
Returns the index corresponding to the nth slot, or #f if that slot is unused.

Returns the slot corresponding to the nth index, which must be valid.

procedure

(stencil-vector-slot-ref sv slot [default])  any

  sv : stencil-vector?
  slot : stencil-vector-slot?
  default : any/c = (lambda () (error "Index not present: " i))
Returns the value associated with the given slot. If that slot is unused, and default is a procedure, the result of invoking it as a tail call is returned. Otherwise, default is returned.

procedure

(stencil-vector->list sv)  list?

  sv : stencil-vector?
Returns a list of the stencil vector’s elements.

procedure

(stencil-vector->vector sv)  vector?

  sv : stencil-vector?
Returns a normal vector corresponding to the stencil vector.

3 Stencil Vector Iteration🔗ℹ

procedure

(in-stencil-vector sv)  sequence?

  sv : stencil-vector?
Returns a sequence that iterates through the elements of the stencil vector.

procedure

(stencil-vector-for-each proc sv)  void?

  proc : (-> any/c any/c)
  sv : stencil-vector?
Calls proc for each element of the stencil vector in turn.

procedure

(stencil-vector-map! proc sv)  void?

  proc : (-> any/c any/c)
  sv : stencil-vector?
Replaces each element of the stencil vector with the result of calling proc on the old value.

procedure

(stencil-vector-map proc    
  sv    
  [#:bitmask bitmask])  stencil-vector?
  proc : (-> any/c any/c)
  sv : stencil-vector?
  bitmask : stencil-vector-bitmask? = (stencil-vector-mask sv)
Returns a new stencil vector created by applying proc to each element of sv. Normally the new stencil vector has the same bitmask as the original; a new one can be specified with the #:bitmask keyword. It is an error if the new mask has a different arity than the original vector’s.

procedure

(stencil-vector-fold kons knil sv)  any/c

  kons : (-> any/c any/c any/c)
  knil : any/c
  sv : stencil-vector?
Folds the elements of the stencil vector. The first argument to kons is the current element, the second argument is the result of the last call, initially knil for the first element.