⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phb_se.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 5 页
字号:
    }
}   /* end of phb_se_delete */


/*****************************************************************************
 * FUNCTION
 *  phb_se_search_by_record_index_name
 * DESCRIPTION
 *  Find a exact match of record index, using name to speed up searching.
 *  
 *  If alpha_id is NULL, this function performs linear searching
 *  on name_num_index to look up given record_index.
 * PARAMETERS
 *  type                [IN]        
 *  storage             [IN]        
 *  record_index        [IN]        
 *  alpha_id            [?]         
 * RETURNS
 *  Index (to name_index) of matched record_index.
 *****************************************************************************/
kal_uint16 phb_se_search_by_record_index_name(
            phb_type_enum type,
            phb_storage_enum storage,
            kal_uint16 record_index,
            alpha_id_type *alpha_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    name_num_index_type *name_num_index;
    compare_result_type result;

    kal_uint8 len = 0;
    kal_uint16 candidate_index;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_SE_SEARCH_BY_RECORD_INDEX_NAME);

#ifdef __PHB_SORT_ENABLE__
    if (type == PHB_PHONEBOOK)
    {
        name_num_index = &phb_ptr->indices.phb_index;
    }
    else if (type == PHB_FDN)
#else /* __PHB_SORT_ENABLE__ */ 
    if (type == PHB_FDN)
#endif /* __PHB_SORT_ENABLE__ */ 
        name_num_index = &phb_ptr->indices.fdn_index;
    else if (type == PHB_BDN)
    {
        name_num_index = &phb_ptr->indices.bdn_index;
    }
    else
    {
        return (kal_uint16) PHB_INVALID_VALUE;
    }

    if (alpha_id != NULL)
    {
        /* Max searching length is PHB_ALPHA_ID_DEPTH */
        len = alpha_id->length;
        if (len > PHB_ALPHA_ID_DEPTH)
        {
            alpha_id->length = PHB_ALPHA_ID_DEPTH;
        }

        /* Find first hit by using binary search */
        candidate_index = phb_name_num_index_find_index_by_alpha_id(name_num_index, alpha_id);

        /* Not found..Impossible, because a nearest neighbor should be returned */
        if (candidate_index == (kal_uint16) PHB_INVALID_VALUE)
        {
            /* Restore length */
            alpha_id->length = len;

            return (kal_uint16) PHB_INVALID_VALUE;
        }
    }
    else
    {
        candidate_index = 0;
    }

   /**
    * Since names (truncated) are sorted and thus they are grouped together,
    * linear searching can be started from first candidate,
    * try to matching record_index of each candidate.
    * Once found, its index should be set to confirmation primitive.
    */
    for (; (candidate_index < name_num_index->data_entry_table.used_count); ++(candidate_index))
    {
        pindex_struct position;

        if ((name_num_index->data_entry_table.table[name_num_index->name_index.table[candidate_index].position].
             storage == storage) &&
            (name_num_index->data_entry_table.table[name_num_index->name_index.table[candidate_index].position].
             record_index == record_index))
        {
            /* Restore length */
            if (alpha_id)
            {
                alpha_id->length = len;
            }
            return candidate_index;
        }

        if (alpha_id != NULL)
        {
            position.position = name_num_index->name_index.table[candidate_index].position;
            phb_compare_by_alpha_id(&name_num_index->data_entry_table, alpha_id, &position, &result);

            /* No more candidates */
            if (result.distance != 0)
            {
                break;
            }
        }
    }

    /* Restore length */
    alpha_id->length = len;

    /* No found? Impossible! */
    return (kal_uint16) PHB_INVALID_VALUE;
}   /* end of phb_se_search_by_record_index_name */


/*****************************************************************************
 * FUNCTION
 *  phb_se_is_next_also_candidate
 * DESCRIPTION
 *  Determines whether next candidate is also a candidate.
 * PARAMETERS
 *  name_num_index      [?]         
 *  candidate_index     [IN]        
 *  is_byname           [IN]        
 *  ilm_ptr(?)          [IN]        The primitives
 * RETURNS
 *  void
 *****************************************************************************/
kal_bool phb_se_is_next_also_candidate(
            name_num_index_type *name_num_index,
            kal_uint16 candidate_index,
            kal_bool is_byname)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    compare_result_type result;

    pindex_struct candidate_position;
    pindex_struct next_position;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_SE_IS_NEXT_ALSO_CANDIDATE);

    /* BYNAME */
    if ((is_byname == KAL_TRUE) && (candidate_index < (name_num_index->name_index.used_count - 1)))
    {
        candidate_position.position = name_num_index->name_index.table[candidate_index].position;
        next_position.position = name_num_index->name_index.table[candidate_index + 1].position;

        phb_compare_by_alpha_id_for_sort(
            &name_num_index->data_entry_table,
            &candidate_position,
            &next_position,
            &result);

        if (result.distance == 0)
        {
            return KAL_TRUE;
        }
    }
    /* BYNUMBER */
    else if ((is_byname == KAL_FALSE) && (candidate_index < name_num_index->num_index.used_count - 1))
    {
        candidate_position.position = name_num_index->num_index.table[candidate_index].position;
        next_position.position = name_num_index->num_index.table[candidate_index + 1].position;

        phb_compare_by_tel_num_sig_for_sort(
            &name_num_index->data_entry_table,
            &candidate_position,
            &next_position,
            &result);

        if (result.distance == 0)
        {
            return KAL_TRUE;
        }
    }

    return KAL_FALSE;
}   /* end of phb_search_confirm */


