Why subtraction is used to compare in nginx_rbtree.c?

张奕普 firstawhois at gmail.com
Tue Mar 24 07:39:23 UTC 2015


When I study the rbtree of nginx I can't understand the comments. Can
someone give me a concrete example?Thanks :)

 for ( ;; ) {

        /*
         * Timer values
         * 1) are spread in small range, usually several minutes,
         * 2) and overflow each 49 days, if milliseconds are stored in 32
bits.
         * The comparison takes into account that overflow.
         */

        /*  node->key < temp->key */

        p = ((ngx_rbtree_key_int_t) (node->key - temp->key) < 0)
            ? &temp->left : &temp->right;

        if (*p == sentinel) {
            break;
        }

        temp = *p;
    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20150324/d1d489f9/attachment-0001.html>


More information about the nginx mailing list