Пример #1
0
AVL_NODE_TYPE*
AVL_PREFIXED(avl_find_interval_start)(AVL_CONST_TREE_TYPE* root, AVL_REFERENCE_TYPE obj_hash)
{
    const AVL_NODE_TYPE* node = *root;
    const AVL_NODE_TYPE* lower_bound = NULL;
    AVL_REFERENCE_TYPE h;
    
    zassert(node != NULL);

    /* This is one of the parts I could try to optimize
     * I've checked the assembly, and it sucks ...
     */

    /* Both the double-test while/ternary and the current one
     * are producing the same assembly code.
     */

    while(node != NULL)
    {
        h = AVL_REFERENCE(node);

        /*
         * [0] is the length of the obj_hash
         *
         * The obj_hashs starts at [1]
         *
         */

        int cmp = dnsname_compare(obj_hash, h);

        /* equals */
        if(cmp == 0)
        {
            return (AVL_NODE_TYPE*)node;
        }

        /* bigger */
        if(cmp > 0)
        {
            lower_bound = node;
            node = AVL_CHILD(node, DIR_RIGHT);
        }
        else
        {
            node = AVL_CHILD(node, DIR_LEFT);
        }
    }

        
    if(lower_bound == NULL)
    {
        lower_bound = *root;
        
        zassert(lower_bound != NULL);
        
        while((node = AVL_CHILD(lower_bound, DIR_RIGHT)) != NULL)
        {
            lower_bound = node;
        }
    }
    
    return (AVL_NODE_TYPE*)lower_bound;
}
Пример #2
0
AVL_NODE_TYPE*
AVL_PREFIXED(avl_find_prev_mod)(AVL_CONST_TREE_TYPE* root, const AVL_REFERENCE_TYPE obj_hash)
{
    AVL_NODE_TYPE* node = *root;
    AVL_NODE_TYPE* lower_bound = NULL;
    AVL_REFERENCE_TYPE h;
    
    yassert(node != NULL);

    /* This is one of the parts I could try to optimize
     * I've checked the assembly, and it sucks ...
     */

    /* Both the double-test while/ternary and the current one
     * are producing the same assembly code.
     */
    
    /**
     * Get a key that 
     */

    while(node != NULL)
    {
        h = AVL_REFERENCE(node);

        /*
         * [0] is the length of the obj_hash
         *
         * The obj_hashs starts at [1]
         *
         */

#ifdef DEBUG
        if(h[0] != obj_hash[0])
        {
            DIE_MSG("NSEC3 corrupted NSEC3 node");
        }
#endif

        int cmp = memcmp(&obj_hash[1], &h[1], h[0]);

        /* equals */
        if(cmp == 0)
        {
            // want the prev mod
            
            return nsec3_avl_node_mod_prev(node);
        }

        /* bigger */
        if(cmp > 0)
        {
            lower_bound = node;
            node = AVL_CHILD(node, DIR_RIGHT);            
        }
        else
        {
            node = AVL_CHILD(node, DIR_LEFT);
        }
    }
    
    if(lower_bound == NULL)
    {
        lower_bound = *root;
        
        yassert(lower_bound != NULL);
        
        while((node = AVL_CHILD(lower_bound, DIR_RIGHT)) != NULL)
        {
            lower_bound = node;
        }
    }
    
    return lower_bound;
}