list.c
int list_lookup(atom_t* obj, atom_t* item, int* idx) {
    list_assert(obj, "list_lookup");
    *idx = 0;

    if (!list_len(obj))  // list is empty
        return 0;

    atom_t** items = obj->val.list->items;
    int hit = 0, left = 1, right = list_len(obj);

    while (left <= right) {
        *idx = left + ((right - left) >> 1);
        if (items[*idx-1] > item) {
            if ((right = *idx - 1) < left) {
                (*idx)--;
                break;
            }
        } else if (items[*idx-1] < item) {
            left = *idx + 1;
        } else {
            hit = 1;
            (*idx)--;
            break;
        }
    }

    return hit;
}
/*
--------------------------------------
list_lookup

    Object lookup in a SORTED list.
    Returns 1 if object is found, 0 otherwise. Leaves index in *idx.
--------------------------------------
*/
list_lookup
Object lookup in a SORTED list.
Returns 1 if object is found, 0 otherwise. Leaves index in *idx.
list_lookup Object lookup in a SORTED list . Returns 1 if object is found 0 otherwise . Leaves index in * idx .
int list_lookup(atom_t* obj, atom_t* item, int* idx) {
    list_assert(obj, "list_lookup");
    *idx = 0;
    if (!list_len(obj))  
        return 0;
    atom_t** items = obj->val.list->items;
    int hit = 0, left = 1, right = list_len(obj);
    while (left <= right) {
        *idx = left + ((right - left) >> 1);
        if (items[*idx-1] > item) {
            if ((right = *idx - 1) < left) {
                (*idx)--;
                break;
            }
        } else if (items[*idx-1] < item) {
            left = *idx + 1;
        } else {
            hit = 1;
            (*idx)--;
            break;
        }
    }
    return hit;
}
int list_lookup ( atom_t * obj , atom_t * item , int * idx ) { list_assert ( obj , " " ) ; * idx = 0 ; if ( ! list_len ( obj ) ) return 0 ; atom_t * * items = obj -> val . list -> items ; int hit = 0 , left = 1 , right = list_len ( obj ) ; while ( left <= right ) { * idx = left + ( ( right - left ) >> 1 ) ; if ( items [ * idx - 1 ] > item ) { if ( ( right = * idx - 1 ) < left ) { ( * idx ) -- ; break ; } } else if ( items [ * idx - 1 ] < item ) { left = * idx + 1 ; } else { hit = 1 ; ( * idx ) -- ; break ; } } return hit ; }
list_lookup
Object lookup in a SORTED list.
list_lookup Object lookup in a SORTED list .
// list is empty