Ejemplo n.º 1
0
static void insert_register( char *name, enum special_reg r ) {
    insert_into_trie(name, 0, r, 2);
}
int find_max_xor_two_numbers_in_array_v2 (int* array, int len)
{
    int index, bit_index, max_xor, num_max_xor, link;
    struct trienode* root = NULL;
    struct trienode* current;

    if (!array || (len <= 1)) {
        return(0);
    }

    init_trie(&root);

    if (!root) {
        return(0);
    }

    for (index = 0; index < len; ++index) {
        insert_into_trie(root, array[index]);
    }

    max_xor = 0;
    for (index = 0; index < len; ++index) {

        current = root;
        num_max_xor = array[index];

        for (bit_index = sizeof(int) * CHAR_BIT - 1;
             bit_index >= 0; --bit_index) {

            if (array[index] & (1 << bit_index)) {
                link = 1;
            } else {
                link = 0;
            }

            if (link == 0) {
                if (!current->links[1]) {
                    num_max_xor &= ~(1 << bit_index);
                    current = current->links[0];
                } else {
                    num_max_xor |= (1 << bit_index);
                    current = current->links[1];
                }
            } else {
                if (!current->links[0]) {
                    num_max_xor &= ~(1 << bit_index);
                    current = current->links[1];
                } else {
                    num_max_xor |= (1 << bit_index);
                    current = current->links[0];
                }
            }
        }

        if (num_max_xor > max_xor) {
            max_xor = num_max_xor;
        }
    }

    free_trie(root);

    return(max_xor);
}
Ejemplo n.º 3
0
static void insert_token( char *name, enum token t ) {
    insert_into_trie(name, t, 0, 1);
}