/[emacs]/emacs/src/intervals.c
ViewVC logotype

Diff of /emacs/src/intervals.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.118 by lektu, Fri Oct 18 10:03:10 2002 UTC revision 1.119 by rms, Sun Apr 6 20:32:52 2003 UTC
# Line 75  create_root_interval (parent) Line 75  create_root_interval (parent)
75      {      {
76        new->total_length = (BUF_Z (XBUFFER (parent))        new->total_length = (BUF_Z (XBUFFER (parent))
77                             - BUF_BEG (XBUFFER (parent)));                             - BUF_BEG (XBUFFER (parent)));
78          CHECK_TOTAL_LENGTH (new);
79        BUF_INTERVALS (XBUFFER (parent)) = new;        BUF_INTERVALS (XBUFFER (parent)) = new;
80        new->position = 1;        new->position = 1;
81      }      }
82    else if (STRINGP (parent))    else if (STRINGP (parent))
83      {      {
84        new->total_length = SCHARS (parent);        new->total_length = SCHARS (parent);
85          CHECK_TOTAL_LENGTH (new);
86        STRING_SET_INTERVALS (parent, new);        STRING_SET_INTERVALS (parent, new);
87        new->position = 0;        new->position = 0;
88      }      }
# Line 338  rotate_right (interval) Line 340  rotate_right (interval)
340    
341    /* A's total length is decreased by the length of B and its left child.  */    /* A's total length is decreased by the length of B and its left child.  */
342    interval->total_length -= B->total_length - LEFT_TOTAL_LENGTH (interval);    interval->total_length -= B->total_length - LEFT_TOTAL_LENGTH (interval);
343      CHECK_TOTAL_LENGTH (interval);
344    
345    /* B must have the same total length of A.  */    /* B must have the same total length of A.  */
346    B->total_length = old_total;    B->total_length = old_total;
347      CHECK_TOTAL_LENGTH (B);
348    
349    return B;    return B;
350  }  }
# Line 384  rotate_left (interval) Line 388  rotate_left (interval)
388    
389    /* A's total length is decreased by the length of B and its right child.  */    /* A's total length is decreased by the length of B and its right child.  */
390    interval->total_length -= B->total_length - RIGHT_TOTAL_LENGTH (interval);    interval->total_length -= B->total_length - RIGHT_TOTAL_LENGTH (interval);
391      CHECK_TOTAL_LENGTH (interval);
392    
393    /* B must have the same total length of A.  */    /* B must have the same total length of A.  */
394    B->total_length = old_total;    B->total_length = old_total;
395      CHECK_TOTAL_LENGTH (B);
396    
397    return B;    return B;
398  }  }
# Line 405  balance_an_interval (i) Line 411  balance_an_interval (i)
411        old_diff = LEFT_TOTAL_LENGTH (i) - RIGHT_TOTAL_LENGTH (i);        old_diff = LEFT_TOTAL_LENGTH (i) - RIGHT_TOTAL_LENGTH (i);
412        if (old_diff > 0)        if (old_diff > 0)
413          {          {
414              /* Since the left child is longer, there must be one.  */
415            new_diff = i->total_length - i->left->total_length            new_diff = i->total_length - i->left->total_length
416              + RIGHT_TOTAL_LENGTH (i->left) - LEFT_TOTAL_LENGTH (i->left);              + RIGHT_TOTAL_LENGTH (i->left) - LEFT_TOTAL_LENGTH (i->left);
417            if (abs (new_diff) >= old_diff)            if (abs (new_diff) >= old_diff)
# Line 414  balance_an_interval (i) Line 421  balance_an_interval (i)
421          }          }
422        else if (old_diff < 0)        else if (old_diff < 0)
423          {          {
424              /* Since the right child is longer, there must be one.  */
425            new_diff = i->total_length - i->right->total_length            new_diff = i->total_length - i->right->total_length
426              + LEFT_TOTAL_LENGTH (i->right) - RIGHT_TOTAL_LENGTH (i->right);              + LEFT_TOTAL_LENGTH (i->right) - RIGHT_TOTAL_LENGTH (i->right);
427            if (abs (new_diff) >= -old_diff)            if (abs (new_diff) >= -old_diff)
# Line 514  split_interval_right (interval, offset) Line 522  split_interval_right (interval, offset)
522      {      {
523        interval->right = new;        interval->right = new;
524        new->total_length = new_length;        new->total_length = new_length;
525          CHECK_TOTAL_LENGTH (new);
526      }      }
527    else    else
528      {      {
# Line 522  split_interval_right (interval, offset) Line 531  split_interval_right (interval, offset)
531        SET_INTERVAL_PARENT (interval->right, new);        SET_INTERVAL_PARENT (interval->right, new);
532        interval->right = new;        interval->right = new;
533        new->total_length = new_length + new->right->total_length;        new->total_length = new_length + new->right->total_length;
534          CHECK_TOTAL_LENGTH (new);
535        balance_an_interval (new);        balance_an_interval (new);
536      }      }
537    
# Line 559  split_interval_left (interval, offset) Line 569  split_interval_left (interval, offset)
569      {      {
570        interval->left = new;        interval->left = new;
571        new->total_length = new_length;        new->total_length = new_length;
572          CHECK_TOTAL_LENGTH (new);
573      }      }
574    else    else
575      {      {
# Line 567  split_interval_left (interval, offset) Line 578  split_interval_left (interval, offset)
578        SET_INTERVAL_PARENT (new->left, new);        SET_INTERVAL_PARENT (new->left, new);
579        interval->left = new;        interval->left = new;
580        new->total_length = new_length + new->left->total_length;        new->total_length = new_length + new->left->total_length;
581          CHECK_TOTAL_LENGTH (new);
582        balance_an_interval (new);        balance_an_interval (new);
583      }      }
584    
# Line 828  adjust_intervals_for_insertion (tree, po Line 840  adjust_intervals_for_insertion (tree, po
840        if (relative_position <= LEFT_TOTAL_LENGTH (this))        if (relative_position <= LEFT_TOTAL_LENGTH (this))
841          {          {
842            this->total_length += length;            this->total_length += length;
843              CHECK_TOTAL_LENGTH (this);
844            this = this->left;            this = this->left;
845          }          }
846        else if (relative_position > (TOTAL_LENGTH (this)        else if (relative_position > (TOTAL_LENGTH (this)
# Line 836  adjust_intervals_for_insertion (tree, po Line 849  adjust_intervals_for_insertion (tree, po
849            relative_position -= (TOTAL_LENGTH (this)            relative_position -= (TOTAL_LENGTH (this)
850                                  - RIGHT_TOTAL_LENGTH (this));                                  - RIGHT_TOTAL_LENGTH (this));
851            this->total_length += length;            this->total_length += length;
852              CHECK_TOTAL_LENGTH (this);
853            this = this->right;            this = this->right;
854          }          }
855        else        else
# Line 843  adjust_intervals_for_insertion (tree, po Line 857  adjust_intervals_for_insertion (tree, po
857            /* If we are to use zero-length intervals as buffer pointers,            /* If we are to use zero-length intervals as buffer pointers,
858               then this code will have to change.  */               then this code will have to change.  */
859            this->total_length += length;            this->total_length += length;
860              CHECK_TOTAL_LENGTH (this);
861            this->position = LEFT_TOTAL_LENGTH (this)            this->position = LEFT_TOTAL_LENGTH (this)
862                             + position - relative_position + 1;                             + position - relative_position + 1;
863            return tree;            return tree;
# Line 987  adjust_intervals_for_insertion (tree, po Line 1002  adjust_intervals_for_insertion (tree, po
1002        for (temp = prev ? prev : i; temp; temp = INTERVAL_PARENT_OR_NULL (temp))        for (temp = prev ? prev : i; temp; temp = INTERVAL_PARENT_OR_NULL (temp))
1003          {          {
1004            temp->total_length += length;            temp->total_length += length;
1005              CHECK_TOTAL_LENGTH (temp);
1006            temp = balance_possible_root_interval (temp);            temp = balance_possible_root_interval (temp);
1007          }          }
1008    
# Line 1043  adjust_intervals_for_insertion (tree, po Line 1059  adjust_intervals_for_insertion (tree, po
1059        for (temp = i; temp; temp = INTERVAL_PARENT_OR_NULL (temp))        for (temp = i; temp; temp = INTERVAL_PARENT_OR_NULL (temp))
1060          {          {
1061            temp->total_length += length;            temp->total_length += length;
1062              CHECK_TOTAL_LENGTH (temp);
1063            temp = balance_possible_root_interval (temp);            temp = balance_possible_root_interval (temp);
1064          }          }
1065      }      }
# Line 1247  delete_node (i) Line 1264  delete_node (i)
1264        this = this->left;        this = this->left;
1265        this->total_length += migrate_amt;        this->total_length += migrate_amt;
1266      }      }
1267      CHECK_TOTAL_LENGTH (this);
1268    this->left = migrate;    this->left = migrate;
1269    SET_INTERVAL_PARENT (migrate, this);    SET_INTERVAL_PARENT (migrate, this);
1270    
# Line 1331  interval_deletion_adjustment (tree, from Line 1349  interval_deletion_adjustment (tree, from
1349                                                     relative_position,                                                     relative_position,
1350                                                     amount);                                                     amount);
1351        tree->total_length -= subtract;        tree->total_length -= subtract;
1352          CHECK_TOTAL_LENGTH (tree);
1353        return subtract;        return subtract;
1354      }      }
1355    /* Right branch */    /* Right branch */
# Line 1345  interval_deletion_adjustment (tree, from Line 1364  interval_deletion_adjustment (tree, from
1364                                                 relative_position,                                                 relative_position,
1365                                                 amount);                                                 amount);
1366        tree->total_length -= subtract;        tree->total_length -= subtract;
1367          CHECK_TOTAL_LENGTH (tree);
1368        return subtract;        return subtract;
1369      }      }
1370    /* Here -- this node.  */    /* Here -- this node.  */
# Line 1359  interval_deletion_adjustment (tree, from Line 1379  interval_deletion_adjustment (tree, from
1379          amount = my_amount;          amount = my_amount;
1380    
1381        tree->total_length -= amount;        tree->total_length -= amount;
1382          CHECK_TOTAL_LENGTH (tree);
1383        if (LENGTH (tree) == 0)        if (LENGTH (tree) == 0)
1384          delete_interval (tree);          delete_interval (tree);
1385    
# Line 1402  adjust_intervals_for_deletion (buffer, s Line 1423  adjust_intervals_for_deletion (buffer, s
1423    if (ONLY_INTERVAL_P (tree))    if (ONLY_INTERVAL_P (tree))
1424      {      {
1425        tree->total_length -= length;        tree->total_length -= length;
1426          CHECK_TOTAL_LENGTH (tree);
1427        return;        return;
1428      }      }
1429    
# Line 1457  merge_interval_right (i) Line 1479  merge_interval_right (i)
1479    
1480    /* Zero out this interval.  */    /* Zero out this interval.  */
1481    i->total_length -= absorb;    i->total_length -= absorb;
1482      CHECK_TOTAL_LENGTH (i);
1483    
1484    /* Find the succeeding interval.  */    /* Find the succeeding interval.  */
1485    if (! NULL_RIGHT_CHILD (i))      /* It's below us.  Add absorb    if (! NULL_RIGHT_CHILD (i))      /* It's below us.  Add absorb
# Line 1466  merge_interval_right (i) Line 1489  merge_interval_right (i)
1489        while (! NULL_LEFT_CHILD (successor))        while (! NULL_LEFT_CHILD (successor))
1490          {          {
1491            successor->total_length += absorb;            successor->total_length += absorb;
1492              CHECK_TOTAL_LENGTH (successor);
1493            successor = successor->left;            successor = successor->left;
1494          }          }
1495    
1496        successor->total_length += absorb;        successor->total_length += absorb;
1497          CHECK_TOTAL_LENGTH (successor);
1498        delete_interval (i);        delete_interval (i);
1499        return successor;        return successor;
1500      }      }
# Line 1487  merge_interval_right (i) Line 1512  merge_interval_right (i)
1512    
1513        successor = INTERVAL_PARENT (successor);        successor = INTERVAL_PARENT (successor);
1514        successor->total_length -= absorb;        successor->total_length -= absorb;
1515          CHECK_TOTAL_LENGTH (successor);
1516      }      }
1517    
1518    /* This must be the rightmost or last interval and cannot    /* This must be the rightmost or last interval and cannot
# Line 1510  merge_interval_left (i) Line 1536  merge_interval_left (i)
1536    
1537    /* Zero out this interval.  */    /* Zero out this interval.  */
1538    i->total_length -= absorb;    i->total_length -= absorb;
1539      CHECK_TOTAL_LENGTH (i);
1540    
1541    /* Find the preceding interval.  */    /* Find the preceding interval.  */
1542    if (! NULL_LEFT_CHILD (i))    /* It's below us. Go down,    if (! NULL_LEFT_CHILD (i))    /* It's below us. Go down,
# Line 1519  merge_interval_left (i) Line 1546  merge_interval_left (i)
1546        while (! NULL_RIGHT_CHILD (predecessor))        while (! NULL_RIGHT_CHILD (predecessor))
1547          {          {
1548            predecessor->total_length += absorb;            predecessor->total_length += absorb;
1549              CHECK_TOTAL_LENGTH (predecessor);
1550            predecessor = predecessor->right;            predecessor = predecessor->right;
1551          }          }
1552    
1553        predecessor->total_length += absorb;        predecessor->total_length += absorb;
1554          CHECK_TOTAL_LENGTH (predecessor);
1555        delete_interval (i);        delete_interval (i);
1556        return predecessor;        return predecessor;
1557      }      }
# Line 1540  merge_interval_left (i) Line 1569  merge_interval_left (i)
1569    
1570        predecessor = INTERVAL_PARENT (predecessor);        predecessor = INTERVAL_PARENT (predecessor);
1571        predecessor->total_length -= absorb;        predecessor->total_length -= absorb;
1572          CHECK_TOTAL_LENGTH (predecessor);
1573      }      }
1574    
1575    /* This must be the leftmost or first interval and cannot    /* This must be the leftmost or first interval and cannot
# Line 2354  copy_intervals (tree, start, length) Line 2384  copy_intervals (tree, start, length)
2384    new->position = 0;    new->position = 0;
2385    got = (LENGTH (i) - (start - i->position));    got = (LENGTH (i) - (start - i->position));
2386    new->total_length = length;    new->total_length = length;
2387      CHECK_TOTAL_LENGTH (new);
2388    copy_properties (i, new);    copy_properties (i, new);
2389    
2390    t = new;    t = new;
# Line 2440  set_intervals_multibyte_1 (i, multi_flag Line 2471  set_intervals_multibyte_1 (i, multi_flag
2471      i->total_length = end - start;      i->total_length = end - start;
2472    else    else
2473      i->total_length = end_byte - start_byte;      i->total_length = end_byte - start_byte;
2474      CHECK_TOTAL_LENGTH (i);
2475    
2476      if (TOTAL_LENGTH (i) == 0)
2477        {
2478          delete_interval (i);
2479          return;
2480        }
2481    
2482    /* Recursively fix the length of the subintervals.  */    /* Recursively fix the length of the subintervals.  */
2483    if (i->left)    if (i->left)
# Line 2448  set_intervals_multibyte_1 (i, multi_flag Line 2486  set_intervals_multibyte_1 (i, multi_flag
2486    
2487        if (multi_flag)        if (multi_flag)
2488          {          {
2489              int temp;
2490            left_end_byte = start_byte + LEFT_TOTAL_LENGTH (i);            left_end_byte = start_byte + LEFT_TOTAL_LENGTH (i);
2491            left_end = BYTE_TO_CHAR (left_end_byte);            left_end = BYTE_TO_CHAR (left_end_byte);
2492    
2493              temp = CHAR_TO_BYTE (left_end);
2494    
2495              /* If LEFT_END_BYTE is in the middle of a character,
2496                 adjust it and LEFT_END to a char boundary.  */
2497              if (left_end_byte > temp)
2498                {
2499                  left_end_byte = temp;
2500                }
2501              if (left_end_byte < temp)
2502                {
2503                  left_end--;
2504                  left_end_byte = CHAR_TO_BYTE (left_end);
2505                }
2506          }          }
2507        else        else
2508          {          {
# Line 2466  set_intervals_multibyte_1 (i, multi_flag Line 2519  set_intervals_multibyte_1 (i, multi_flag
2519    
2520        if (multi_flag)        if (multi_flag)
2521          {          {
2522              int temp;
2523    
2524            right_start_byte = end_byte - RIGHT_TOTAL_LENGTH (i);            right_start_byte = end_byte - RIGHT_TOTAL_LENGTH (i);
2525            right_start = BYTE_TO_CHAR (right_start_byte);            right_start = BYTE_TO_CHAR (right_start_byte);
2526    
2527              /* If RIGHT_START_BYTE is in the middle of a character,
2528                 adjust it and RIGHT_START to a char boundary.  */
2529              temp = CHAR_TO_BYTE (right_start);
2530    
2531              if (right_start_byte < temp)
2532                {
2533                  right_start_byte = temp;
2534                }
2535              if (right_start_byte > temp)
2536                {
2537                  right_start++;
2538                  right_start_byte = CHAR_TO_BYTE (right_start);
2539                }
2540          }          }
2541        else        else
2542          {          {
# Line 2479  set_intervals_multibyte_1 (i, multi_flag Line 2548  set_intervals_multibyte_1 (i, multi_flag
2548                                   right_start, right_start_byte,                                   right_start, right_start_byte,
2549                                   end, end_byte);                                   end, end_byte);
2550      }      }
2551    
2552      /* Rounding to char boundaries can theoretically ake this interval
2553         spurious.  If so, delete one child, and copy its property list
2554         to this interval.  */
2555      if (LEFT_TOTAL_LENGTH (i) + RIGHT_TOTAL_LENGTH (i) >= TOTAL_LENGTH (i))
2556        {
2557          if ((i)->left)
2558            {
2559              (i)->plist = (i)->left->plist;
2560              (i)->left->total_length = 0;
2561              delete_interval ((i)->left);
2562            }
2563          else
2564            {
2565              (i)->plist = (i)->right->plist;
2566              (i)->right->total_length = 0;
2567              delete_interval ((i)->right);
2568            }
2569        }
2570  }  }
2571    
2572  /* Update the intervals of the current buffer  /* Update the intervals of the current buffer

Legend:
Removed from v.1.118  
changed lines
  Added in v.1.119

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26