comparison src/rangetab.c @ 444:576fb035e263 r21-2-37

Import from CVS: tag r21-2-37
author cvs
date Mon, 13 Aug 2007 11:36:19 +0200
parents abe6d1db359e
children 183866b06e0b
comparison
equal deleted inserted replaced
443:a8296e22da4e 444:576fb035e263
239 XSETRANGE_TABLE (obj, rt); 239 XSETRANGE_TABLE (obj, rt);
240 return obj; 240 return obj;
241 } 241 }
242 242
243 DEFUN ("copy-range-table", Fcopy_range_table, 1, 1, 0, /* 243 DEFUN ("copy-range-table", Fcopy_range_table, 1, 1, 0, /*
244 Make a new range table which contains the same values for the same 244 Return a new range table which is a copy of RANGE-TABLE.
245 ranges as the given table. The values will not themselves be copied. 245 It will contain the same values for the same ranges as RANGE-TABLE.
246 */ 246 The values will not themselves be copied.
247 (old_table)) 247 */
248 (range_table))
248 { 249 {
249 Lisp_Range_Table *rt, *rtnew; 250 Lisp_Range_Table *rt, *rtnew;
250 Lisp_Object obj; 251 Lisp_Object obj;
251 252
252 CHECK_RANGE_TABLE (old_table); 253 CHECK_RANGE_TABLE (range_table);
253 rt = XRANGE_TABLE (old_table); 254 rt = XRANGE_TABLE (range_table);
254 255
255 rtnew = alloc_lcrecord_type (Lisp_Range_Table, &lrecord_range_table); 256 rtnew = alloc_lcrecord_type (Lisp_Range_Table, &lrecord_range_table);
256 rtnew->entries = Dynarr_new (range_table_entry); 257 rtnew->entries = Dynarr_new (range_table_entry);
257 258
258 Dynarr_add_many (rtnew->entries, Dynarr_atp (rt->entries, 0), 259 Dynarr_add_many (rtnew->entries, Dynarr_atp (rt->entries, 0),
260 XSETRANGE_TABLE (obj, rtnew); 261 XSETRANGE_TABLE (obj, rtnew);
261 return obj; 262 return obj;
262 } 263 }
263 264
264 DEFUN ("get-range-table", Fget_range_table, 2, 3, 0, /* 265 DEFUN ("get-range-table", Fget_range_table, 2, 3, 0, /*
265 Find value for position POS in TABLE. 266 Find value for position POS in RANGE-TABLE.
266 If there is no corresponding value, return DEFAULT (defaults to nil). 267 If there is no corresponding value, return DEFAULT (defaults to nil).
267 */ 268 */
268 (pos, table, default_)) 269 (pos, range_table, default_))
269 { 270 {
270 Lisp_Range_Table *rt; 271 Lisp_Range_Table *rt;
271 272
272 CHECK_RANGE_TABLE (table); 273 CHECK_RANGE_TABLE (range_table);
273 rt = XRANGE_TABLE (table); 274 rt = XRANGE_TABLE (range_table);
274 275
275 CHECK_INT_COERCE_CHAR (pos); 276 CHECK_INT_COERCE_CHAR (pos);
276 277
277 return get_range_table (XINT (pos), Dynarr_length (rt->entries), 278 return get_range_table (XINT (pos), Dynarr_length (rt->entries),
278 Dynarr_atp (rt->entries, 0), default_); 279 Dynarr_atp (rt->entries, 0), default_);
401 } 402 }
402 } 403 }
403 } 404 }
404 405
405 DEFUN ("put-range-table", Fput_range_table, 4, 4, 0, /* 406 DEFUN ("put-range-table", Fput_range_table, 4, 4, 0, /*
406 Set the value for range (START, END) to be VAL in TABLE. 407 Set the value for range (START, END) to be VALUE in RANGE-TABLE.
407 */ 408 */
408 (start, end, val, table)) 409 (start, end, value, range_table))
409 { 410 {
410 EMACS_INT first, last; 411 EMACS_INT first, last;
411 412
412 CHECK_RANGE_TABLE (table); 413 CHECK_RANGE_TABLE (range_table);
413 CHECK_INT_COERCE_CHAR (start); 414 CHECK_INT_COERCE_CHAR (start);
414 first = XINT (start); 415 first = XINT (start);
415 CHECK_INT_COERCE_CHAR (end); 416 CHECK_INT_COERCE_CHAR (end);
416 last = XINT (end); 417 last = XINT (end);
417 if (first > last) 418 if (first > last)
418 signal_simple_error_2 ("start must be <= end", start, end); 419 signal_simple_error_2 ("start must be <= end", start, end);
419 420
420 put_range_table (table, first, last, val); 421 put_range_table (range_table, first, last, value);
421 verify_range_table (XRANGE_TABLE (table)); 422 verify_range_table (XRANGE_TABLE (range_table));
422 return Qnil; 423 return Qnil;
423 } 424 }
424 425
425 DEFUN ("remove-range-table", Fremove_range_table, 3, 3, 0, /* 426 DEFUN ("remove-range-table", Fremove_range_table, 3, 3, 0, /*
426 Remove the value for range (START, END) in TABLE. 427 Remove the value for range (START, END) in RANGE-TABLE.
427 */ 428 */
428 (start, end, table)) 429 (start, end, range_table))
429 { 430 {
430 return Fput_range_table (start, end, Qunbound, table); 431 return Fput_range_table (start, end, Qunbound, range_table);
431 } 432 }
432 433
433 DEFUN ("clear-range-table", Fclear_range_table, 1, 1, 0, /* 434 DEFUN ("clear-range-table", Fclear_range_table, 1, 1, 0, /*
434 Flush TABLE. 435 Flush RANGE-TABLE.
435 */ 436 */
436 (table)) 437 (range_table))
437 { 438 {
438 CHECK_RANGE_TABLE (table); 439 CHECK_RANGE_TABLE (range_table);
439 Dynarr_reset (XRANGE_TABLE (table)->entries); 440 Dynarr_reset (XRANGE_TABLE (range_table)->entries);
440 return Qnil; 441 return Qnil;
441 } 442 }
442 443
443 DEFUN ("map-range-table", Fmap_range_table, 2, 2, 0, /* 444 DEFUN ("map-range-table", Fmap_range_table, 2, 2, 0, /*
444 Map FUNCTION over entries in TABLE, calling it with three args, 445 Map FUNCTION over entries in RANGE-TABLE, calling it with three args,
445 the beginning and end of the range and the corresponding value. 446 the beginning and end of the range and the corresponding value.
446 447
447 Results are guaranteed to be correct (i.e. each entry processed 448 Results are guaranteed to be correct (i.e. each entry processed
448 exactly once) if FUNCTION modifies or deletes the current entry 449 exactly once) if FUNCTION modifies or deletes the current entry
449 (i.e. passes the current range to `put-range-table' or 450 \(i.e. passes the current range to `put-range-table' or
450 `remove-range-table'), but not otherwise. 451 `remove-range-table'), but not otherwise.
451 */ 452 */
452 (function, table)) 453 (function, range_table))
453 { 454 {
454 Lisp_Range_Table *rt; 455 Lisp_Range_Table *rt;
455 int i; 456 int i;
456 457
457 CHECK_RANGE_TABLE (table); 458 CHECK_RANGE_TABLE (range_table);
458 CHECK_FUNCTION (function); 459 CHECK_FUNCTION (function);
459 460
460 rt = XRANGE_TABLE (table); 461 rt = XRANGE_TABLE (range_table);
461 462
462 /* Do not "optimize" by pulling out the length computation below! 463 /* Do not "optimize" by pulling out the length computation below!
463 FUNCTION may have changed the table. */ 464 FUNCTION may have changed the table. */
464 for (i = 0; i < Dynarr_length (rt->entries); i++) 465 for (i = 0; i < Dynarr_length (rt->entries); i++)
465 { 466 {