-/**
- * \brief Find a suitable subrange of candidate duplicates for a given state
- * \param list dynamic array of states/pairs with candidate duplicates of the current state;
- * \param ref current state/pair;
- * \param min (output) index of the beginning of the the subrange
- * \param max (output) index of the enf of the subrange
- *
- * Given a suitably ordered array of states/pairs, this function extracts a subrange
- * (with index *min <= i <= *max) with candidate duplicates of the given state/pair.
- * This function uses only fast discriminating criterions and does not use the
- * full state/pair comparison algorithms.
- *
- * The states/pairs in list MUST be ordered using a (given) weak order
- * (based on nb_processes and heap_bytes_used).
- * The subrange is the subrange of "equivalence" of the given state/pair.
- */
-int get_search_interval(xbt_dynar_t list, void *ref, int *min, int *max)
-{
- int cursor = 0, previous_cursor;
- int nb_processes, heap_bytes_used, nb_processes_test, heap_bytes_used_test;
- void *ref_test;
-
- if (_sg_mc_liveness) {
- nb_processes = ((simgrid::mc::VisitedPair*) ref)->nb_processes;
- heap_bytes_used = ((simgrid::mc::VisitedPair*) ref)->heap_bytes_used;
- } else {
- nb_processes = ((mc_visited_state_t) ref)->nb_processes;
- heap_bytes_used = ((mc_visited_state_t) ref)->heap_bytes_used;
- }
-
- int start = 0;
- int end = xbt_dynar_length(list) - 1;
-
- while (start <= end) {
- cursor = (start + end) / 2;
- if (_sg_mc_liveness) {
- ref_test = (simgrid::mc::VisitedPair*) xbt_dynar_get_as(list, cursor, simgrid::mc::VisitedPair*);
- nb_processes_test = ((simgrid::mc::VisitedPair*) ref_test)->nb_processes;
- heap_bytes_used_test = ((simgrid::mc::VisitedPair*) ref_test)->heap_bytes_used;
- } else {
- ref_test = (mc_visited_state_t) xbt_dynar_get_as(list, cursor, mc_visited_state_t);
- nb_processes_test = ((mc_visited_state_t) ref_test)->nb_processes;
- heap_bytes_used_test = ((mc_visited_state_t) ref_test)->heap_bytes_used;
- }
- if (nb_processes_test < nb_processes)
- start = cursor + 1;
- else if (nb_processes_test > nb_processes)
- end = cursor - 1;
- else if (heap_bytes_used_test < heap_bytes_used)
- start = cursor + 1;
- else if (heap_bytes_used_test > heap_bytes_used)
- end = cursor - 1;
- else {
- *min = *max = cursor;
- previous_cursor = cursor - 1;
- while (previous_cursor >= 0) {
- if (_sg_mc_liveness) {
- ref_test = (simgrid::mc::VisitedPair*) xbt_dynar_get_as(list, previous_cursor, simgrid::mc::VisitedPair*);
- nb_processes_test = ((simgrid::mc::VisitedPair*) ref_test)->nb_processes;
- heap_bytes_used_test = ((simgrid::mc::VisitedPair*) ref_test)->heap_bytes_used;
- } else {
- ref_test = (mc_visited_state_t) xbt_dynar_get_as(list, previous_cursor, mc_visited_state_t);
- nb_processes_test = ((mc_visited_state_t) ref_test)->nb_processes;
- heap_bytes_used_test = ((mc_visited_state_t) ref_test)->heap_bytes_used;
- }
- if (nb_processes_test != nb_processes || heap_bytes_used_test != heap_bytes_used)
- break;
- *min = previous_cursor;
- previous_cursor--;
- }
- size_t next_cursor = cursor + 1;
- while (next_cursor < xbt_dynar_length(list)) {
- if (_sg_mc_liveness) {
- ref_test = (simgrid::mc::VisitedPair*) xbt_dynar_get_as(list, next_cursor, simgrid::mc::VisitedPair*);
- nb_processes_test = ((simgrid::mc::VisitedPair*) ref_test)->nb_processes;
- heap_bytes_used_test = ((simgrid::mc::VisitedPair*) ref_test)->heap_bytes_used;
- } else {
- ref_test = (mc_visited_state_t) xbt_dynar_get_as(list, next_cursor, mc_visited_state_t);
- nb_processes_test = ((mc_visited_state_t) ref_test)->nb_processes;
- heap_bytes_used_test = ((mc_visited_state_t) ref_test)->heap_bytes_used;
- }
- if (nb_processes_test != nb_processes || heap_bytes_used_test != heap_bytes_used)
- break;
- *max = next_cursor;
- next_cursor++;
- }
- return -1;
- }
- }
- return cursor;
-}
-
-static
-void replace_state(
- mc_visited_state_t state_test, mc_visited_state_t new_state, int cursor)
-{
- if (state_test->other_num == -1)
- new_state->other_num = state_test->num;
- else
- new_state->other_num = state_test->other_num;
-
- if (dot_output == nullptr)
- XBT_DEBUG("State %d already visited ! (equal to state %d)",
- new_state->num, state_test->num);
- else
- XBT_DEBUG(
- "State %d already visited ! (equal to state %d (state %d in dot_output))",
- new_state->num, state_test->num, new_state->other_num);
-
- /* Replace the old state with the new one (with a bigger num)
- (when the max number of visited states is reached, the oldest
- one is removed according to its number (= with the min number) */
- xbt_dynar_remove_at(visited_states, cursor, nullptr);
- xbt_dynar_insert_at(visited_states, cursor, &new_state);
- XBT_DEBUG("Replace visited state %d with the new visited state %d",
- state_test->num, new_state->num);
-}
-