* weaks.c: Use new vector elements API or simple vector
[bpt/guile.git] / libguile / vectors.h
1 /* classes: h_files */
2
3 #ifndef SCM_VECTORS_H
4 #define SCM_VECTORS_H
5
6 /* Copyright (C) 1995,1996,1998,2000,2001, 2002 Free Software Foundation, Inc.
7 *
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.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
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 */
22
23 \f
24
25 #include "libguile/__scm.h"
26 #include "libguile/unif.h"
27
28 \f
29
30 /*
31 bit vectors
32 */
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))
36
37 \f
38
39
40 \f
41
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);
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);
54 SCM_API SCM scm_vector_copy (SCM vec);
55
56 SCM_API int scm_is_vector (SCM obj);
57 SCM_API int scm_is_simple_vector (SCM obj);
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);
61 SCM_API void scm_c_vector_set_x (SCM vec, size_t k, SCM obj);
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]))
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
83 /* Deprecated */
84
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
98 SCM_API SCM scm_vector_equal_p (SCM x, SCM y);
99
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
125 SCM_API void scm_init_vectors (void);
126
127 #endif /* SCM_VECTORS_H */
128
129 /*
130 Local Variables:
131 c-file-style: "gnu"
132 End:
133 */