Next: , Up: dynamic arrays   [Index]


40.1 Dynamic-Arrays objects

Dynamic arrays are implemented as built–in vector objects of which only a subrange of slots is used:

  left span       used slots     right span
|...........|...................|...........|

|---|---|---|+++|+++|+++|+++|+++|---|---|---| vector
              0   1   2   3   4

when a new object is inserted: if there is room at the beginning or end of the vector, that room is consumed. Indexing in dynamic arrays is zero–based, with index ‘0’ referencing the first used slot.

The following syntactic bindings are exported by the library (vicare containers dynamic-arrays).

R6RS Record Type: <dynamic-array>

Record type representing a dynamic-arrays object. The <dynamic-array> type is non–generative and available for subtyping. In this documentation <dynamic-array> objects used as arguments to functions are indicated as arry.

Function: make-dynamic-array
Function: make-dynamic-array full-length left-span

Build and return a new <dynamic-array> object.

The optional argument full-length must be a non–negative fixnum representing the number of slots in the internal vector object; when not used, it defaults to ‘15’. The optional argument left-span must be a non–negative fixnum representing the number of slots to initially leave unused at the left; when not used, it defaults to ‘7’.

Function: dynamic-array? obj

Return #t if obj is a record of type <dynamic-array>; otherwise return #f.

Function: dynamic-array obj

Build and return a <dynamic-array> object holding the given objects, which are pushed on the dynamic-array left to right from the rear side. The size of the internal vector is set to the default.

(define D
  (dynamic-array 0 1 2))

(dynamic-array-front D)         ⇒ 0
(dynamic-array-rear  D)         ⇒ 2

Object properties

Function: dynamic-array-putprop arry key value
Function: $dynamic-array-putprop arry key value

Add a new property key to the property list of arry; key must be a symbol. If key is already set: the old entry is mutated to reference the new value.

Function: dynamic-array-getprop arry key
Function: $dynamic-array-getprop arry key

Return the value of the property key in the property list of arry; if key is not set: return #f. key must be a symbol.

Function: dynamic-array-remprop arry key
Function: $dynamic-array-remprop arry key

Remove the property key from the property list of arry; if key is not set: nothing happens. key must be a symbol.

Function: dynamic-array-property-list arry
Function: $dynamic-array-property-list arry

Return a new association list representing the property list of arry. The order of the entries is the same as the property creation order.

Other operations

Function: dynamic-array-hash arry
Function: $dynamic-array-hash arry

Return an exact integer to be used as hashtable key for arry. Hashtables having a <dynamic-array> as key can be instantiated as follows:

(make-hashtable dynamic-array-hash eq?)

Next: , Up: dynamic arrays   [Index]