data.texi 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. @node Library data structures
  2. @section Library data structures
  3. Scheme48 includes several libraries for a variety of data structures.
  4. @subsection Multi-dimensional arrays
  5. @cindex arrays
  6. @stindex arrays
  7. The @code{arrays} structure exports a facility for multi-dimensional
  8. arrays, based on Alan Bawden's interface.
  9. @deffn procedure make-array value dimension @dots{} @returns{} array
  10. @deffnx procedure array dimensions element @dots{} @returns{} array
  11. @deffnx procedure copy-array array @dots{} @returns{} array
  12. Array constructors. @code{Make-array} constructs an array with the
  13. given dimensions, each of which must be an exact, non-negative integer,
  14. and fills all of the elements with @var{value}. @code{Array} creates
  15. an array with the given list of dimensions, which must be a list of
  16. exact, non-negative integers, and fills it with the given elements in
  17. row-major order. The number of elements must be equal to the product
  18. of @var{dimensions}. @code{Copy-array} constructs an array with the
  19. same dimensions and contents as @var{array}.
  20. @end deffn
  21. @deffn procedure array? object @returns{} boolean
  22. Disjoint type predicate for arrays.
  23. @end deffn
  24. @deffn procedure array-shape array @returns{} integer-list
  25. Returns the list of dimensions of @var{array}.
  26. @end deffn
  27. @deffn procedure array-ref array index @dots{} @returns{} value
  28. @deffnx procedure array-set! array value index @dots{} @returns{} unspecified
  29. Array element dereferencing and assignment. Each @var{index} must be
  30. in the half-open interval [0,@var{d}), where @var{d} is the respective
  31. dimension of @var{array} corresponding with that index.
  32. @end deffn
  33. @deffn procedure array->vector array @returns{} vector
  34. Creates a vector of the elements in @var{array} in row-major order.
  35. @end deffn
  36. @deffn procedure make-shared-array array linear-map dimension @dots{} @returns{} array
  37. Creates a new array that shares storage with @var{array} and uses the
  38. procedure @var{linear-map} to map indices in the new array to indices in
  39. @var{array}. @var{Linear-map} must accept as many arguments as
  40. @var{dimension} @dots{}, each of which must be an exact, non-negative
  41. integer; and must return a list of exact, non-negative integers equal
  42. in length to the number of dimensions of @var{array}, and which must
  43. be valid indices into @var{array}.
  44. @end deffn
  45. @subsection Red/black search trees
  46. @cindex binary search trees
  47. @stindex search-trees
  48. Along with hash tables for general object maps, Scheme48 also provides
  49. red/black binary search trees generalized across key equality
  50. comparison & ordering functions, as opposed to key equality comparison
  51. & hash functions with hash tables. These names are exported by the
  52. @code{search-trees} structure.
  53. @deffn procedure make-search-tree key= key< @returns{} search-tree
  54. @deffnx procedure search-tree? object @returns{} boolean
  55. @code{Make-search-tree} creates a new search tree with the given key
  56. equality comparison & ordering functions. @code{Search-tree?} is the
  57. disjoint type predicate for red/black binary search trees.
  58. @end deffn
  59. @deffn procedure search-tree-ref search-tree key @returns{} value or @code{#f}
  60. @deffnx procedure search-tree-set! search-tree key value @returns{} unspecified
  61. @deffnx procedure search-tree-modify! search-tree key modifier @returns{} unspecified
  62. @code{Search-tree-ref} returns the value associated with @var{key} in
  63. @var{search-tree}, or @code{#f} if no such association exists.
  64. @code{Search-tree-set!} assigns the value of an existing association in
  65. @var{search-tree} for @var{key} to be @var{value}, if the association
  66. already exists; or, if not, it creates a new association with the given
  67. key and value. If @var{value} is @code{#f}, however, any association
  68. is removed. @code{Search-tree-modify!} modifies the association in
  69. @var{search-tree} for @var{key} by applying @var{modifier} to the
  70. previous value of the association. If no association previously
  71. existed, one is created whose key is @var{key} and whose value is the
  72. result of applying @var{modifier} to @code{#f}. If @var{modifier}
  73. returns @code{#f}, the association is removed. This is equivalent to
  74. @code{(search-tree-set! @var{search-tree} @var{key} (@var{modifier}
  75. (search-tree-ref @var{search-tree} @var{key})))}, but it is implemented
  76. more efficiently.
  77. @end deffn
  78. @deffn procedure search-tree-max search-tree @returns{} value or @code{#f}
  79. @deffnx procedure search-tree-min search-tree @returns{} value or @code{#f}
  80. @deffnx procedure pop-search-tree-max! search-tree @returns{} value or @code{#f}
  81. @deffnx procedure pop-search-tree-min! search-tree @returns{} value or @code{#f}
  82. These all return two values: the key & value for the association in
  83. @var{search-tree} whose key is the maximum or minimum of the tree.
  84. @code{Search-tree-max} and @code{search-tree-min} do not remove the
  85. association from @var{search-tree}; @code{pop-search-tree-max!} and
  86. @code{pop-search-tree-min!} do. If @var{search-tree} is empty, these
  87. all return the two values @code{#f} and @code{#f}.
  88. @end deffn
  89. @deffn procedure walk-search-tree proc search-tree @returns{} unspecified
  90. This applies @var{proc} to two arguments, the key & value, for every
  91. association in @var{search-tree}.
  92. @end deffn
  93. @subsection Sparse vectors
  94. @cindex resizable vectors
  95. @cindex growing vectors
  96. @stindex sparse-vectors
  97. Sparse vectors, exported by the structure @code{sparse-vectors}, are
  98. vectors that grow as large as necessary without leaving large, empty
  99. spaces in the vector. They are implemented as trees of subvectors.
  100. @deffn procedure make-sparse-vector @returns{} sparse-vector
  101. Sparse vector constructor.
  102. @end deffn
  103. @deffn procedure sparse-vector-ref sparse-vector index @returns{} value or @code{#f}
  104. @deffnx procedure sparse-vector-set! sparse-vector index value @returns{} unspecified
  105. Sparse vector element accessor and modifier. In the case of
  106. @code{sparse-vector-ref}, if @var{index} is beyond the highest index
  107. that was inserted into @var{sparse-vector}, it returns @code{#f}; if
  108. @code{sparse-vector-set!} is passed an index beyond what was already
  109. assigned, it simply extends the vector.
  110. @end deffn
  111. @deffn procedure sparse-vector->list sparse-vector @returns{} list
  112. Creates a list of the elements in @var{sparse-vector}. Elements that
  113. uninitialized gaps comprise are denoted by @code{#f} in the list.
  114. @end deffn