Commit | Line | Data |
---|---|---|
0f2d19dd JB |
1 | /* classes: h_files */ |
2 | ||
dcb410ec DH |
3 | #ifndef SCM_VECTORS_H |
4 | #define SCM_VECTORS_H | |
dee01b01 | 5 | |
1f1270b9 | 6 | /* Copyright (C) 1995,1996,1998,2000,2001, 2002 Free Software Foundation, Inc. |
dee01b01 | 7 | * |
73be1d9e MV |
8 | * This library is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License as published by the Free Software Foundation; either | |
11 | * version 2.1 of the License, or (at your option) any later version. | |
dee01b01 | 12 | * |
73be1d9e | 13 | * This library is distributed in the hope that it will be useful, |
0f2d19dd | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
73be1d9e MV |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Lesser General Public License for more details. | |
dee01b01 | 17 | * |
73be1d9e MV |
18 | * You should have received a copy of the GNU Lesser General Public |
19 | * License along with this library; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | */ | |
d3a6bc94 | 22 | |
0f2d19dd JB |
23 | \f |
24 | ||
b4309c3c | 25 | #include "libguile/__scm.h" |
6e708ef2 | 26 | #include "libguile/unif.h" |
0f2d19dd JB |
27 | |
28 | \f | |
29 | ||
c209c88e GB |
30 | /* |
31 | bit vectors | |
32 | */ | |
bab246f3 DH |
33 | #define SCM_BITVEC_REF(a, i) ((SCM_BITVECTOR_BASE (a) [(i) / SCM_LONG_BIT] & (1L << ((i) % SCM_LONG_BIT))) ? 1 : 0) |
34 | #define SCM_BITVEC_SET(a, i) SCM_BITVECTOR_BASE (a) [(i) / SCM_LONG_BIT] |= (1L << ((i) % SCM_LONG_BIT)) | |
35 | #define SCM_BITVEC_CLR(a, i) SCM_BITVECTOR_BASE (a) [(i) / SCM_LONG_BIT] &= ~(1L << ((i) % SCM_LONG_BIT)) | |
c209c88e | 36 | |
6e708ef2 MV |
37 | \f |
38 | ||
c209c88e | 39 | |
0f2d19dd | 40 | \f |
0f2d19dd | 41 | |
33b001fd MV |
42 | SCM_API SCM scm_vector_p (SCM x); |
43 | SCM_API SCM scm_vector_length (SCM v); | |
44 | SCM_API SCM scm_vector (SCM l); | |
45 | SCM_API SCM scm_vector_ref (SCM v, SCM k); | |
46 | SCM_API SCM scm_vector_set_x (SCM v, SCM k, SCM obj); | |
47 | SCM_API SCM scm_make_vector (SCM k, SCM fill); | |
48 | SCM_API SCM scm_vector_to_list (SCM v); | |
49 | SCM_API SCM scm_vector_fill_x (SCM v, SCM fill_x); | |
33b001fd MV |
50 | SCM_API SCM scm_vector_move_left_x (SCM vec1, SCM start1, SCM end1, |
51 | SCM vec2, SCM start2); | |
52 | SCM_API SCM scm_vector_move_right_x (SCM vec1, SCM start1, SCM end1, | |
53 | SCM vec2, SCM start2); | |
6e708ef2 | 54 | SCM_API SCM scm_vector_copy (SCM vec); |
88797580 MV |
55 | |
56 | SCM_API int scm_is_vector (SCM obj); | |
6e708ef2 | 57 | SCM_API int scm_is_simple_vector (SCM obj); |
88797580 MV |
58 | SCM_API SCM scm_c_make_vector (size_t len, SCM fill); |
59 | SCM_API size_t scm_c_vector_length (SCM vec); | |
60 | SCM_API SCM scm_c_vector_ref (SCM vec, size_t k); | |
de5c0f58 | 61 | SCM_API void scm_c_vector_set_x (SCM vec, size_t k, SCM obj); |
6e708ef2 MV |
62 | |
63 | /* Fast, non-checking accessors for simple vectors. | |
64 | */ | |
65 | #define SCM_SIMPLE_VECTOR_LENGTH(x) SCM_I_VECTOR_LENGTH(x) | |
66 | #define SCM_SIMPLE_VECTOR_REF(x,idx) ((SCM_I_VECTOR_ELTS(x))[idx]) | |
67 | #define SCM_SIMPLE_VECTOR_SET(x,idx,val) ((SCM_I_VECTOR_WELTS(x))[idx]=(val)) | |
68 | #define SCM_SIMPLE_VECTOR_LOC(x,idx) (&((SCM_I_VECTOR_WELTS(x))[idx])) | |
88797580 MV |
69 | |
70 | /* Generalized vectors */ | |
71 | ||
72 | SCM_API SCM scm_generalized_vector_p (SCM v); | |
73 | SCM_API SCM scm_generalized_vector_length (SCM v); | |
74 | SCM_API SCM scm_generalized_vector_ref (SCM v, SCM idx); | |
75 | SCM_API SCM scm_generalized_vector_set_x (SCM v, SCM idx, SCM val); | |
76 | SCM_API SCM scm_generalized_vector_to_list (SCM v); | |
77 | ||
78 | SCM_API int scm_is_generalized_vector (SCM obj); | |
79 | SCM_API size_t scm_c_generalized_vector_length (SCM v); | |
80 | SCM_API SCM scm_c_generalized_vector_ref (SCM v, size_t idx); | |
81 | SCM_API void scm_c_generalized_vector_set_x (SCM v, size_t idx, SCM val); | |
82 | ||
1d0df896 MV |
83 | /* Deprecated */ |
84 | ||
6e708ef2 MV |
85 | #if SCM_ENABLE_DEPRECATED |
86 | ||
87 | #define SCM_VECTOR_MAX_LENGTH ((1L << 24) - 1) | |
88 | ||
89 | SCM_API int SCM_VECTORP (SCM x); | |
90 | SCM_API unsigned long SCM_VECTOR_LENGTH (SCM x); | |
91 | SCM_API const SCM *SCM_VELTS (SCM x); | |
92 | SCM_API SCM *SCM_WRITABLE_VELTS (SCM x); | |
93 | SCM_API SCM SCM_VECTOR_REF (SCM x, size_t idx); | |
94 | SCM_API void SCM_VECTOR_SET (SCM x, size_t idx, SCM val); | |
95 | ||
96 | #endif | |
97 | ||
1d0df896 MV |
98 | SCM_API SCM scm_vector_equal_p (SCM x, SCM y); |
99 | ||
6e708ef2 MV |
100 | /* Internals */ |
101 | ||
102 | #define SCM_I_IS_VECTOR(x) (!SCM_IMP(x) && (SCM_TYP7S(x)==scm_tc7_vector)) | |
103 | #define SCM_I_VECTOR_ELTS(x) ((const SCM *) SCM_CELL_WORD_1 (x)) | |
104 | #define SCM_I_VECTOR_WELTS(x) ((SCM *) SCM_CELL_WORD_1 (x)) | |
105 | #define SCM_I_VECTOR_LENGTH(x) (((size_t) SCM_CELL_WORD_0 (x)) >> 8) | |
106 | ||
107 | SCM_API void scm_i_vector_free (SCM vec); | |
108 | ||
109 | /* Weak vectors share implementation details with ordinary vectors, | |
110 | but no one else should. Weak vectors need to be cleaned up as | |
111 | well. | |
112 | */ | |
113 | ||
114 | #define SCM_I_WVECTP(x) (!SCM_IMP (x) && \ | |
115 | SCM_TYP7 (x) == scm_tc7_wvect) | |
116 | #define SCM_I_WVECT_LENGTH SCM_I_VECTOR_LENGTH | |
117 | #define SCM_I_WVECT_VELTS SCM_I_VECTOR_ELTS | |
118 | #define SCM_I_WVECT_GC_WVELTS SCM_I_VECTOR_WELTS | |
119 | #define SCM_I_WVECT_TYPE(x) (SCM_CELL_WORD_2 (x)) | |
120 | #define SCM_I_WVECT_GC_CHAIN(X) (SCM_CELL_OBJECT_3 (X)) | |
121 | #define SCM_I_SET_WVECT_GC_CHAIN(X, o) (SCM_SET_CELL_OBJECT_3 ((X), (o))) | |
122 | ||
123 | SCM_API SCM scm_i_allocate_weak_vector (scm_t_bits type, SCM size, SCM fill); | |
124 | ||
33b001fd | 125 | SCM_API void scm_init_vectors (void); |
0f2d19dd | 126 | |
dcb410ec | 127 | #endif /* SCM_VECTORS_H */ |
89e00824 ML |
128 | |
129 | /* | |
130 | Local Variables: | |
131 | c-file-style: "gnu" | |
132 | End: | |
133 | */ |