/*****************************************************************************
 * FUNCTION
 *  phb_se_search_by_name
 * DESCRIPTION
 *  Search by name.
 *  This function returns the index of first candidate. Because the search behavior of PHB
 *  is fixed-length matching.
 * PARAMETERS
 *  type                        [IN]        
 *  alpha_id                    [?]         
 *  first_candidate_index       [?]         
 *  is_more_candidate           [?]         
 * RETURNS
 *  First cadidate which is index to name_index
 *****************************************************************************/
name_num_index_type *phb_se_search_by_name(
                        phb_type_enum type,
                        alpha_id_type *alpha_id,
                        kal_uint16 *first_candidate_index,
                        kal_bool *is_more_candidate)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    name_num_index_type *name_num_index;

    kal_uint8 len;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_SE_SEARCH_BY_NAME);

#ifdef __PHB_SORT_ENABLE__
    if (type == PHB_PHONEBOOK)
    {
        name_num_index = &phb_ptr->indices.phb_index;
    }
    else if (type == PHB_FDN)
#else /* __PHB_SORT_ENABLE__ */ 
    if (type == PHB_FDN)
#endif /* __PHB_SORT_ENABLE__ */ /* __PHB_SORT_NAME__ */
        name_num_index = &phb_ptr->indices.fdn_index;
    else if (type == PHB_BDN)
    {
        name_num_index = &phb_ptr->indices.bdn_index;
    }
    else
    {
        return NULL;
    }

    /* Max searching length is PHB_ALPHA_ID_DEPTH */
    len = alpha_id->length;
    if (len > PHB_ALPHA_ID_DEPTH)
    {
        alpha_id->length = PHB_ALPHA_ID_DEPTH;
    }

    /* Find first hit by using binary search */
    *first_candidate_index = phb_name_num_index_find_index_by_alpha_id(name_num_index, alpha_id);

   /**
    * Unless there are no entries, the nearest neighbor is ALWAYS found.
    */
    if (*first_candidate_index == (kal_uint16) PHB_INVALID_VALUE)
    {
        *is_more_candidate = KAL_FALSE;
        return NULL;
    }

    /* MTK 2003-12-30 Wilson, Compare String again if is a UCS2 character.(Exactly Encoding match) */
#if defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__)
    if ((alpha_id->charset == PHB_UCS2) && (*first_candidate_index < name_num_index->name_index.used_count))
    {
        *first_candidate_index = phb_name_num_index_after_find_index_by_alpha_id(name_num_index, alpha_id, *first_candidate_index);
    }
#endif /* defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__) */ 
    /* END MTK */

    if (*first_candidate_index >= name_num_index->name_index.used_count)
    {
        --(*first_candidate_index);
    }

   /**
    * Condition for determining whether more candidates exist:
    * 1. For BYNAME:
    *   Since a nearest neighbor is always found, only when
    *   length of query pattern and length of pattern are both
    *   larger than ALPHA_ID_DEPTH,
    *   and stored pattern of this candidate is the same as next candidate
    *   should verify this candidate.
    *   Futhermore, when doing verification, if this candidate is not a
    *   hit, and next neighbor of this candidate also meets the
    *   condition above, proceed verification for next candidate;
    *   otherwise, a hit is found, and stop verification.
    *
    * 2. For BYNUMBER:
    *   As long as both of signature and 2 digits of telephone number
    *   are the same as query pattern, the candidate has to be verified.
    *   If hit, temporarily stores it, and proceeds for next candidate,
    *   until there are no candidates.
    */
    if ((name_num_index->data_entry_table.used_count > 0) && (len > PHB_ALPHA_ID_DEPTH))
    {
        data_entry_struct *data_entry;

        data_entry =
            &name_num_index->data_entry_table.table[name_num_index->name_index.table[*first_candidate_index].position];
        if (data_entry->alpha_id.length >= PHB_ALPHA_ID_DEPTH)
        {
            compare_result_type result;

            phb_compare_by_key_alpha_id(alpha_id, &data_entry->alpha_id, &result);
            if ((result.distance == 0) &&
                (phb_se_is_next_also_candidate(name_num_index, *first_candidate_index, KAL_TRUE)))
            {
                *is_more_candidate = KAL_TRUE;
            }
        }
    }
    else
    {
        *is_more_candidate = KAL_FALSE;
    }

    /* Restore length */
    alpha_id->length = len;

    return name_num_index;
}   /* end of phb_se_search_by_name */


/*****************************************************************************
 * FUNCTION
 *  phb_se_compare_tel_number_with_first_character
 * DESCRIPTION
 *  compare tel number with first character.
 * PARAMETERS
 *  type        [IN]        
 *  tel_num     [?]         
 *  first_candidate_index       [?]         
 *  is_more_candidate           [?]         
 * RETURNS
 *  First cadidate which is index to num_index
 *  For PHB_BYNUMBER, could return NULL if no candidate found.
 *****************************************************************************/
name_num_index_type *phb_se_compare_tel_number_with_first_character(
                        phb_type_enum type,
                        l4_addr_bcd_struct *tel_num,
                        kal_uint16 *first_candidate_index,
                        kal_bool *is_more_candidate)

{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    name_num_index_type *name_num_index;
    kal_uint8 num;
    kal_uint8 signat

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -