comparison src/rangetab.c @ 440:8de8e3f6228a r21-2-28

Import from CVS: tag r21-2-28
author cvs
date Mon, 13 Aug 2007 11:33:38 +0200
parents 3ecd8885ac67
children abe6d1db359e
comparison
equal deleted inserted replaced
439:357dd071b03c 440:8de8e3f6228a
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) 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 mark_object (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(). */
131 depth)); 131 depth));
132 return hash; 132 return hash;
133 } 133 }
134 134
135 static const struct lrecord_description rte_description_1[] = { 135 static const struct lrecord_description rte_description_1[] = {
136 { XD_LISP_OBJECT, offsetof(range_table_entry, val), 1 }, 136 { XD_LISP_OBJECT, offsetof (range_table_entry, val) },
137 { XD_END } 137 { XD_END }
138 }; 138 };
139 139
140 static const struct struct_description rte_description = { 140 static const struct struct_description rte_description = {
141 sizeof(range_table_entry), 141 sizeof (range_table_entry),
142 rte_description_1 142 rte_description_1
143 }; 143 };
144 144
145 static const struct lrecord_description rted_description_1[] = { 145 static const struct lrecord_description rted_description_1[] = {
146 XD_DYNARR_DESC(range_table_entry_dynarr, &rte_description), 146 XD_DYNARR_DESC (range_table_entry_dynarr, &rte_description),
147 { XD_END } 147 { XD_END }
148 }; 148 };
149 149
150 static const struct struct_description rted_description = { 150 static const struct struct_description rted_description = {
151 sizeof(range_table_entry_dynarr), 151 sizeof (range_table_entry_dynarr),
152 rted_description_1 152 rted_description_1
153 }; 153 };
154 154
155 static const struct lrecord_description range_table_description[] = { 155 static const struct lrecord_description range_table_description[] = {
156 { XD_STRUCT_PTR, offsetof(struct Lisp_Range_Table, entries), 1, &rted_description }, 156 { XD_STRUCT_PTR, offsetof (Lisp_Range_Table, entries), 1, &rted_description },
157 { XD_END } 157 { XD_END }
158 }; 158 };
159 159
160 DEFINE_LRECORD_IMPLEMENTATION ("range-table", range_table, 160 DEFINE_LRECORD_IMPLEMENTATION ("range-table", range_table,
161 mark_range_table, print_range_table, 0, 161 mark_range_table, print_range_table, 0,
162 range_table_equal, range_table_hash, 162 range_table_equal, range_table_hash,
163 range_table_description, 163 range_table_description,
164 struct Lisp_Range_Table); 164 Lisp_Range_Table);
165 165
166 /************************************************************************/ 166 /************************************************************************/
167 /* Range table operations */ 167 /* Range table operations */
168 /************************************************************************/ 168 /************************************************************************/
169 169
170 #ifdef ERROR_CHECK_TYPECHECK 170 #ifdef ERROR_CHECK_TYPECHECK
171 171
172 static void 172 static void
173 verify_range_table (struct Lisp_Range_Table *rt) 173 verify_range_table (Lisp_Range_Table *rt)
174 { 174 {
175 int i; 175 int i;
176 176
177 for (i = 0; i < Dynarr_length (rt->entries); i++) 177 for (i = 0; i < Dynarr_length (rt->entries); i++)
178 { 178 {
231 `remove-range-table', and `clear-range-table'. 231 `remove-range-table', and `clear-range-table'.
232 */ 232 */
233 ()) 233 ())
234 { 234 {
235 Lisp_Object obj; 235 Lisp_Object obj;
236 struct Lisp_Range_Table *rt = alloc_lcrecord_type (struct Lisp_Range_Table, 236 Lisp_Range_Table *rt = alloc_lcrecord_type (Lisp_Range_Table,
237 &lrecord_range_table); 237 &lrecord_range_table);
238 rt->entries = Dynarr_new (range_table_entry); 238 rt->entries = Dynarr_new (range_table_entry);
239 XSETRANGE_TABLE (obj, rt); 239 XSETRANGE_TABLE (obj, rt);
240 return obj; 240 return obj;
241 } 241 }
242 242
244 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
245 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.
246 */ 246 */
247 (old_table)) 247 (old_table))
248 { 248 {
249 struct Lisp_Range_Table *rt, *rtnew; 249 Lisp_Range_Table *rt, *rtnew;
250 Lisp_Object obj; 250 Lisp_Object obj;
251 251
252 CHECK_RANGE_TABLE (old_table); 252 CHECK_RANGE_TABLE (old_table);
253 rt = XRANGE_TABLE (old_table); 253 rt = XRANGE_TABLE (old_table);
254 254
255 rtnew = alloc_lcrecord_type (struct Lisp_Range_Table, &lrecord_range_table); 255 rtnew = alloc_lcrecord_type (Lisp_Range_Table, &lrecord_range_table);
256 rtnew->entries = Dynarr_new (range_table_entry); 256 rtnew->entries = Dynarr_new (range_table_entry);
257 257
258 Dynarr_add_many (rtnew->entries, Dynarr_atp (rt->entries, 0), 258 Dynarr_add_many (rtnew->entries, Dynarr_atp (rt->entries, 0),
259 Dynarr_length (rt->entries)); 259 Dynarr_length (rt->entries));
260 XSETRANGE_TABLE (obj, rtnew); 260 XSETRANGE_TABLE (obj, rtnew);
265 Find value for position POS in TABLE. 265 Find value for position POS in TABLE.
266 If there is no corresponding value, return DEFAULT (defaults to nil). 266 If there is no corresponding value, return DEFAULT (defaults to nil).
267 */ 267 */
268 (pos, table, default_)) 268 (pos, table, default_))
269 { 269 {
270 struct Lisp_Range_Table *rt; 270 Lisp_Range_Table *rt;
271 271
272 CHECK_RANGE_TABLE (table); 272 CHECK_RANGE_TABLE (table);
273 rt = XRANGE_TABLE (table); 273 rt = XRANGE_TABLE (table);
274 274
275 CHECK_INT_COERCE_CHAR (pos); 275 CHECK_INT_COERCE_CHAR (pos);
282 put_range_table (Lisp_Object table, EMACS_INT first, 282 put_range_table (Lisp_Object table, EMACS_INT first,
283 EMACS_INT last, Lisp_Object val) 283 EMACS_INT last, Lisp_Object val)
284 { 284 {
285 int i; 285 int i;
286 int insert_me_here = -1; 286 int insert_me_here = -1;
287 struct Lisp_Range_Table *rt = XRANGE_TABLE (table); 287 Lisp_Range_Table *rt = XRANGE_TABLE (table);
288 288
289 /* Now insert in the proper place. This gets tricky because 289 /* Now insert in the proper place. This gets tricky because
290 we may be overlapping one or more existing ranges and need 290 we may be overlapping one or more existing ranges and need
291 to fix them up. */ 291 to fix them up. */
292 292