// check whether the subtree rooted at x is ordered static bool is_ordered(rba_buffer_t *b, uint32_t x) { uint32_t i, j; pprod_t *r, *s, *t; assert(x < b->num_nodes); if (x == 0) return true; i = b->child[x][0]; // left child j = b->child[x][1]; // right child r = b->mono[x].prod; s = b->mono[i].prod; t = b->mono[j].prod; // the expected order is s < r < t if (i != 0 && !pprod_precedes(s, r)) { printf("tree not ordered at node %"PRIu32" (for left child %"PRIu32")\n", x, i); fflush(stdout); return false; } if (j != 0 && !pprod_precedes(r, t)) { printf("tree not ordered at node %"PRIu32" (for right child = %"PRIu32")\n", x, j); fflush(stdout); return false; } return is_ordered(b, i) && is_ordered(b, j); }
void quicksort(t_env *env) { t_elem *tmp; while (!is_ordered(env)) { env->pivot = choose_pivot(env); while (env->a_start->value < env->pivot) pushing_to_b(env); while (1) { tmp = env->a_start; while (tmp && tmp->value >= env->pivot) tmp = tmp->next; if (!tmp) break ; while (env->a_start->value < env->pivot) pushing_to_b(env); if (env->a_start->next && ASTA > ANEX && ANEX > env->pivot) move_sa(env); (!is_ordered(env)) ? move_ra(env) : 0; } } optimize_order(env); while (env->b_start) move_pa(env); }
bool is_ordered(tree* T, elem lower, elem upper, bst B) { if (T == NULL) return true; return T->data != NULL && (lower == NULL || B->elem_compare(lower, T->data) < 0) && (upper == NULL || B->elem_compare(T->data, upper) < 0) && is_ordered(T->left, lower, T->data, B) && is_ordered(T->right, T->data, upper, B); }
int alphabet_score(std::vector<std::string> const& words, alphabet_t const& alpabet) { return std::count_if( words.begin(), words.end(), [&alpabet](std::string const& word) { return is_ordered(word, alpabet); } ); }
/*override*/void* operator()( void* item ) { Harness::ConcurrencyTracker ct; if( is_serial() ) ASSERT( !my_is_running, "premature entry to serial stage" ); my_is_running = true; Buffer* b = get_buffer(item); if( b ) { if( is_ordered() ) { if( b->sequence_number == Buffer::unused ) b->sequence_number = current_token-1; else ASSERT( b->sequence_number==current_token-1, "item arrived out of order" ); } else if( is_serial() ) { if( b->sequence_number != current_token-1 && b->sequence_number != Buffer::unused ) out_of_order_count++; } ASSERT( b->id < StreamSize, NULL ); ASSERT( !my_done[b->id], "duplicate processing of token?" ); ASSERT( b->is_busy, NULL ); my_done[b->id] = true; if( my_is_last ) { b->id = Buffer::unused; b->sequence_number = Buffer::unused; __TBB_store_with_release(b->is_busy, false); } } my_is_running = false; return b; }
int main(int argc, char **argv) { t_pretty *first; t_pretty *second; int data; int index; error_handling(argc, argv); index = 2; first = new_node(ft_atoi(argv[1])); while (index < argc) { data = ft_atoi(argv[index]); add_node(first, data); index++; } if (is_ordered(first)) { ft_putstr("\n"); return (0); } fill_second(first, &second); filler(second); first = second; ft_putstr("\n"); return (0); }
bool ValueFilter::validate() const { if (mask == 0) { return false; } if ((mask & (1 << LT)) && (mask & (1 << LE))) { return false; } if ((mask & (1 << GT)) && (mask & (1 << GE))) { return false; } return is_ordered(); }
// ordering constraints for the full tree static bool tree_is_ordered(rba_buffer_t *b) { return is_ordered(b, b->root); }
bool is_tree(tree* T, bst B) { return is_ordered(T, NULL, NULL, B) && is_specified_height(T) && is_balanced(T); }