CLDS_ST_HASH_SET_FIND_RESULT clds_st_hash_set_find()

in src/clds_st_hash_set.c [165:207]


CLDS_ST_HASH_SET_FIND_RESULT clds_st_hash_set_find(CLDS_ST_HASH_SET_HANDLE clds_st_hash_set, void* key)
{
    CLDS_ST_HASH_SET_FIND_RESULT result;

    if (
        (clds_st_hash_set == NULL) ||
        (key == NULL)
        )
    {
        LogError("Invalid arguments: CLDS_ST_HASH_SET_HANDLE clds_st_hash_set=%p, void* key=%p", clds_st_hash_set, key);
        result = CLDS_ST_HASH_SET_FIND_ERROR;
    }
    else
    {
        // compute the hash
        uint64_t hash = clds_st_hash_set->compute_hash_func(key);

        // find the bucket
        uint64_t bucket_index = hash % clds_st_hash_set->bucket_count;

        HASH_TABLE_ITEM* hash_table_item = clds_st_hash_set->hash_set[bucket_index];
        while (hash_table_item != NULL)
        {
            if (hash_table_item->key == key)
            {
                break;
            }

            hash_table_item = hash_table_item->next;
        }

        if (hash_table_item == NULL)
        {
            result = CLDS_ST_HASH_SET_FIND_NOT_FOUND;
        }
        else
        {
            result = CLDS_ST_HASH_SET_FIND_OK;
        }
    }

    return result;
}