Mercurial > hg > xemacs-beta
comparison src/rangetab.c @ 398:74fd4e045ea6 r21-2-29
Import from CVS: tag r21-2-29
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:13:30 +0200 |
parents | 8626e4521993 |
children | a86b2b5e0111 |
comparison
equal
deleted
inserted
replaced
397:f4aeb21a5bad | 398:74fd4e045ea6 |
---|---|
39 | 39 |
40 #### We should be using the gap array stuff from extents.c. This | 40 #### We should be using the gap array stuff from extents.c. This |
41 is not hard but just requires moving that stuff out of that file. */ | 41 is not hard but just requires moving that stuff out of that file. */ |
42 | 42 |
43 static Lisp_Object | 43 static Lisp_Object |
44 mark_range_table (Lisp_Object obj, void (*markobj) (Lisp_Object)) | 44 mark_range_table (Lisp_Object obj) |
45 { | 45 { |
46 struct Lisp_Range_Table *rt = XRANGE_TABLE (obj); | 46 Lisp_Range_Table *rt = XRANGE_TABLE (obj); |
47 int i; | 47 int i; |
48 | 48 |
49 for (i = 0; i < Dynarr_length (rt->entries); i++) | 49 for (i = 0; i < Dynarr_length (rt->entries); i++) |
50 markobj (Dynarr_at (rt->entries, i).val); | 50 mark_object (Dynarr_at (rt->entries, i).val); |
51 return Qnil; | 51 return Qnil; |
52 } | 52 } |
53 | 53 |
54 static void | 54 static void |
55 print_range_table (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | 55 print_range_table (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) |
56 { | 56 { |
57 struct Lisp_Range_Table *rt = XRANGE_TABLE (obj); | 57 Lisp_Range_Table *rt = XRANGE_TABLE (obj); |
58 char buf[200]; | 58 char buf[200]; |
59 int i; | 59 int i; |
60 | 60 |
61 write_c_string ("#s(range-table data (", printcharfun); | 61 write_c_string ("#s(range-table data (", printcharfun); |
62 for (i = 0; i < Dynarr_length (rt->entries); i++) | 62 for (i = 0; i < Dynarr_length (rt->entries); i++) |
75 } | 75 } |
76 | 76 |
77 static int | 77 static int |
78 range_table_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | 78 range_table_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) |
79 { | 79 { |
80 struct Lisp_Range_Table *rt1 = XRANGE_TABLE (obj1); | 80 Lisp_Range_Table *rt1 = XRANGE_TABLE (obj1); |
81 struct Lisp_Range_Table *rt2 = XRANGE_TABLE (obj2); | 81 Lisp_Range_Table *rt2 = XRANGE_TABLE (obj2); |
82 int i; | 82 int i; |
83 | 83 |
84 if (Dynarr_length (rt1->entries) != Dynarr_length (rt2->entries)) | 84 if (Dynarr_length (rt1->entries) != Dynarr_length (rt2->entries)) |
85 return 0; | 85 return 0; |
86 | 86 |
105 } | 105 } |
106 | 106 |
107 static unsigned long | 107 static unsigned long |
108 range_table_hash (Lisp_Object obj, int depth) | 108 range_table_hash (Lisp_Object obj, int depth) |
109 { | 109 { |
110 struct Lisp_Range_Table *rt = XRANGE_TABLE (obj); | 110 Lisp_Range_Table *rt = XRANGE_TABLE (obj); |
111 int i; | 111 int i; |
112 int size = Dynarr_length (rt->entries); | 112 int size = Dynarr_length (rt->entries); |
113 unsigned long hash = size; | 113 unsigned long hash = size; |
114 | 114 |
115 /* approach based on internal_array_hash(). */ | 115 /* approach based on internal_array_hash(). */ |
130 i*size/5), | 130 i*size/5), |
131 depth)); | 131 depth)); |
132 return hash; | 132 return hash; |
133 } | 133 } |
134 | 134 |
135 static const struct lrecord_description rte_description_1[] = { | |
136 { XD_LISP_OBJECT, offsetof (range_table_entry, val) }, | |
137 { XD_END } | |
138 }; | |
139 | |
140 static const struct struct_description rte_description = { | |
141 sizeof (range_table_entry), | |
142 rte_description_1 | |
143 }; | |
144 | |
145 static const struct lrecord_description rted_description_1[] = { | |
146 XD_DYNARR_DESC (range_table_entry_dynarr, &rte_description), | |
147 { XD_END } | |
148 }; | |
149 | |
150 static const struct struct_description rted_description = { | |
151 sizeof (range_table_entry_dynarr), | |
152 rted_description_1 | |
153 }; | |
154 | |
155 static const struct lrecord_description range_table_description[] = { | |
156 { XD_STRUCT_PTR, offsetof (Lisp_Range_Table, entries), 1, &rted_description }, | |
157 { XD_END } | |
158 }; | |
159 | |
135 DEFINE_LRECORD_IMPLEMENTATION ("range-table", range_table, | 160 DEFINE_LRECORD_IMPLEMENTATION ("range-table", range_table, |
136 mark_range_table, print_range_table, 0, | 161 mark_range_table, print_range_table, 0, |
137 range_table_equal, range_table_hash, | 162 range_table_equal, range_table_hash, |
138 struct Lisp_Range_Table); | 163 range_table_description, |
164 Lisp_Range_Table); | |
139 | 165 |
140 /************************************************************************/ | 166 /************************************************************************/ |
141 /* Range table operations */ | 167 /* Range table operations */ |
142 /************************************************************************/ | 168 /************************************************************************/ |
143 | 169 |
144 #ifdef ERROR_CHECK_TYPECHECK | 170 #ifdef ERROR_CHECK_TYPECHECK |
145 | 171 |
146 static void | 172 static void |
147 verify_range_table (struct Lisp_Range_Table *rt) | 173 verify_range_table (Lisp_Range_Table *rt) |
148 { | 174 { |
149 int i; | 175 int i; |
150 | 176 |
151 for (i = 0; i < Dynarr_length (rt->entries); i++) | 177 for (i = 0; i < Dynarr_length (rt->entries); i++) |
152 { | 178 { |
205 `remove-range-table', and `clear-range-table'. | 231 `remove-range-table', and `clear-range-table'. |
206 */ | 232 */ |
207 ()) | 233 ()) |
208 { | 234 { |
209 Lisp_Object obj; | 235 Lisp_Object obj; |
210 struct Lisp_Range_Table *rt = alloc_lcrecord_type (struct Lisp_Range_Table, | 236 Lisp_Range_Table *rt = alloc_lcrecord_type (Lisp_Range_Table, |
211 lrecord_range_table); | 237 &lrecord_range_table); |
212 rt->entries = Dynarr_new (range_table_entry); | 238 rt->entries = Dynarr_new (range_table_entry); |
213 XSETRANGE_TABLE (obj, rt); | 239 XSETRANGE_TABLE (obj, rt); |
214 return obj; | 240 return obj; |
215 } | 241 } |
216 | 242 |
218 Make a new range table which contains the same values for the same | 244 Make a new range table which contains the same values for the same |
219 ranges as the given table. The values will not themselves be copied. | 245 ranges as the given table. The values will not themselves be copied. |
220 */ | 246 */ |
221 (old_table)) | 247 (old_table)) |
222 { | 248 { |
223 struct Lisp_Range_Table *rt, *rtnew; | 249 Lisp_Range_Table *rt, *rtnew; |
224 Lisp_Object obj; | 250 Lisp_Object obj; |
225 | 251 |
226 CHECK_RANGE_TABLE (old_table); | 252 CHECK_RANGE_TABLE (old_table); |
227 rt = XRANGE_TABLE (old_table); | 253 rt = XRANGE_TABLE (old_table); |
228 | 254 |
229 rtnew = alloc_lcrecord_type (struct Lisp_Range_Table, lrecord_range_table); | 255 rtnew = alloc_lcrecord_type (Lisp_Range_Table, &lrecord_range_table); |
230 rtnew->entries = Dynarr_new (range_table_entry); | 256 rtnew->entries = Dynarr_new (range_table_entry); |
231 | 257 |
232 Dynarr_add_many (rtnew->entries, Dynarr_atp (rt->entries, 0), | 258 Dynarr_add_many (rtnew->entries, Dynarr_atp (rt->entries, 0), |
233 Dynarr_length (rt->entries)); | 259 Dynarr_length (rt->entries)); |
234 XSETRANGE_TABLE (obj, rtnew); | 260 XSETRANGE_TABLE (obj, rtnew); |
239 Find value for position POS in TABLE. | 265 Find value for position POS in TABLE. |
240 If there is no corresponding value, return DEFAULT (defaults to nil). | 266 If there is no corresponding value, return DEFAULT (defaults to nil). |
241 */ | 267 */ |
242 (pos, table, default_)) | 268 (pos, table, default_)) |
243 { | 269 { |
244 struct Lisp_Range_Table *rt; | 270 Lisp_Range_Table *rt; |
245 | 271 |
246 CHECK_RANGE_TABLE (table); | 272 CHECK_RANGE_TABLE (table); |
247 rt = XRANGE_TABLE (table); | 273 rt = XRANGE_TABLE (table); |
248 | 274 |
249 CHECK_INT_COERCE_CHAR (pos); | 275 CHECK_INT_COERCE_CHAR (pos); |
256 put_range_table (Lisp_Object table, EMACS_INT first, | 282 put_range_table (Lisp_Object table, EMACS_INT first, |
257 EMACS_INT last, Lisp_Object val) | 283 EMACS_INT last, Lisp_Object val) |
258 { | 284 { |
259 int i; | 285 int i; |
260 int insert_me_here = -1; | 286 int insert_me_here = -1; |
261 struct Lisp_Range_Table *rt = XRANGE_TABLE (table); | 287 Lisp_Range_Table *rt = XRANGE_TABLE (table); |
262 | 288 |
263 /* Now insert in the proper place. This gets tricky because | 289 /* Now insert in the proper place. This gets tricky because |
264 we may be overlapping one or more existing ranges and need | 290 we may be overlapping one or more existing ranges and need |
265 to fix them up. */ | 291 to fix them up. */ |
266 | 292 |