(scm_bitvector_p, scm_bitvector,
[bpt/guile.git] / libguile / unif.h
1 /* classes: h_files */
2
3 #ifndef SCM_UNIF_H
4 #define SCM_UNIF_H
5
6 /* Copyright (C) 1995,1996,1997,1999,2000,2001, 2004 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
27 \f
28
29 /* This file contains the definitions for arrays and bit vectors.
30 Uniform numeric vectors are now in srfi-4.c.
31 */
32
33
34 /** Arrays */
35
36 /*
37 an array SCM is a non-immediate pointing to a heap cell where:
38
39 CAR: bits 0-15 hold the smob type id: scm_tc16_array
40 bit 16 is the SCM_ARRAY_FLAG_CONTIGUOUS flag
41 bits 17-31 hold the dimension (0 -- 32767)
42 CDR: pointer to a malloced block containing an scm_t_array structure
43 followed by an scm_t_array_dim structure for each dimension.
44 */
45
46 typedef struct scm_t_array
47 {
48 SCM v; /* the contents of the array, e.g., a vector or uniform vector. */
49 unsigned long base;
50 } scm_t_array;
51
52 typedef struct scm_t_array_dim
53 {
54 long lbnd;
55 long ubnd;
56 long inc;
57 } scm_t_array_dim;
58
59 SCM_API scm_t_bits scm_tc16_array;
60
61 #define SCM_ARRAY_FLAG_CONTIGUOUS (1 << 16)
62
63 #define SCM_ARRAYP(a) SCM_TYP16_PREDICATE (scm_tc16_array, a)
64 #define SCM_ARRAY_NDIM(x) ((size_t) (SCM_CELL_WORD_0 (x) >> 17))
65 #define SCM_ARRAY_CONTP(x) (SCM_CELL_WORD_0 (x) & SCM_ARRAY_FLAG_CONTIGUOUS)
66 #define SCM_SET_ARRAY_CONTIGUOUS_FLAG(x) \
67 (SCM_SET_CELL_WORD_0 ((x), SCM_CELL_WORD_0 (x) | SCM_ARRAY_FLAG_CONTIGUOUS))
68 #define SCM_CLR_ARRAY_CONTIGUOUS_FLAG(x) \
69 (SCM_SET_CELL_WORD_0 ((x), SCM_CELL_WORD_0 (x) & ~SCM_ARRAY_FLAG_CONTIGUOUS))
70
71 #define SCM_ARRAY_MEM(a) ((scm_t_array *) SCM_CELL_WORD_1 (a))
72 #define SCM_ARRAY_V(a) (SCM_ARRAY_MEM (a)->v)
73 #define SCM_ARRAY_BASE(a) (SCM_ARRAY_MEM (a)->base)
74 #define SCM_ARRAY_DIMS(a) ((scm_t_array_dim *)((char *) SCM_ARRAY_MEM (a) + sizeof (scm_t_array)))
75
76 SCM_API SCM scm_array_p (SCM v, SCM prot);
77 SCM_API SCM scm_array_rank (SCM ra);
78 SCM_API SCM scm_array_dimensions (SCM ra);
79 SCM_API SCM scm_shared_array_root (SCM ra);
80 SCM_API SCM scm_shared_array_offset (SCM ra);
81 SCM_API SCM scm_shared_array_increments (SCM ra);
82 SCM_API long scm_aind (SCM ra, SCM args, const char *what);
83 SCM_API SCM scm_shap2ra (SCM args, const char *what);
84 SCM_API SCM scm_dimensions_to_uniform_array (SCM dims, SCM prot, SCM fill);
85 SCM_API SCM scm_make_shared_array (SCM oldra, SCM mapfunc, SCM dims);
86 SCM_API SCM scm_transpose_array (SCM ra, SCM args);
87 SCM_API SCM scm_enclose_array (SCM ra, SCM axes);
88 SCM_API SCM scm_array_in_bounds_p (SCM v, SCM args);
89 SCM_API SCM scm_array_ref (SCM v, SCM args);
90 SCM_API SCM scm_array_set_x (SCM v, SCM obj, SCM args);
91 SCM_API SCM scm_array_contents (SCM ra, SCM strict);
92 SCM_API SCM scm_ra2contig (SCM ra, int copy);
93 SCM_API SCM scm_uniform_array_read_x (SCM ra, SCM port_or_fd, SCM start, SCM end);
94 SCM_API SCM scm_uniform_array_write (SCM v, SCM port_or_fd, SCM start, SCM end);
95 SCM_API SCM scm_array_to_list (SCM v);
96 SCM_API SCM scm_list_to_uniform_array (SCM ndim, SCM prot, SCM lst);
97 SCM_API SCM scm_array_creator (SCM ra);
98
99 SCM_API SCM scm_i_read_array (SCM port, int c);
100
101 \f
102 /** Bit vectors */
103
104 SCM_API SCM scm_bitvector_p (SCM vec);
105 SCM_API SCM scm_bitvector (SCM bits);
106 SCM_API SCM scm_make_bitvector (SCM len, SCM fill);
107 SCM_API SCM scm_bitvector_length (SCM vec);
108 SCM_API SCM scm_bitvector_ref (SCM vec, SCM idx);
109 SCM_API SCM scm_bitvector_set_x (SCM vec, SCM idx, SCM val);
110 SCM_API SCM scm_list_to_bitvector (SCM list);
111 SCM_API SCM scm_bitvector_to_list (SCM vec);
112 SCM_API SCM scm_bitvector_fill_x (SCM vec, SCM val);
113
114 SCM_API SCM scm_bit_count (SCM item, SCM seq);
115 SCM_API SCM scm_bit_position (SCM item, SCM v, SCM k);
116 SCM_API SCM scm_bit_set_star_x (SCM v, SCM kv, SCM obj);
117 SCM_API SCM scm_bit_count_star (SCM v, SCM kv, SCM obj);
118 SCM_API SCM scm_bit_invert_x (SCM v);
119
120 SCM_API int scm_is_bitvector (SCM obj);
121 SCM_API SCM scm_c_make_bitvector (size_t len, SCM fill);
122 SCM_API size_t scm_c_bitvector_length (SCM vec);
123 SCM_API SCM scm_c_bitvector_ref (SCM vec, size_t idx);
124 SCM_API void scm_c_bitvector_set_x (SCM vec, size_t idx, SCM val);
125 SCM_API scm_t_uint32 *scm_bitvector_elements (SCM vec);
126 SCM_API void scm_bitvector_release (SCM vec);
127 SCM_API void scm_frame_bitvector_release (SCM vec);
128
129 /* deprecated. */
130
131 SCM_API SCM scm_make_uve (long k, SCM prot);
132 SCM_API SCM scm_make_ra (int ndim);
133 SCM_API void scm_ra_set_contp (SCM ra);
134 SCM_API SCM scm_cvref (SCM v, unsigned long pos, SCM last);
135 SCM_API SCM scm_istr2bve (SCM str);
136 SCM_API int scm_raprin1 (SCM exp, SCM port, scm_print_state *pstate);
137 SCM_API SCM scm_array_prototype (SCM ra);
138
139 SCM_API SCM scm_i_proc_make_vector;
140 SCM_API SCM scm_i_proc_make_string;
141 SCM_API SCM scm_i_proc_make_bitvector;
142
143 SCM_API void scm_init_unif (void);
144
145 #endif /* SCM_UNIF_H */
146
147 /*
148 Local Variables:
149 c-file-style: "gnu"
150 End:
151 */