Exemplo n.º 1
0
hash_t string_hash(string_t *str)
{
    if (!str->buf)
        return 0;

    return string_hash_imp(str->buf);
}
Exemplo n.º 2
0
hash_t obj_hash(obj_ptr obj)
{
    switch (TYPE(obj))
    {
    case TYPE_INT:
    case TYPE_BOOL:
        return (hash_t) INT(obj);

    case TYPE_SYMBOL:
        return string_hash_imp(SYMBOL(obj));
            
    case TYPE_STRING:
        return string_hash(&STRING(obj));

    case TYPE_CONS:
    {
        hash_t res = 0;

        for (;;)
        {
            if (NTYPEP(obj, TYPE_CONS))
            {
                res += obj_hash(obj);
                break;
            }

            res += obj_hash(CAR(obj));
            obj = CDR(obj);
        }

        return res;
    }

    case TYPE_VEC:
        return vec_hash(&obj->data.as_vec);

    /* These types shouldn't be keys anyway ... */
    case TYPE_FLOAT:
        assert(TYPE(obj) != TYPE_FLOAT);
        break;
    case TYPE_MAP:
        assert(TYPE(obj) != TYPE_MAP);
        break;
    case TYPE_CLOSURE:
        assert(TYPE(obj) != TYPE_CLOSURE);
        break;
    case TYPE_PRIMITIVE:
        assert(TYPE(obj) != TYPE_PRIMITIVE);
        break;
    case TYPE_ERROR:
        assert(TYPE(obj) != TYPE_ERROR);
        break;
    case TYPE_PORT:
        assert(TYPE(obj) != TYPE_PORT);
        break;
    }

    return 0;
}
Exemplo n.º 3
0
int string_hash(string_ptr str)
{
    return string_hash_imp(str->buf);
}