1 | [[tags:egg]] |
---|
2 | |
---|
3 | == srfi-4-utils |
---|
4 | |
---|
5 | Utility functions for SRFI-4 vectors. |
---|
6 | |
---|
7 | [[toc:]] |
---|
8 | |
---|
9 | == Usage |
---|
10 | |
---|
11 | (require-extension srfi-4-utils) |
---|
12 | |
---|
13 | == Documentation |
---|
14 | |
---|
15 | {{srfi-4-utils}} contains a set of convenience procedures for |
---|
16 | [[http://srfi.schemers.org/srfi-4/srfi-4.html|SRFI-4]] vectors: |
---|
17 | {{fold}}, {{map}}, {{quick-sort!}}, {{merge!}}, {{merge-sort!}}. |
---|
18 | |
---|
19 | === Procedures |
---|
20 | |
---|
21 | <procedure>s8vector-fold :: F * X0 * V [* V1 ... VN] -> XN</procedure><br> |
---|
22 | <procedure>u8vector-fold :: F * X0 * V [* V1 ... VN] -> XN</procedure><br> |
---|
23 | <procedure>s16vector-fold :: F * X0 * V [* V1 ... VN] -> XN</procedure><br> |
---|
24 | <procedure>u16vector-fold :: F * X0 * V [* V1 ... VN] -> XN</procedure><br> |
---|
25 | <procedure>s32vector-fold :: F * X0 * V [* V1 ... VN] -> XN</procedure><br> |
---|
26 | <procedure>u32vector-fold :: F * X0 * V [* V1 ... VN] -> XN</procedure><br> |
---|
27 | <procedure>f32vector-fold :: F * X0 * V [* V1 ... VN] -> XN</procedure><br> |
---|
28 | <procedure>f64vector-fold :: F * X0 * V [* V1 ... VN] -> XN</procedure> |
---|
29 | |
---|
30 | where {{F :: V(I) [ * V1(I) ... VN(I)] * AX -> AX}} |
---|
31 | |
---|
32 | <procedure>s8vector-map :: F * V [ * V1 ... VN] -> V</procedure><br> |
---|
33 | <procedure>u8vector-map :: F * V [ * V1 ... VN] -> V</procedure><br> |
---|
34 | <procedure>s16vector-map :: F * V [ * V1 ... VN] -> V</procedure><br> |
---|
35 | <procedure>u16vector-map :: F * V [ * V1 ... VN] -> V</procedure><br> |
---|
36 | <procedure>s32vector-map :: F * V [ * V1 ... VN] -> V</procedure><br> |
---|
37 | <procedure>u32vector-map :: F * V [ * V1 ... VN] -> V</procedure><br> |
---|
38 | <procedure>f32vector-map :: F * V [ * V1 ... VN] -> V</procedure><br> |
---|
39 | <procedure>f64vector-map :: F * V [ * V1 ... VN] -> V</procedure> |
---|
40 | |
---|
41 | <procedure>s8vector-foldi :: F * X0 * V [ * V1 ... VN] -> XN</procedure><br> |
---|
42 | <procedure>u8vector-foldi :: F * X0 * V [ * V1 ... VN] -> XN</procedure><br> |
---|
43 | <procedure>s16vector-foldi :: F * X0 * V [ * V1 ... VN] -> XN</procedure><br> |
---|
44 | <procedure>u16vector-foldi :: F * X0 * V [ * V1 ... VN] -> XN</procedure><br> |
---|
45 | <procedure>s32vector-foldi :: F * X0 * V [ * V1 ... VN] -> XN</procedure><br> |
---|
46 | <procedure>u32vector-foldi :: F * X0 * V [ * V1 ... VN] -> XN</procedure><br> |
---|
47 | <procedure>f32vector-foldi :: F * X0 * V [ * V1 ... VN] -> XN</procedure><br> |
---|
48 | <procedure>f64vector-foldi :: F * X0 * V [ * V1 ... VN] -> XN</procedure> |
---|
49 | |
---|
50 | where {{F :: I * V(I) [ * V1(I) ... VN(I)] * AX -> AX}} |
---|
51 | |
---|
52 | |
---|
53 | <procedure>s8vector-mapi :: F * V [* V1 ... VN] -> V</procedure><br> |
---|
54 | <procedure>u8vector-mapi :: F * V [* V1 ... VN] -> V</procedure><br> |
---|
55 | <procedure>s16vector-mapi :: F * V [* V1 ... VN] -> V</procedure><br> |
---|
56 | <procedure>u16vector-mapi :: F * V [* V1 ... VN] -> V</procedure><br> |
---|
57 | <procedure>s32vector-mapi :: F * V [* V1 ... VN] -> V</procedure><br> |
---|
58 | <procedure>u32vector-mapi :: F * V [* V1 ... VN] -> V</procedure><br> |
---|
59 | <procedure>f32ector-mapi :: F * V [* V1 ... VN] -> V</procedure><br> |
---|
60 | <procedure>f64vector-mapi :: F * V [* V1 ... VN] -> V</procedure> |
---|
61 | |
---|
62 | where {{F :: I * V(I) [* V1(I) ... VN(I)] -> V}} |
---|
63 | |
---|
64 | <procedure>s8vector-blit! :: VFROM * I * END * VTO * J] -> V</procedure><br> |
---|
65 | <procedure>u8vector-blit! :: VFROM * I * END * VTO * J] -> V</procedure><br> |
---|
66 | <procedure>s16vector-blit! :: VFROM * I * END * VTO * J] -> V</procedure><br> |
---|
67 | <procedure>u16vector-blit! :: VFROM * I * END * VTO * J] -> V</procedure><br> |
---|
68 | <procedure>s32vector-blit! :: VFROM * I * END * VTO * J] -> V</procedure><br> |
---|
69 | <procedure>u32vector-blit! :: VFROM * I * END * VTO * J] -> V</procedure><br> |
---|
70 | <procedure>f32vector-blit! :: VFROM * I * END * VTO * J] -> V</procedure><br> |
---|
71 | <procedure>f64vector-blit! :: VFROM * I * END * VTO * J] -> V</procedure><br> |
---|
72 | |
---|
73 | Copies subvector {{VFROM[I,END)}} into {{VTO[J,J+(END-I))}}. |
---|
74 | |
---|
75 | <procedure>s8vector-merge! :: ELT< * VA * P * Q * R * VB * N -> VB</procedure><br> |
---|
76 | <procedure>u8vector-merge! :: ELT< * VA * P * Q * R * VB * N -> VB</procedure><br> |
---|
77 | <procedure>s16vector-merge! :: ELT< * VA * P * Q * R * VB * N -> VB</procedure><br> |
---|
78 | <procedure>u16vector-merge! :: ELT< * VA * P * Q * R * VB * N -> VB</procedure><br> |
---|
79 | <procedure>s32vector-merge! :: ELT< * VA * P * Q * R * VB * N -> VB</procedure><br> |
---|
80 | <procedure>u32vector-merge! :: ELT< * VA * P * Q * R * VB * N -> VB</procedure><br> |
---|
81 | <procedure>f32vector-merge! :: ELT< * VA * P * Q * R * VB * N -> VB</procedure><br> |
---|
82 | <procedure>f64vector-merge! :: ELT< * VA * P * Q * R * VB * N -> VB</procedure><br> |
---|
83 | |
---|
84 | Given vector VA and indices P, Q, R such that P < Q < R, merges |
---|
85 | subvector {{VA[P,Q)}} and subvector {{A[Q,R)}} into vector {{B[N,N+(R-P))}}. |
---|
86 | The comparison function {{ELT<}} must be of type {{ELT< :: i1 * V(i1) * i2 * V(i2) -> boolean}}. |
---|
87 | |
---|
88 | |
---|
89 | <procedure>s8vector-quick-sort! :: ELT< * V -> V</procedure><br> |
---|
90 | <procedure>u8vector-quick-sort! :: ELT< * V -> V</procedure><br> |
---|
91 | <procedure>s16vector-quick-sort! :: ELT< * V -> V</procedure><br> |
---|
92 | <procedure>u16vector-quick-sort! :: ELT< * V -> V</procedure><br> |
---|
93 | <procedure>s32vector-quick-sort! :: ELT< * V -> V</procedure><br> |
---|
94 | <procedure>u32vector-quick-sort! :: ELT< * V -> V</procedure><br> |
---|
95 | <procedure>f32vector-quick-sort! :: ELT< * V -> V</procedure><br> |
---|
96 | <procedure>f64vector-quick-sort! :: ELT< * V -> V</procedure> |
---|
97 | |
---|
98 | where {{ELT< :: i1 * V(i1) * i2 * V(i2) -> boolean}} |
---|
99 | |
---|
100 | <procedure>s8vector-merge-sort! :: ELT< * V -> V</procedure><br> |
---|
101 | <procedure>u8vector-merge-sort! :: ELT< * V -> V</procedure><br> |
---|
102 | <procedure>s16vector-merge-sort! :: ELT< * V -> V</procedure><br> |
---|
103 | <procedure>u16vector-merge-sort! :: ELT< * V -> V</procedure><br> |
---|
104 | <procedure>s32vector-merge-sort! :: ELT< * V -> V</procedure><br> |
---|
105 | <procedure>u32vector-merge-sort! :: ELT< * V -> V</procedure><br> |
---|
106 | <procedure>f32vector-merge-sort! :: ELT< * V -> V</procedure><br> |
---|
107 | <procedure>f64vector-merge-sort! :: ELT< * V -> V</procedure> |
---|
108 | |
---|
109 | where {{ELT< :: i1 * V(i1) * i2 * V(i2) -> boolean}} |
---|
110 | |
---|
111 | |
---|
112 | == Examples |
---|
113 | |
---|
114 | |
---|
115 | csi> (f64vector-map (lambda (v) (* 2 v)) (f64vector 1 2 3)) |
---|
116 | -> #f64(2.0 4.0 6.0) |
---|
117 | |
---|
118 | csi> (f64vector-fold (lambda (v ax) (+ v ax)) (f64vector 1 2 3) 0) |
---|
119 | -> 6.0 |
---|
120 | |
---|
121 | ;; input vector is modified |
---|
122 | csi> (f64vector-quick-sort! (lambda (i1 v1 i2 v2) (< v1 v2)) (f64vector 1 4 2 3) ) |
---|
123 | #f64(1.0 2.0 3.0 4.0) |
---|
124 | |
---|
125 | == About this egg |
---|
126 | |
---|
127 | |
---|
128 | === Author |
---|
129 | |
---|
130 | [[/users/ivan-raikov|Ivan Raikov]] |
---|
131 | |
---|
132 | === Version history |
---|
133 | |
---|
134 | ; 1.9 : Added merge! and merge-sort! procedures |
---|
135 | ; 1.6 : Documentation converted to wiki format |
---|
136 | ; 1.5 : Ported to Chicken 4 |
---|
137 | ; 1.4 : Build script bug fix |
---|
138 | ; 1.3 : Build script updated for better cross-platform compatibility |
---|
139 | ; 1.2 : Extended fold and map interface to support multiple vector arguments |
---|
140 | ; 1.1 : Added foldi and mapi procedures |
---|
141 | ; 1.0 : Initial release |
---|
142 | |
---|
143 | |
---|
144 | === License |
---|
145 | |
---|
146 | |
---|
147 | Copyright 2007-2013 Ivan Raikov and the Okinawa Institute of Science and Technology |
---|
148 | |
---|
149 | This program is free software: you can redistribute it and/or modify |
---|
150 | it under the terms of the GNU General Public License as published by |
---|
151 | the Free Software Foundation, either version 3 of the License, or (at |
---|
152 | your option) any later version. |
---|
153 | |
---|
154 | This program is distributed in the hope that it will be useful, but |
---|
155 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
156 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
157 | General Public License for more details. |
---|
158 | |
---|
159 | A full copy of the GPL license can be found at |
---|
160 | <http://www.gnu.org/licenses/>. |
---|
161 | |
---|