src/or/consdiff.c
static void
calc_changes(smartlist_slice_t *slice1, smartlist_slice_t *slice2,
             bitarray_t *changed1, bitarray_t *changed2)
{
  trim_slices(slice1, slice2);

  if (slice1->len <= 1) {
    set_changed(changed1, changed2, slice1, slice2);

  } else if (slice2->len <= 1) {
    set_changed(changed2, changed1, slice2, slice1);

  /* Keep on splitting the slices in two. */
  } else {

    smartlist_slice_t *top, *bot, *left, *right;

    /* Split the first slice in half. */
    int mid = slice1->len/2;
    top = smartlist_slice(slice1->list, slice1->offset, slice1->offset+mid);
    bot = smartlist_slice(slice1->list, slice1->offset+mid,
        slice1->offset+slice1->len);

    /* Split the second slice by the optimal column. */
    int mid2 = optimal_column_to_split(top, bot, slice2);
    left = smartlist_slice(slice2->list, slice2->offset, slice2->offset+mid2);
    right = smartlist_slice(slice2->list, slice2->offset+mid2,
        slice2->offset+slice2->len);

    calc_changes(top, left, changed1, changed2);
    calc_changes(bot, right, changed1, changed2);
    tor_free(top);
    tor_free(bot);
    tor_free(left);
    tor_free(right);
  }
}
/**
 * Helper: Figure out what elements are new or gone on the second smartlist
 * relative to the first smartlist, and store the booleans in the bitarrays.
 * True on the first bitarray means the element is gone, true on the second
 * bitarray means it's new.
 *
 * In its base case, either of the smartlists is of length <= 1 and we can
 * quickly see what elements are new or are gone. In the other case, we will
 * split one smartlist by half and we'll use optimal_column_to_split to find
 * the optimal column at which to split the second smartlist so that we are
 * finding the smallest diff possible.
 */
Figure out what elements are new or gone on the second smartlist
relative to the first smartlist, and store the booleans in the bitarrays.
True on the first bitarray means the element is gone, true on the second
bitarray means it's new.

In its base case, either of the smartlists is of length <= 1 and we can
quickly see what elements are new or are gone. In the other case, we will
split one smartlist by half and we'll use optimal_column_to_split to find
the optimal column at which to split the second smartlist so that we are
finding the smallest diff possible.
Figure out what elements are new or gone on the second smartlist relative to the first smartlist and store the booleans in the bitarrays . True on the first bitarray means the element is gone true on the second bitarray means it ' s new . In its base case either of the smartlists is of length < = 1 and we can quickly see what elements are new or are gone . In the other case we will split one smartlist by half and we ' ll use optimal_column_to_split to find the optimal column at which to split the second smartlist so that we are finding the smallest diff possible .
static void
calc_changes(smartlist_slice_t *slice1, smartlist_slice_t *slice2,
             bitarray_t *changed1, bitarray_t *changed2)
{
  trim_slices(slice1, slice2);
  if (slice1->len <= 1) {
    set_changed(changed1, changed2, slice1, slice2);
  } else if (slice2->len <= 1) {
    set_changed(changed2, changed1, slice2, slice1);
  } else {
    smartlist_slice_t *top, *bot, *left, *right;
    int mid = slice1->len/2;
    top = smartlist_slice(slice1->list, slice1->offset, slice1->offset+mid);
    bot = smartlist_slice(slice1->list, slice1->offset+mid,
        slice1->offset+slice1->len);
    int mid2 = optimal_column_to_split(top, bot, slice2);
    left = smartlist_slice(slice2->list, slice2->offset, slice2->offset+mid2);
    right = smartlist_slice(slice2->list, slice2->offset+mid2,
        slice2->offset+slice2->len);
    calc_changes(top, left, changed1, changed2);
    calc_changes(bot, right, changed1, changed2);
    tor_free(top);
    tor_free(bot);
    tor_free(left);
    tor_free(right);
  }
}
static void calc_changes ( smartlist_slice_t * slice1 , smartlist_slice_t * slice2 , bitarray_t * changed1 , bitarray_t * changed2 ) { trim_slices ( slice1 , slice2 ) ; if ( slice1 -> len <= 1 ) { set_changed ( changed1 , changed2 , slice1 , slice2 ) ; } else if ( slice2 -> len <= 1 ) { set_changed ( changed2 , changed1 , slice2 , slice1 ) ; } else { smartlist_slice_t * top , * bot , * left , * right ; int mid = slice1 -> len / 2 ; top = smartlist_slice ( slice1 -> list , slice1 -> offset , slice1 -> offset + mid ) ; bot = smartlist_slice ( slice1 -> list , slice1 -> offset + mid , slice1 -> offset + slice1 -> len ) ; int mid2 = optimal_column_to_split ( top , bot , slice2 ) ; left = smartlist_slice ( slice2 -> list , slice2 -> offset , slice2 -> offset + mid2 ) ; right = smartlist_slice ( slice2 -> list , slice2 -> offset + mid2 , slice2 -> offset + slice2 -> len ) ; calc_changes ( top , left , changed1 , changed2 ) ; calc_changes ( bot , right , changed1 , changed2 ) ; tor_free ( top ) ; tor_free ( bot ) ; tor_free ( left ) ; tor_free ( right ) ; } }
Helper: Figure out what elements are new or gone on the second smartlist
 relative to the first smartlist, and store the booleans in the bitarrays.
Helper : Figure out what elements are new or gone on the second smartlist relative to the first smartlist and store the booleans in the bitarrays .
/* Keep on splitting the slices in two. */ /* Split the first slice in half. */ /* Split the second slice by the optimal column. */