comparison src/rangetab.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 8de8e3f6228a
children 576fb035e263
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
441 } 441 }
442 442
443 DEFUN ("map-range-table", Fmap_range_table, 2, 2, 0, /* 443 DEFUN ("map-range-table", Fmap_range_table, 2, 2, 0, /*
444 Map FUNCTION over entries in TABLE, calling it with three args, 444 Map FUNCTION over entries in TABLE, calling it with three args,
445 the beginning and end of the range and the corresponding value. 445 the beginning and end of the range and the corresponding value.
446
447 Results are guaranteed to be correct (i.e. each entry processed
448 exactly once) if FUNCTION modifies or deletes the current entry
449 (i.e. passes the current range to `put-range-table' or
450 `remove-range-table'), but not otherwise.
446 */ 451 */
447 (function, table)) 452 (function, table))
448 { 453 {
449 error ("not yet implemented"); 454 Lisp_Range_Table *rt;
455 int i;
456
457 CHECK_RANGE_TABLE (table);
458 CHECK_FUNCTION (function);
459
460 rt = XRANGE_TABLE (table);
461
462 /* Do not "optimize" by pulling out the length computation below!
463 FUNCTION may have changed the table. */
464 for (i = 0; i < Dynarr_length (rt->entries); i++)
465 {
466 struct range_table_entry *entry = Dynarr_atp (rt->entries, i);
467 EMACS_INT first, last;
468 Lisp_Object args[4];
469 int oldlen;
470
471 again:
472 first = entry->first;
473 last = entry->last;
474 oldlen = Dynarr_length (rt->entries);
475 args[0] = function;
476 args[1] = make_int (first);
477 args[2] = make_int (last);
478 args[3] = entry->val;
479 Ffuncall (countof (args), args);
480 /* Has FUNCTION removed the entry? */
481 if (oldlen > Dynarr_length (rt->entries)
482 && i < Dynarr_length (rt->entries)
483 && (first != entry->first || last != entry->last))
484 goto again;
485 }
486
450 return Qnil; 487 return Qnil;
451 } 488 }
452 489
453 490
454 /************************************************************************/ 491 /************************************************************************/
702 /************************************************************************/ 739 /************************************************************************/
703 740
704 void 741 void
705 syms_of_rangetab (void) 742 syms_of_rangetab (void)
706 { 743 {
744 INIT_LRECORD_IMPLEMENTATION (range_table);
745
707 defsymbol (&Qrange_tablep, "range-table-p"); 746 defsymbol (&Qrange_tablep, "range-table-p");
708 defsymbol (&Qrange_table, "range-table"); 747 defsymbol (&Qrange_table, "range-table");
709 748
710 DEFSUBR (Frange_table_p); 749 DEFSUBR (Frange_table_p);
711 DEFSUBR (Fmake_range_table); 750 DEFSUBR (Fmake_range_table);